From fa3b12edac3ca81a24917a6ad281382380e1b2e2 Mon Sep 17 00:00:00 2001 From: Pavel Popov Date: Sun, 19 Nov 2017 15:53:21 +0300 Subject: [PATCH 1/3] Add ClickHouse support --- modules/clickhouse/pom.xml | 44 +++++++++++++ .../containers/ClickHouseContainer.java | 66 +++++++++++++++++++ .../containers/ClickHouseProvider.java | 13 ++++ ...s.containers.JdbcDatabaseContainerProvider | 1 + modules/jdbc-test/pom.xml | 11 ++++ .../testcontainers/jdbc/JDBCDriverTest.java | 23 ++++--- pom.xml | 1 + 7 files changed, 149 insertions(+), 10 deletions(-) create mode 100644 modules/clickhouse/pom.xml create mode 100644 modules/clickhouse/src/main/java/org/testcontainers/containers/ClickHouseContainer.java create mode 100644 modules/clickhouse/src/main/java/org/testcontainers/containers/ClickHouseProvider.java create mode 100644 modules/clickhouse/src/main/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider diff --git a/modules/clickhouse/pom.xml b/modules/clickhouse/pom.xml new file mode 100644 index 00000000000..b90853777cf --- /dev/null +++ b/modules/clickhouse/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + + + org.testcontainers + testcontainers-parent + 0-SNAPSHOT + ../../pom.xml + + + clickhouse + TestContainers :: JDBC :: ClickHouse + + + + ${project.groupId} + jdbc + ${project.version} + + + ru.yandex.clickhouse + clickhouse-jdbc + 0.1.34 + test + + + com.zaxxer + HikariCP-java6 + 2.3.8 + test + + + commons-dbutils + commons-dbutils + 1.6 + test + + + + + \ No newline at end of file diff --git a/modules/clickhouse/src/main/java/org/testcontainers/containers/ClickHouseContainer.java b/modules/clickhouse/src/main/java/org/testcontainers/containers/ClickHouseContainer.java new file mode 100644 index 00000000000..612aee13b10 --- /dev/null +++ b/modules/clickhouse/src/main/java/org/testcontainers/containers/ClickHouseContainer.java @@ -0,0 +1,66 @@ +package org.testcontainers.containers; + +import org.testcontainers.containers.wait.HttpWaitStrategy; + +import java.time.Duration; + +public class ClickHouseContainer> extends JdbcDatabaseContainer { + public static final String NAME = "clickhouse"; + public static final String IMAGE = "yandex/clickhouse-server"; + public static final Integer HTTP_PORT = 8123; + public static final Integer NATIVE_PORT = 9000; + + private String databaseName = "default"; + private String username = "default"; + private String password = ""; + + public ClickHouseContainer() { + super(IMAGE + ":1.1.54310"); + } + + public ClickHouseContainer(String dockerImageName) { + super(dockerImageName); + } + + @Override + protected void configure() { + withExposedPorts(HTTP_PORT, NATIVE_PORT); + waitingFor( + new HttpWaitStrategy() + .forStatusCode(200) + .forResponsePredicate(responseBody -> "Ok.".equals(responseBody)) + .withStartupTimeout(Duration.ofMinutes(1)) + ); + } + + @Override + protected Integer getLivenessCheckPort() { + return getMappedPort(HTTP_PORT); + } + + @Override + public String getDriverClassName() { + return "ru.yandex.clickhouse.ClickHouseDriver"; + } + + @Override + public String getJdbcUrl() { + return "jdbc:clickhouse://" + getContainerIpAddress() + ":" + getMappedPort(HTTP_PORT) + "/" + databaseName; + } + + @Override + public String getUsername() { + return username; + } + + @Override + public String getPassword() { + return password; + } + + @Override + public String getTestQueryString() { + return "SELECT 1"; + } + +} diff --git a/modules/clickhouse/src/main/java/org/testcontainers/containers/ClickHouseProvider.java b/modules/clickhouse/src/main/java/org/testcontainers/containers/ClickHouseProvider.java new file mode 100644 index 00000000000..be5a01657f0 --- /dev/null +++ b/modules/clickhouse/src/main/java/org/testcontainers/containers/ClickHouseProvider.java @@ -0,0 +1,13 @@ +package org.testcontainers.containers; + +public class ClickHouseProvider extends JdbcDatabaseContainerProvider { + @Override + public boolean supports(String databaseType) { + return databaseType.equals(ClickHouseContainer.NAME); + } + + @Override + public JdbcDatabaseContainer newInstance(String tag) { + return new ClickHouseContainer(ClickHouseContainer.IMAGE + ":" + tag); + } +} diff --git a/modules/clickhouse/src/main/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider b/modules/clickhouse/src/main/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider new file mode 100644 index 00000000000..63e99284d2b --- /dev/null +++ b/modules/clickhouse/src/main/resources/META-INF/services/org.testcontainers.containers.JdbcDatabaseContainerProvider @@ -0,0 +1 @@ +org.testcontainers.containers.ClickHouseProvider \ No newline at end of file diff --git a/modules/jdbc-test/pom.xml b/modules/jdbc-test/pom.xml index 3a311119187..b8fd6eb2662 100644 --- a/modules/jdbc-test/pom.xml +++ b/modules/jdbc-test/pom.xml @@ -24,6 +24,11 @@ postgresql ${project.version} + + ${project.groupId} + clickhouse + ${project.version} + com.google.guava @@ -51,6 +56,12 @@ 1.4.6 test + + ru.yandex.clickhouse + clickhouse-jdbc + 0.1.34 + test + diff --git a/modules/jdbc-test/src/test/java/org/testcontainers/jdbc/JDBCDriverTest.java b/modules/jdbc-test/src/test/java/org/testcontainers/jdbc/JDBCDriverTest.java index 8e663df8a45..f7c33a9d156 100644 --- a/modules/jdbc-test/src/test/java/org/testcontainers/jdbc/JDBCDriverTest.java +++ b/modules/jdbc-test/src/test/java/org/testcontainers/jdbc/JDBCDriverTest.java @@ -31,18 +31,21 @@ public class JDBCDriverTest { public boolean performTestForCharacterSet; @Parameter(3) public boolean performTestForCustomIniFile; + @Parameter(4) + public boolean pmdKnownBroken; @Parameterized.Parameters(name = "{index} - {0}") public static Iterable data() { return asList( new Object[][]{ - {"jdbc:tc:mysql:5.5.43://hostname/databasename", false, false, false}, - {"jdbc:tc:mysql://hostname/databasename?TC_INITSCRIPT=somepath/init_mysql.sql", true, false, false}, - {"jdbc:tc:mysql://hostname/databasename?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction", true, false, false}, - {"jdbc:tc:mysql://hostname/databasename?useUnicode=yes&characterEncoding=utf8", false, true, false}, - {"jdbc:tc:mysql://hostname/databasename", false, false, false}, - {"jdbc:tc:postgresql://hostname/databasename", false, false, false}, - {"jdbc:tc:mysql:5.6://hostname/databasename?TC_MY_CNF=somepath/mysql_conf_override", false, false, true}, + {"jdbc:tc:mysql:5.5.43://hostname/databasename", false, false, false, false}, + {"jdbc:tc:mysql://hostname/databasename?TC_INITSCRIPT=somepath/init_mysql.sql", true, false, false, false}, + {"jdbc:tc:mysql://hostname/databasename?TC_INITFUNCTION=org.testcontainers.jdbc.JDBCDriverTest::sampleInitFunction", true, false, false, false}, + {"jdbc:tc:mysql://hostname/databasename?useUnicode=yes&characterEncoding=utf8", false, true, false, false}, + {"jdbc:tc:mysql://hostname/databasename", false, false, false, false}, + {"jdbc:tc:postgresql://hostname/databasename", false, false, false, false}, + {"jdbc:tc:mysql:5.6://hostname/databasename?TC_MY_CNF=somepath/mysql_conf_override", false, false, true, false}, + {"jdbc:tc:clickhouse://hostname/databasename", false, false, false, true}, }); } @@ -63,7 +66,7 @@ public static void testCleanup() { @Test public void test() throws SQLException { - performSimpleTest(jdbcUrl); + performSimpleTest(jdbcUrl, pmdKnownBroken); if (performTestForScriptedSchema) { performTestForScriptedSchema(jdbcUrl); @@ -78,9 +81,9 @@ public void test() throws SQLException { } } - private void performSimpleTest(String jdbcUrl) throws SQLException { + private void performSimpleTest(String jdbcUrl, boolean pmdKnownBroken) throws SQLException { try (HikariDataSource dataSource = getDataSource(jdbcUrl, 1)) { - boolean result = new QueryRunner(dataSource).query("SELECT 1", rs -> { + boolean result = new QueryRunner(dataSource, pmdKnownBroken).query("SELECT 1", rs -> { rs.next(); int resultSetInt = rs.getInt(1); assertEquals("A basic SELECT query succeeds", 1, resultSetInt); diff --git a/pom.xml b/pom.xml index bf158718386..49392c4d56d 100644 --- a/pom.xml +++ b/pom.xml @@ -163,6 +163,7 @@ modules/jdbc modules/mysql modules/postgresql + modules/clickhouse modules/selenium modules/nginx modules/jdbc-test From 5b9985c7cc299e01e87a3da88ed0a77e5f33b6ef Mon Sep 17 00:00:00 2001 From: Pavel Popov Date: Tue, 27 Feb 2018 12:43:46 +0300 Subject: [PATCH 2/3] Remove unused imports --- .../testcontainers/containers/ClickHouseContainer.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/clickhouse/src/main/java/org/testcontainers/containers/ClickHouseContainer.java b/modules/clickhouse/src/main/java/org/testcontainers/containers/ClickHouseContainer.java index a84646a3f2f..1cdee46f72f 100644 --- a/modules/clickhouse/src/main/java/org/testcontainers/containers/ClickHouseContainer.java +++ b/modules/clickhouse/src/main/java/org/testcontainers/containers/ClickHouseContainer.java @@ -3,7 +3,6 @@ import org.testcontainers.containers.wait.HttpWaitStrategy; import java.time.Duration; -import java.util.Collections; public class ClickHouseContainer> extends JdbcDatabaseContainer { public static final String NAME = "clickhouse"; @@ -31,10 +30,10 @@ public ClickHouseContainer(String dockerImageName) { protected void configure() { withExposedPorts(HTTP_PORT, NATIVE_PORT); waitingFor( - new HttpWaitStrategy() - .forStatusCode(200) - .forResponsePredicate(responseBody -> "Ok.".equals(responseBody)) - .withStartupTimeout(Duration.ofMinutes(1)) + new HttpWaitStrategy() + .forStatusCode(200) + .forResponsePredicate(responseBody -> "Ok.".equals(responseBody)) + .withStartupTimeout(Duration.ofMinutes(1)) ); } From 845424d2a57147f1cbe92dbb556cb7ea9ca57832 Mon Sep 17 00:00:00 2001 From: Pavel Popov Date: Tue, 27 Feb 2018 12:54:42 +0300 Subject: [PATCH 3/3] Fix deps --- modules/jdbc-test/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/jdbc-test/build.gradle b/modules/jdbc-test/build.gradle index 29b7a035d1e..14da0930f75 100644 --- a/modules/jdbc-test/build.gradle +++ b/modules/jdbc-test/build.gradle @@ -7,6 +7,7 @@ dependencies { testCompile 'org.postgresql:postgresql:42.0.0' testCompile 'mysql:mysql-connector-java:5.1.45' testCompile 'org.mariadb.jdbc:mariadb-java-client:1.4.6' + testCompile 'ru.yandex.clickhouse:clickhouse-jdbc:0.1.36' testCompile 'com.zaxxer:HikariCP-java6:2.3.8' testCompile 'org.apache.tomcat:tomcat-jdbc:8.5.4' testCompile 'org.vibur:vibur-dbcp:9.0'