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
7 changes: 7 additions & 0 deletions docs/modules/databases/clickhouse.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ testImplementation "org.testcontainers:clickhouse:{{latest_version}}"
!!! hint
Adding this Testcontainers library JAR will not automatically add a database driver JAR to your project. You should ensure that your project also has a suitable database driver as a dependency.

!!! note
Testcontainers uses the new ClickHouse driver (`com.clickhouse.jdbc.ClickHouseDriver`) by default after version 1.16.3, but the new driver only supports ClickHouse with version >= 20.7.

For compatibility with ClickHouse versions < 20.7, you can temporarily continue to use the old ClickHouse driver(`ru.yandex.clickhouse.ClickHouseDriver`) by adding the following JVM config option: `-Dclickhouse-temporarily-use-deprecated-driver=true`

Future versions of Testcontainers will not support the old driver after July 2022 and it is recommended that you to use ClickHouse version 20.7 or above.

2 changes: 1 addition & 1 deletion modules/clickhouse/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ dependencies {
api project(':jdbc')

testImplementation project(':jdbc-test')
testImplementation 'ru.yandex.clickhouse:clickhouse-jdbc:0.3.2'
testImplementation 'com.clickhouse:clickhouse-jdbc:0.3.2'
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,62 @@
package org.testcontainers.containers;

import com.google.common.collect.Sets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
import org.testcontainers.utility.DockerImageName;

import java.time.Duration;
import java.util.Set;

public class ClickHouseContainer extends JdbcDatabaseContainer {
private static final Logger LOGGER = LoggerFactory.getLogger(ClickHouseContainer.class);

public static final String NAME = "clickhouse";

private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("yandex/clickhouse-server");
private static final DockerImageName DEFAULT_IMAGE_NAME;

@Deprecated
public static final String IMAGE = DEFAULT_IMAGE_NAME.getUnversionedPart();
public static final String IMAGE;

@Deprecated
public static final String DEFAULT_TAG = "18.10.3";
public static final String DEFAULT_TAG;

public static final Integer HTTP_PORT = 8123;
public static final Integer NATIVE_PORT = 9000;

private static final String DRIVER_CLASS_NAME = "ru.yandex.clickhouse.ClickHouseDriver";
private static final String DRIVER_CLASS_NAME;
private static final String DEPRECATED_DRIVER_CLASS_NAME = "ru.yandex.clickhouse.ClickHouseDriver";
private static final String LATEST_DRIVER_CLASS_NAME = "com.clickhouse.jdbc.ClickHouseDriver";
private static final String JDBC_URL_PREFIX = "jdbc:" + NAME + "://";
private static final String TEST_QUERY = "SELECT 1";

private String databaseName = "default";
private String username = "default";
private String password = "";

static {
// TODO: Future versions of Testcontainers will not support the old driver after July 2022 (https://github.com/testcontainers/testcontainers-java/issues/4924)
boolean temporarilyUseDeprecatedDriver = Boolean.getBoolean("clickhouse-temporarily-use-deprecated-driver");
if (temporarilyUseDeprecatedDriver) {
DEFAULT_IMAGE_NAME = DockerImageName.parse("yandex/clickhouse-server");
IMAGE = DEFAULT_IMAGE_NAME.getUnversionedPart();
DEFAULT_TAG = "18.10.3";
DRIVER_CLASS_NAME = DEPRECATED_DRIVER_CLASS_NAME;

LOGGER.warn("Future versions of Testcontainers will not support the old ClickHouse driver[{}] after July 2022.", DEPRECATED_DRIVER_CLASS_NAME);
LOGGER.warn("It is recommended that you to use ClickHouse version 20.7 or above.");
LOGGER.warn("You may temporarily continue running on old ClickHouse driver[{}] by adding the following", DEPRECATED_DRIVER_CLASS_NAME);
LOGGER.warn("JVM config option:");
LOGGER.warn(" -Dclickhouse-temporarily-use-deprecated-driver=true");
} else {
DEFAULT_IMAGE_NAME = DockerImageName.parse("clickhouse/clickhouse-server");
IMAGE = DEFAULT_IMAGE_NAME.getUnversionedPart();
DEFAULT_TAG = "21.3";
DRIVER_CLASS_NAME = LATEST_DRIVER_CLASS_NAME;
}
}

/**
* @deprecated use {@link ClickHouseContainer(DockerImageName)} instead
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
import org.testcontainers.utility.DockerImageName;

public interface ClickhouseTestImages {
DockerImageName CLICKHOUSE_IMAGE = DockerImageName.parse("yandex/clickhouse-server:18.10.3");
DockerImageName CLICKHOUSE_IMAGE = Boolean.getBoolean("clickhouse-temporarily-use-deprecated-driver")
? DockerImageName.parse("yandex/clickhouse-server:18.10.3")
: DockerImageName.parse("clickhouse/clickhouse-server:21.3");
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,16 @@ public void testSimple() throws SQLException {
assertEquals("A basic SELECT query succeeds", 1, resultSetInt);
}
}

@Test
public void testTemporarilyUseDeprecatedDriver() throws SQLException {
System.setProperty("clickhouse-temporarily-use-deprecated-driver", "true");
try (ClickHouseContainer clickhouse = new ClickHouseContainer(CLICKHOUSE_IMAGE)) {
clickhouse.start();
ResultSet resultSet = performQuery(clickhouse, "SELECT 1");

int resultSetInt = resultSet.getInt(1);
assertEquals("A basic SELECT query succeeds", 1, resultSetInt);
}
}
}