Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions modules/clickhouse/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
description = "Testcontainers :: JDBC :: ClickHouse"

dependencies {
compile project(':jdbc')

testCompile 'ru.yandex.clickhouse:clickhouse-jdbc:0.1.36'
testCompile 'com.zaxxer:HikariCP-java6:2.3.8'
testCompile 'commons-dbutils:commons-dbutils:1.6'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.testcontainers.containers;

import org.testcontainers.containers.wait.HttpWaitStrategy;

import java.time.Duration;

public class ClickHouseContainer<SELF extends ClickHouseContainer<SELF>> extends JdbcDatabaseContainer<SELF> {
public static final String NAME = "clickhouse";
public static final String IMAGE = "yandex/clickhouse-server";
public static final String IMAGE_TAG = "1.1.54310";
public static final String JDBC_DRIVER_CLASS_NAME = "ru.yandex.clickhouse.ClickHouseDriver";
public static final String JDBC_URL_PREFIX = "jdbc:clickhouse";
public static final String TEST_QUERY_STRING = "SELECT 1";
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 + ":" + IMAGE_TAG);
}

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 JDBC_DRIVER_CLASS_NAME;
}

@Override
public String getJdbcUrl() {
return JDBC_URL_PREFIX + "://" + getContainerIpAddress() + ":" + getMappedPort(HTTP_PORT) + "/" + databaseName;
}

@Override
public String getUsername() {
return username;
}

@Override
public String getPassword() {
return password;
}

@Override
public String getTestQueryString() {
return TEST_QUERY_STRING;
}

}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.testcontainers.containers.ClickHouseProvider
2 changes: 2 additions & 0 deletions modules/jdbc-test/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
dependencies {
compile project(':mysql')
compile project(':postgresql')
compile project(':clickhouse')

testCompile 'com.google.guava:guava:18.0'
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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@ public class JDBCDriverTest {
public boolean performTestForCharacterSet;
@Parameter(3)
public boolean performTestForCustomIniFile;
@Parameter(4)
public boolean pmdKnownBroken;

@Parameterized.Parameters(name = "{index} - {0}")
public static Iterable<Object[]> 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:mysql://hostname/databasename?useSSL=false", 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:mysql://hostname/databasename?useSSL=false", 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}
});
}

Expand All @@ -64,7 +67,7 @@ public static void testCleanup() {

@Test
public void test() throws SQLException {
performSimpleTest(jdbcUrl);
performSimpleTest(jdbcUrl, pmdKnownBroken);

if (performTestForScriptedSchema) {
performTestForScriptedSchema(jdbcUrl);
Expand All @@ -79,9 +82,9 @@ public void test() throws SQLException {
}
}

private void performSimpleTest(String jdbcUrl) throws SQLException {
private void performSimpleTest(String jdbcUrl, boolean pmdKnownBroken) throws SQLException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so happy with adding an additional param to the method if it's only needed by on tested class.
The tests will fail if not set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method getParameterMetaData not implemented on clickhouse jdbc driver.

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);
Expand Down