Skip to content

Commit

Permalink
Simplify version code in JDBC compatibility test
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Jun 2, 2021
1 parent 9fb818a commit c637346
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> testedTrinoVersions = ImmutableList.builder();
int testVersion = currentVersion - 1; // last release version
for (int i = 0; i < NUMBER_OF_TESTED_VERSIONS; i++) {
Expand Down Expand Up @@ -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();

Expand All @@ -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) {
Expand All @@ -134,14 +131,19 @@ protected Connection createConnection()
@Override
protected int getTestedServerVersion()
{
return Integer.parseInt(testedTrinoVersion.orElseThrow());
return parseInt(getTestedTrinoVersion());
}

@Override
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"));
}
}

0 comments on commit c637346

Please sign in to comment.