From c6373462dedf2fb356c3ed70ccdc278a09073229 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Tue, 1 Jun 2021 13:00:58 -0700 Subject: [PATCH] Simplify version code in JDBC compatibility test --- ...stJdbcResultSetCompatibilityOldServer.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/testing/trino-test-jdbc-compatibility-old-server/src/test/java/io/trino/TestJdbcResultSetCompatibilityOldServer.java b/testing/trino-test-jdbc-compatibility-old-server/src/test/java/io/trino/TestJdbcResultSetCompatibilityOldServer.java index 508290d611dc..d50e40716be5 100644 --- a/testing/trino-test-jdbc-compatibility-old-server/src/test/java/io/trino/TestJdbcResultSetCompatibilityOldServer.java +++ b/testing/trino-test-jdbc-compatibility-old-server/src/test/java/io/trino/TestJdbcResultSetCompatibilityOldServer.java @@ -34,6 +34,8 @@ import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Throwables.getStackTraceAsString; import static io.trino.testing.DataProviders.toDataProvider; +import static java.lang.Integer.parseInt; +import static java.lang.String.format; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Objects.requireNonNull; import static org.testng.Assert.assertEquals; @@ -65,7 +67,7 @@ public static Object[][] testedTrinoVersions() String currentVersionString = Resources.toString(Resources.getResource("trino-test-jdbc-compatibility-old-server-version.txt"), UTF_8).trim(); Matcher matcher = Pattern.compile("(\\d+)(?:-SNAPSHOT)?").matcher(currentVersionString); checkState(matcher.matches()); - int currentVersion = Integer.parseInt(matcher.group(1)); + int currentVersion = parseInt(matcher.group(1)); ImmutableList.Builder testedTrinoVersions = ImmutableList.builder(); int testVersion = currentVersion - 1; // last release version for (int i = 0; i < NUMBER_OF_TESTED_VERSIONS; i++) { @@ -93,12 +95,7 @@ public static Object[][] testedTrinoVersions() @BeforeClass public void setupTrinoContainer() { - if (testedTrinoVersion.isEmpty()) { - throw new AssertionError("Could not determine current Trino version"); - } - - DockerImageName image = DockerImageName.parse("trinodb/trino") - .withTag(testedTrinoVersion.get()); + DockerImageName image = DockerImageName.parse("trinodb/trino").withTag(getTestedTrinoVersion()); trinoContainer = new TrinoContainer(image); trinoContainer.start(); @@ -107,7 +104,7 @@ public void setupTrinoContainer() try (ResultSet rs = statementWrapper.getStatement().executeQuery("SELECT node_version FROM system.runtime.nodes")) { assertTrue(rs.next()); String actualTrinoVersion = rs.getString(1); - assertEquals(actualTrinoVersion, testedTrinoVersion.get(), "Trino server version reported by container does not match expected one"); + assertEquals(actualTrinoVersion, getTestedTrinoVersion(), "Trino server version reported by container does not match expected one"); } } catch (SQLException e) { @@ -134,7 +131,7 @@ protected Connection createConnection() @Override protected int getTestedServerVersion() { - return Integer.parseInt(testedTrinoVersion.orElseThrow()); + return parseInt(getTestedTrinoVersion()); } @Override @@ -142,6 +139,11 @@ public String toString() { // This allows distinguishing tests run against different Trino server version from each other. // It is included in tests report and maven output. - return "TestJdbcResultSetCompatibility[" + testedTrinoVersion.orElse("unknown") + "]"; + return format("TestJdbcResultSetCompatibility[%s]", testedTrinoVersion.orElse("unknown")); + } + + protected String getTestedTrinoVersion() + { + return testedTrinoVersion.orElseThrow(() -> new IllegalStateException("Trino version not set")); } }