diff --git a/modules/timeplus/build.gradle b/modules/timeplus/build.gradle index b403c9bef58..c0c7574608a 100644 --- a/modules/timeplus/build.gradle +++ b/modules/timeplus/build.gradle @@ -5,6 +5,6 @@ dependencies { api project(':jdbc') testImplementation project(':jdbc-test') - testRuntimeOnly 'com.timeplus:proton-jdbc:0.6.0' + testRuntimeOnly 'com.timeplus:timeplus-native-jdbc:2.0.1' testImplementation 'org.assertj:assertj-core:3.25.3' } diff --git a/modules/timeplus/src/main/java/org/testcontainers/containers/TimeplusContainer.java b/modules/timeplus/src/main/java/org/testcontainers/containers/TimeplusContainer.java deleted file mode 100644 index abd33989d46..00000000000 --- a/modules/timeplus/src/main/java/org/testcontainers/containers/TimeplusContainer.java +++ /dev/null @@ -1,106 +0,0 @@ -package org.testcontainers.containers; - -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.utility.ComparableVersion; -import org.testcontainers.utility.DockerImageName; - -import java.time.Duration; -import java.util.HashSet; -import java.util.Set; - -/** - * Testcontainers implementation for timeplus. - */ -public class TimeplusContainer extends JdbcDatabaseContainer { - - public static final String NAME = "timeplus"; - - public static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("timeplus/timeplusd"); - - private static final Integer HTTP_PORT = 3128; - - private static final Integer NATIVE_PORT = 8463; - - private static final String LEGACY_DRIVER_CLASS_NAME = "ru.yandex.clickhouse.ClickHouseDriver"; - - private static final String DRIVER_CLASS_NAME = "com.timeplus.jdbc.TimeplusDriver"; - - private static final String JDBC_URL_PREFIX = "jdbc:" + NAME + "://"; - - private static final String TEST_QUERY = "SELECT 1"; - - private String databaseName = "default"; - - private String username = "proton"; - - private String password = "proton@t+"; - - private boolean supportsNewDriver; - - public TimeplusContainer(String dockerImageName) { - this(DockerImageName.parse(dockerImageName)); - } - - public TimeplusContainer(final DockerImageName dockerImageName) { - super(dockerImageName); - dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); - supportsNewDriver = isNewDriverSupported(dockerImageName); - - addExposedPorts(HTTP_PORT, NATIVE_PORT); - this.waitStrategy = - Wait - .forHttp("/") - .forStatusCode(200) - .forResponsePredicate("Ok."::equals) - .withStartupTimeout(Duration.ofMinutes(1)); - } - - @Override - public Set getLivenessCheckPortNumbers() { - return new HashSet<>(getMappedPort(HTTP_PORT)); - } - - @Override - public String getDriverClassName() { - try { - if (supportsNewDriver) { - Class.forName(DRIVER_CLASS_NAME); - return DRIVER_CLASS_NAME; - } else { - return LEGACY_DRIVER_CLASS_NAME; - } - } catch (ClassNotFoundException e) { - return LEGACY_DRIVER_CLASS_NAME; - } - } - - private static boolean isNewDriverSupported(DockerImageName dockerImageName) { - // New driver supports versions 20.7+. Check the version part of the tag - return new ComparableVersion(dockerImageName.getVersionPart()).isGreaterThanOrEqualTo("20.7"); - } - - @Override - public String getJdbcUrl() { - return JDBC_URL_PREFIX + getHost() + ":" + getMappedPort(HTTP_PORT) + "/" + databaseName; - } - - @Override - public String getUsername() { - return username; - } - - @Override - public String getPassword() { - return password; - } - - @Override - public String getTestQueryString() { - return TEST_QUERY; - } - - @Override - public TimeplusContainer withUrlParam(String paramName, String paramValue) { - throw new UnsupportedOperationException("The Timeplus does not support this"); - } -} diff --git a/modules/timeplus/src/main/java/org/testcontainers/containers/TimeplusProvider.java b/modules/timeplus/src/main/java/org/testcontainers/containers/TimeplusProvider.java deleted file mode 100644 index 506549654df..00000000000 --- a/modules/timeplus/src/main/java/org/testcontainers/containers/TimeplusProvider.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.testcontainers.containers; - -import org.testcontainers.utility.DockerImageName; - -public class TimeplusProvider extends JdbcDatabaseContainerProvider { - - @Override - public boolean supports(String databaseType) { - return databaseType.equals(TimeplusContainer.NAME); - } - - @Override - public JdbcDatabaseContainer newInstance(String tag) { - return new TimeplusContainer( - DockerImageName.parse(TimeplusContainer.DEFAULT_IMAGE_NAME.getUnversionedPart()).withTag(tag) - ); - } -} diff --git a/modules/timeplus/src/main/java/org/testcontainers/timeplus/TimeplusContainer.java b/modules/timeplus/src/main/java/org/testcontainers/timeplus/TimeplusContainer.java index a770cb65fcb..e51d52ee997 100644 --- a/modules/timeplus/src/main/java/org/testcontainers/timeplus/TimeplusContainer.java +++ b/modules/timeplus/src/main/java/org/testcontainers/timeplus/TimeplusContainer.java @@ -13,11 +13,13 @@ */ public class TimeplusContainer extends JdbcDatabaseContainer { - private static final String NAME = "timeplus"; + static final String NAME = "timeplus"; + + static final String DOCKER_IMAGE_NAME = "timeplus/timeplusd"; private static final DockerImageName TIMEPLUS_IMAGE_NAME = DockerImageName.parse("timeplus/timeplusd:2.3.3"); - private static final Integer HTTP_PORT = 3128; + private static final Integer HTTP_PORT = 3218; private static final Integer NATIVE_PORT = 8463; @@ -29,9 +31,9 @@ public class TimeplusContainer extends JdbcDatabaseContainer private String databaseName = "default"; - private String username = "proton"; + private String username = "default"; - private String password = "proton@t+"; + private String password = ""; public TimeplusContainer(String dockerImageName) { this(DockerImageName.parse(dockerImageName)); @@ -39,15 +41,11 @@ public TimeplusContainer(String dockerImageName) { public TimeplusContainer(final DockerImageName dockerImageName) { super(dockerImageName); - dockerImageName.assertCompatibleWith(TIMEPLUS_IMAGE_NAME); + dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME); addExposedPorts(HTTP_PORT, NATIVE_PORT); this.waitStrategy = - Wait - .forHttp("/") - .forStatusCode(200) - .forResponsePredicate("Ok."::equals) - .withStartupTimeout(Duration.ofMinutes(1)); + Wait.forHttp("/timeplusd/v1/ping").forStatusCode(200).withStartupTimeout(Duration.ofMinutes(1)); } @Override @@ -73,7 +71,7 @@ public String getJdbcUrl() { JDBC_URL_PREFIX + getHost() + ":" + - getMappedPort(HTTP_PORT) + + getMappedPort(NATIVE_PORT) + "/" + this.databaseName + constructUrlParameters("?", "&") diff --git a/modules/timeplus/src/main/java/org/testcontainers/timeplus/TimeplusContainerProvider.java b/modules/timeplus/src/main/java/org/testcontainers/timeplus/TimeplusContainerProvider.java new file mode 100644 index 00000000000..d92828e2b27 --- /dev/null +++ b/modules/timeplus/src/main/java/org/testcontainers/timeplus/TimeplusContainerProvider.java @@ -0,0 +1,32 @@ +package org.testcontainers.timeplus; + +import org.testcontainers.containers.JdbcDatabaseContainer; +import org.testcontainers.containers.JdbcDatabaseContainerProvider; +import org.testcontainers.utility.DockerImageName; + +/** + * Factory for Timeplus containers. + */ +public class TimeplusContainerProvider extends JdbcDatabaseContainerProvider { + + private static final String DEFAULT_TAG = "2.3.3"; + + @Override + public boolean supports(String databaseType) { + return databaseType.equals(TimeplusContainer.NAME); + } + + @Override + public JdbcDatabaseContainer newInstance() { + return newInstance(DEFAULT_TAG); + } + + @Override + public JdbcDatabaseContainer newInstance(String tag) { + if (tag != null) { + return new TimeplusContainer(DockerImageName.parse(TimeplusContainer.DOCKER_IMAGE_NAME).withTag(tag)); + } else { + return newInstance(); + } + } +} diff --git a/modules/timeplus/src/main/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider b/modules/timeplus/src/main/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider new file mode 100644 index 00000000000..f3122d3d73b --- /dev/null +++ b/modules/timeplus/src/main/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider @@ -0,0 +1 @@ +org.testcontainers.timeplus.TimeplusContainerProvider diff --git a/modules/timeplus/src/main/resources/META_INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider b/modules/timeplus/src/main/resources/META_INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider deleted file mode 100644 index 6d88f52ae7b..00000000000 --- a/modules/timeplus/src/main/resources/META_INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider +++ /dev/null @@ -1 +0,0 @@ -org.testcontainers.containers.TimeplusProvider \ No newline at end of file diff --git a/modules/timeplus/src/test/java/org/testcontainers/TimeplusImages.java b/modules/timeplus/src/test/java/org/testcontainers/TimeplusImages.java index 03d98c77e5a..0e37c489036 100644 --- a/modules/timeplus/src/test/java/org/testcontainers/TimeplusImages.java +++ b/modules/timeplus/src/test/java/org/testcontainers/TimeplusImages.java @@ -3,6 +3,5 @@ import org.testcontainers.utility.DockerImageName; public interface TimeplusImages { - DockerImageName TIMEPLUS_PROTON_IMAGE = DockerImageName.parse("timeplus/timeplusd:2.2.10"); DockerImageName TIMEPLUS_IMAGE = DockerImageName.parse("timeplus/timeplusd:2.3.3"); } diff --git a/modules/timeplus/src/test/java/org/testcontainers/jdbc/clickhouse/TimeplusJDBCDriverTest.java b/modules/timeplus/src/test/java/org/testcontainers/jdbc/clickhouse/TimeplusJDBCDriverTest.java deleted file mode 100644 index f46c7b0f4ef..00000000000 --- a/modules/timeplus/src/test/java/org/testcontainers/jdbc/clickhouse/TimeplusJDBCDriverTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.testcontainers.jdbc.timeplus; - -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.testcontainers.jdbc.AbstractJDBCDriverTest; - -import java.util.Arrays; -import java.util.EnumSet; - -@RunWith(Parameterized.class) -public class TimeplusJDBCDriverTest extends AbstractJDBCDriverTest { - - @Parameterized.Parameters(name = "{index} - {0}") - public static Iterable data() { - return Arrays.asList( - new Object[][] { // - { "jdbc:tc:timeplus://hostname/databasename", EnumSet.of(Options.PmdKnownBroken) }, - } - ); - } -} diff --git a/modules/timeplus/src/test/java/org/testcontainers/junit/clickhouse/SimpleTimeplusTest.java b/modules/timeplus/src/test/java/org/testcontainers/junit/timeplus/SimpleTimeplusTest.java similarity index 85% rename from modules/timeplus/src/test/java/org/testcontainers/junit/clickhouse/SimpleTimeplusTest.java rename to modules/timeplus/src/test/java/org/testcontainers/junit/timeplus/SimpleTimeplusTest.java index 78b7c24d581..830fd4c73e4 100644 --- a/modules/timeplus/src/test/java/org/testcontainers/junit/clickhouse/SimpleTimeplusTest.java +++ b/modules/timeplus/src/test/java/org/testcontainers/junit/timeplus/SimpleTimeplusTest.java @@ -4,8 +4,8 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.testcontainers.TimeplusImages; -import org.testcontainers.containers.TimeplusContainer; import org.testcontainers.db.AbstractContainerDatabaseTest; +import org.testcontainers.timeplus.TimeplusContainer; import org.testcontainers.utility.DockerImageName; import java.sql.ResultSet; @@ -24,10 +24,7 @@ public SimpleTimeplusTest(DockerImageName imageName) { @Parameterized.Parameters(name = "{0}") public static Object[][] data() { - return new Object[][] { // - { TimeplusImages.TIMEPLUS_PROTON_IMAGE }, - { TimeplusImages.TIMEPLUS_IMAGE }, - }; + return new Object[][] { { TimeplusImages.TIMEPLUS_IMAGE } }; } @Test diff --git a/modules/timeplus/src/test/java/org/testcontainers/timeplus/TimeplusContainerTest.java b/modules/timeplus/src/test/java/org/testcontainers/timeplus/TimeplusContainerTest.java index eee7d64187f..7b3ade3858a 100644 --- a/modules/timeplus/src/test/java/org/testcontainers/timeplus/TimeplusContainerTest.java +++ b/modules/timeplus/src/test/java/org/testcontainers/timeplus/TimeplusContainerTest.java @@ -26,9 +26,9 @@ public void testSimple() throws SQLException { public void customCredentialsWithUrlParams() throws SQLException { try ( TimeplusContainer timeplus = new TimeplusContainer("timeplus/timeplusd:2.3.3") - .withUsername("test") - .withPassword("test") - .withDatabaseName("test") + .withUsername("system") + .withPassword("sys@t+") + .withDatabaseName("system") .withUrlParam("max_result_rows", "5") ) { timeplus.start();