test
```
TBD: document a dockerized development environment for running the standard local test suite.
diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseContainerStarter.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseContainerStarter.java
new file mode 100644
index 000000000..b26710ce9
--- /dev/null
+++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseContainerStarter.java
@@ -0,0 +1,193 @@
+package com.clickhouse.client;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.BindMode;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.Network;
+import org.testcontainers.containers.wait.strategy.Wait;
+import org.testcontainers.images.builder.ImageFromDockerfile;
+
+import java.time.Duration;
+import java.util.List;
+
+import static java.time.temporal.ChronoUnit.SECONDS;
+
+/**
+ * Starts the ClickHouse containers integration tests connect to.
+ *
+ * {@code single} starts one server. {@code cluster} starts three servers behind nginx.
+ * The process that calls {@link #getHost()} always sees one host and the published service ports.
+ */
+public abstract class ClickHouseContainerStarter {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ClickHouseContainerStarter.class);
+
+ public static final int HTTP_PORT = 18123;
+
+ static final String FRONTEND_ALIAS = "clickhouse";
+ static final String CONTAINER_TMP_DIR = "/tmp";
+ private static final String CUSTOM_DIRECTORY = "/custom";
+ private static final String CONFIG_RESOURCE = "containers/clickhouse-server";
+
+ protected final ClickHouseTestEnvironment environment;
+ protected final Network network;
+
+ ClickHouseContainerStarter(ClickHouseTestEnvironment environment, Network network) {
+ this.environment = environment;
+ this.network = network;
+ }
+
+ /**
+ * @return a starter for {@code single} or {@code cluster}, or null when the mode is {@code none}
+ */
+ static ClickHouseContainerStarter create(ClickHouseTestEnvironment environment, Network network) {
+ switch (environment.getContainerMode()) {
+ case SINGLE:
+ return new SingleClickHouseContainerStarter(environment, network);
+ case CLUSTER:
+ return new ClusterClickHouseContainerStarter(environment, network);
+ case NONE:
+ return null;
+ default:
+ throw new IllegalStateException("Unsupported container mode: " + environment.getContainerMode());
+ }
+ }
+
+ public abstract void start();
+
+ public abstract void stop();
+
+ public abstract boolean isRunning();
+
+ public abstract String getHost();
+
+ public abstract int getMappedPort(int port);
+
+ public abstract Container.ExecResult execInContainer(String... command) throws Exception;
+
+ /**
+ * Cluster name when these servers are replicas of one shard, otherwise null.
+ */
+ public String replicatedClusterName() {
+ return null;
+ }
+
+ /**
+ * Creates the test database. A cluster creates one Replicated database, with each
+ * node joining as its own replica of shard {@code s1}.
+ */
+ public final void createDatabase(String database, String user, String password) throws Exception {
+ if (replicatedClusterName() == null) {
+ execQuery("CREATE DATABASE IF NOT EXISTS `" + database + "`", user, password, clickHouseServers().get(0));
+ return;
+ }
+ List> servers = clickHouseServers();
+ for (int index = 0; index < servers.size(); index++) {
+ String sql = "CREATE DATABASE IF NOT EXISTS `" + database + "` ENGINE = Replicated("
+ + "'/clickhouse/databases/" + database + "', 's1', 'r" + (index + 1) + "')";
+ execQuery(sql, user, password, servers.get(index));
+ }
+ }
+
+ private static void execQuery(String sql, String user, String password, GenericContainer> server) throws Exception {
+ Container.ExecResult result = server.execInContainer("clickhouse-client",
+ "-u", user, "--password", password, "--query", sql);
+ if (result.getExitCode() != 0) {
+ throw new IllegalStateException("Failed to execute [" + sql + "]: " + result.getStderr()
+ + result.getStdout());
+ }
+ }
+
+ protected abstract List> clickHouseServers();
+
+ public abstract GenericContainer> getEndpointContainer();
+
+ public Network getNetwork() {
+ return network;
+ }
+
+ protected final GenericContainer> newClickHouseServer(String networkAlias, String containerName) {
+ return newClickHouseServer(networkAlias, containerName, null);
+ }
+
+ /**
+ * @param replicaName replica macro for a cluster node, or null for the single-server config
+ */
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ protected final GenericContainer> newClickHouseServer(String networkAlias, String containerName,
+ String replicaName) {
+ String additionalPackages = environment.getAdditionalPackages();
+ GenericContainer container = ((additionalPackages == null)
+ ? new GenericContainer<>(environment.getImageRef())
+ : new GenericContainer<>(new ImageFromDockerfile().withDockerfileFromBuilder(builder -> builder
+ .from(environment.getImageRef())
+ .run("apt-get update && apt-get install -y " + additionalPackages))))
+ .withCreateContainerCmdModifier(command -> {
+ command.withEntrypoint("/bin/sh");
+ if (containerName != null) {
+ command.withName(containerName);
+ }
+ })
+ .withCommand("-c", String.format("chmod +x %1$s/patch && %1$s/patch", CUSTOM_DIRECTORY))
+ .withEnv("TZ", environment.getTimezone())
+ .withExposedPorts(
+ ClickHouseProtocol.GRPC.getDefaultPort(),
+ HTTP_PORT,
+ ClickHouseProtocol.HTTP.getDefaultSecurePort(),
+ ClickHouseProtocol.MYSQL.getDefaultPort(),
+ ClickHouseProtocol.TCP.getDefaultPort(),
+ ClickHouseProtocol.TCP.getDefaultSecurePort(),
+ ClickHouseProtocol.POSTGRESQL.getDefaultPort())
+ .withClasspathResourceMapping(CONFIG_RESOURCE, CUSTOM_DIRECTORY, BindMode.READ_ONLY)
+ .withClasspathResourceMapping("empty.csv", "/var/lib/clickhouse/user_files/empty.csv",
+ BindMode.READ_ONLY)
+ .withFileSystemBind(System.getProperty("java.io.tmpdir"), CONTAINER_TMP_DIR, BindMode.READ_WRITE)
+ .withNetwork(network)
+ .withNetworkAliases(networkAlias);
+ if (replicaName != null) {
+ container = container
+ .withEnv("CLICKHOUSE_REPLICA", replicaName)
+ .withEnv("CLICKHOUSE_INTERSERVER_HOST", networkAlias)
+ .withClasspathResourceMapping("containers/clickhouse-cluster/config.d/custom_config.xml",
+ CUSTOM_DIRECTORY + "/config.d/custom_config.xml", BindMode.READ_ONLY)
+ .withClasspathResourceMapping("containers/clickhouse-cluster/users.d/cluster_quorum.xml",
+ CUSTOM_DIRECTORY + "/users.d/cluster_quorum.xml", BindMode.READ_ONLY);
+ }
+ return container.waitingFor(Wait.forHttp("/ping").forPort(HTTP_PORT)
+ .forStatusCode(200).withStartupTimeout(Duration.of(600, SECONDS)));
+ }
+
+ protected final GenericContainer> newNginx(String containerName, String configResource) {
+ return new GenericContainer<>("nginx:1.27-alpine")
+ .withCreateContainerCmdModifier(command -> {
+ if (containerName != null) {
+ command.withName(containerName);
+ }
+ })
+ .withNetwork(network)
+ .withNetworkAliases(FRONTEND_ALIAS)
+ .withClasspathResourceMapping(configResource, "/etc/nginx/nginx.conf", BindMode.READ_ONLY)
+ .withExposedPorts(
+ ClickHouseProtocol.GRPC.getDefaultPort(),
+ HTTP_PORT,
+ ClickHouseProtocol.HTTP.getDefaultSecurePort(),
+ ClickHouseProtocol.MYSQL.getDefaultPort(),
+ ClickHouseProtocol.TCP.getDefaultPort(),
+ ClickHouseProtocol.TCP.getDefaultSecurePort(),
+ ClickHouseProtocol.POSTGRESQL.getDefaultPort())
+ .waitingFor(Wait.forHttp("/ping").forPort(HTTP_PORT)
+ .forStatusCode(200).withStartupTimeout(Duration.of(600, SECONDS)));
+ }
+
+ protected static void stopQuietly(GenericContainer> container) {
+ if (container == null) {
+ return;
+ }
+ try {
+ container.stop();
+ } catch (RuntimeException e) {
+ LOGGER.warn("Failed to stop test container", e);
+ }
+ }
+}
diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseNodeTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseNodeTest.java
index bb81e939d..94318ae8f 100644
--- a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseNodeTest.java
+++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseNodeTest.java
@@ -396,7 +396,7 @@ public void testQueryWithSlash() throws URISyntaxException {
public void testProbe() {
// FIXME does not support ClickHouseProtocol.POSTGRESQL for now
ClickHouseProtocol[] protocols = null;
- if ( isCloud() ) {
+ if ( isCloud() || ClickHouseServerForTest.isCluster()) {
protocols = new ClickHouseProtocol[]{
ClickHouseProtocol.HTTP
};
diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseServerForTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseServerForTest.java
index fc4f5f26c..bd8bd0871 100644
--- a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseServerForTest.java
+++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseServerForTest.java
@@ -2,199 +2,81 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.testcontainers.containers.BindMode;
-import org.testcontainers.containers.Container;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
-import org.testcontainers.containers.wait.strategy.Wait;
-import org.testcontainers.images.builder.ImageFromDockerfile;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
+import com.clickhouse.client.ClickHouseTestEnvironment.ContainerMode;
+
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.URL;
import java.nio.charset.StandardCharsets;
-import java.time.Duration;
+import java.util.Locale;
import java.util.Base64;
import java.util.Collections;
import java.util.Map;
-import java.util.Properties;
-import java.util.UUID;
-
-import static java.time.temporal.ChronoUnit.SECONDS;
/**
- * Adaptive ClickHouse server environment for integration test. Two modes are
- * supported: 1) existing server(when system property {@code clickhouseServer}
- * is defined); and 2) test container.
- *
+ * ClickHouse endpoint for integration tests.
*
- * Below system properties can be used for customization:
- *
- * - clickhouseServer - host of clickhouse server
- * - clickhouse<Protocol>Port - port of specific protocol, for example:
- * {@code clickhouseGRPCPort}
- * - clickhouseImage - custom docker image, with or without tag and/or image
- * digest
- * - clickhouseVersion - version of clickhouse, could be replaced by the one
- * used in {@code clickhouseImage}
- * - clickhouseTimezone - server timezone
- * - additionalPackages - additional system packages should be installed in
- * container mode
- *
+ * What to start is {@code TEST_CLICKHOUSE_CONTAINER}: {@code single} (default) starts one
+ * server, {@code cluster} starts three servers behind nginx, and {@code none} starts nothing.
+ * Where tests connect when no container is started comes from {@code TEST_CLICKHOUSE_HOST}
+ * (default {@code localhost}), {@code TEST_CLICKHOUSE_USER}, and {@code TEST_CLICKHOUSE_PASSWORD}.
+ * {@code TEST_CLICKHOUSE_IMAGE_VERSION} is the image tag used to start a container.
+ * The removed {@code clickhouseVersion} system property throws {@link IllegalArgumentException}.
+ * {@code TEST_CLICKHOUSE_SECURE=true} selects the HTTPS endpoint on port 8443 (ClickHouse Cloud).
*/
@SuppressWarnings("squid:S2187")
public class ClickHouseServerForTest {
private static final Logger LOGGER = LoggerFactory.getLogger(ClickHouseServerForTest.class);
- private static final Network network = Network.newNetwork();
- private static final Properties properties;
-
- private static final String clickhouseServer;
- private static final String clickhouseVersion;
- private static final GenericContainer> clickhouseContainer;
+ private static final Network network;
+ private static final ClickHouseTestEnvironment environment;
+ private static final ClickHouseContainerStarter starter;
private static final String proxyHost;
private static final int proxyPort;
private static final String proxyImage;
- private static boolean isCloud = false;
-
- private static final String database;
- private static final boolean localDatabase;
static {
- properties = new Properties(System.getProperties());
- String externalDatabase = System.getenv("TEST_DB_NAME"); // see build.yaml workflow
- if (externalDatabase != null && !externalDatabase.trim().isEmpty()) {
- if (!externalDatabase.startsWith("clickhouse_java_test_")) {
- throw new RuntimeException("external database for tests should start with 'clickhouse_java_test_'");
- }
- localDatabase = false;
- database = externalDatabase;
- } else {
- localDatabase = true;
- database = "clickhouse_java_" + UUID.randomUUID().toString().substring(0, 8) + "_test_" + System.currentTimeMillis();
- }
-
- LOGGER.info("Local database: {}", localDatabase);
-
- String proxy = properties.getProperty("proxyAddress");
- if (proxy != null && !proxy.isEmpty()) { // use external proxy
- int index = proxy.indexOf(':');
- if (index > 0) {
- proxyHost = proxy.substring(0, index);
- proxyPort = Integer.parseInt(proxy.substring(index + 1));
- } else {
- proxyHost = proxy;
- proxyPort = 8666;
- }
- proxyImage = "";
- } else {
- proxyHost = "";
- proxyPort = -1;
- String image = properties.getProperty("proxyImage");
- proxyImage = image == null ? "ghcr.io/shopify/toxiproxy:2.5.0" : image;
- }
-
- final String containerName = System.getenv("CHC_TEST_CONTAINER_ID");
-
- clickhouseServer = properties.getProperty("clickhouseServer");
- String imageTag = properties.getProperty("clickhouseVersion");
- if (imageTag != null && imageTag.equalsIgnoreCase("cloud")) {
- isCloud = true;
- imageTag = "";
- }
- if (clickhouseServer != null || isCloud) { // use external server
- clickhouseVersion = imageTag == null
- || ClickHouseVersionUtils.of(imageTag).getYear() == 0 ? "" : imageTag;
- clickhouseContainer = null;
- } else { // use test container
- String timezone = properties.getProperty("clickhouseTimezone");
- if (timezone == null) {
- timezone = "UTC";
- }
-
- String imageName = properties.getProperty("clickhouseImage");
- if (imageName == null) {
- imageName = "clickhouse/clickhouse-server";
- }
-
- int tagIndex = imageName.indexOf(':');
- int digestIndex = imageName.indexOf('@');
- if (tagIndex > 0) {
- imageTag = "";
- clickhouseVersion = digestIndex > 0 ? imageName.substring(tagIndex + 1, digestIndex)
- : imageName.substring(tagIndex + 1);
- } else if (digestIndex > 0 || imageTag == null) {
- clickhouseVersion = imageTag = "";
- } else {
- if (ClickHouseVersionUtils.of(imageTag).getYear() == 0) {
- clickhouseVersion = "";
- } else {
- clickhouseVersion = imageTag;
- }
- imageTag = ":" + imageTag;
- }
-
- String imageNameWithTag = imageName + imageTag;
- String customPackages = properties.getProperty("additionalPackages");
- if (ClickHouseVersionUtils.check(clickhouseVersion, "(,21.3]")) {
- if (customPackages == null) {
- customPackages = "tzdata";
- } else if (!customPackages.contains("tzdata")) {
- customPackages += " tzdata";
- }
- }
-
- final String additionalPackages = customPackages;
- final String customDirectory = "/custom";
- clickhouseContainer = ((additionalPackages == null)
- ? new GenericContainer<>(imageNameWithTag)
- : new GenericContainer<>(new ImageFromDockerfile().withDockerfileFromBuilder(builder -> builder
- .from(imageNameWithTag).run("apt-get update && apt-get install -y " + additionalPackages))))
- .withCreateContainerCmdModifier(
- it -> {
- it.withEntrypoint("/bin/sh");
- if (containerName != null) {
- it.withName(containerName);
- }
- })
- .withCommand("-c", String.format("chmod +x %1$s/patch && %1$s/patch", customDirectory))
- .withEnv("TZ", timezone)
- .withExposedPorts(ClickHouseProtocol.GRPC.getDefaultPort(),
- ClickHouseProtocol.HTTP.getDefaultPort(),
- ClickHouseProtocol.HTTP.getDefaultSecurePort(),
- ClickHouseProtocol.MYSQL.getDefaultPort(),
- ClickHouseProtocol.TCP.getDefaultPort(),
- ClickHouseProtocol.TCP.getDefaultSecurePort(),
- ClickHouseProtocol.POSTGRESQL.getDefaultPort())
- .withClasspathResourceMapping("containers/clickhouse-server", customDirectory, BindMode.READ_ONLY)
- .withClasspathResourceMapping("empty.csv", "/var/lib/clickhouse/user_files/empty.csv", BindMode.READ_ONLY)
- .withFileSystemBind(System.getProperty("java.io.tmpdir"), getClickHouseContainerTmpDir(),
- BindMode.READ_WRITE)
- .withNetwork(network)
- .withNetworkAliases("clickhouse")
- .waitingFor(Wait.forHttp("/ping").forPort(ClickHouseProtocol.HTTP.getDefaultPort())
- .forStatusCode(200).withStartupTimeout(Duration.of(600, SECONDS)));
- }
+ ClickHouseTestEnvironment.rejectRemovedOptions(System.getProperties());
+ network = Network.newNetwork();
+ environment = ClickHouseTestEnvironment.from(System.getenv());
+ LOGGER.info("Local database: {}", environment.isLocalDatabase());
+
+ proxyHost = environment.getProxyHost();
+ proxyPort = environment.getProxyPort();
+ proxyImage = environment.getProxyImage();
+
+ starter = ClickHouseContainerStarter.create(environment, network);
+
+ LOGGER.info(
+ "ClickHouse test target: container={}, image={}, host={}, user={}, secure={}, database={}",
+ environment.getContainerMode(), environment.getImageRef(), environment.getHost(),
+ environment.getUser(), environment.isSecure(), environment.getDatabase());
+ System.out.println("TEST_CLICKHOUSE_CONTAINER="
+ + environment.getContainerMode().name().toLowerCase(Locale.ROOT));
+ System.out.println("TEST_CLICKHOUSE_IMAGE_VERSION=" + environment.getImageRef());
}
public static String getClickHouseVersion() {
- return clickhouseVersion;
+ return environment.getClickHouseVersion();
}
public static boolean hasClickHouseContainer() {
- return clickhouseContainer != null;
+ return starter != null;
}
public static GenericContainer> getClickHouseContainer() {
- return clickhouseContainer;
+ return starter == null ? null : starter.getEndpointContainer();
}
public static String getClickHouseContainerTmpDir() {
- return "/tmp";
+ return ClickHouseContainerStarter.CONTAINER_TMP_DIR;
}
public static String getClickHouseAddress() {
@@ -202,88 +84,57 @@ public static String getClickHouseAddress() {
}
public static String getClickHouseAddress(ClickHouseProtocol protocol, boolean useIPaddress) {
- StringBuilder builder = new StringBuilder();
- if (isCloud) {
- String host = System.getenv("CLICKHOUSE_CLOUD_HOST");
- int port = 8443;
- builder.append("https://").append(host).append(':').append(port);
- return builder.toString();
- } else if (clickhouseContainer != null) {
- builder.append(clickhouseContainer.getHost())
- .append(':').append(clickhouseContainer.getMappedPort(protocol.getDefaultPort()));
- } else {
- String port = properties
- .getProperty(String.format("clickhouse%SPort", protocol.name()), String.valueOf(protocol.getDefaultPort()));
- builder.append(clickhouseServer).append(':').append(port);
+ if (isCloud()) {
+ Endpoint endpoint = cloudHttpEndpoint();
+ return "https://" + endpoint.host + ":" + endpoint.port;
}
-
- return builder.toString();
+ Endpoint endpoint = resolve(protocol, protocol.getDefaultPort(), true);
+ return endpoint.host + ":" + endpoint.port;
}
public static ClickHouseNode getClickHouseNode(ClickHouseProtocol protocol,
boolean useSecurePort,
ClickHouseNode template) {
- String host = clickhouseServer;
- int port = useSecurePort ? protocol.getDefaultSecurePort() : protocol.getDefaultPort();
String database = template != null ? template.getDatabase().orElse("default") : "default";
- GenericContainer> container = clickhouseContainer;
if (isCloud()) {
- port = 8443;
- host = System.getenv("CLICKHOUSE_CLOUD_HOST");
+ Endpoint endpoint = cloudHttpEndpoint();
return ClickHouseNode.builder(template)
- .address(ClickHouseProtocol.HTTP, new InetSocketAddress(host, port))
- .credentials(new ClickHouseCredentials("default", getPassword()))
+ .address(ClickHouseProtocol.HTTP, new InetSocketAddress(endpoint.host, endpoint.port))
+ .credentials(new ClickHouseCredentials(getUsername(), getPassword()))
.options(Collections.singletonMap("ssl", "true"))
.database(database)
.build();
- } else if (container != null) {
- host = container.getHost();
- port = container.getMappedPort(port);
- } else {
- String config = properties
- .getProperty(String.format("clickhouse%SPort", protocol.name()));
- if (config != null && !config.isEmpty()) {
- port = Integer.parseInt(config);
- }
}
- return ClickHouseNode.builder(template).address(protocol, new InetSocketAddress(host, port))
- .credentials(new ClickHouseCredentials("default", getPassword()))
+ int port = useSecurePort ? protocol.getDefaultSecurePort() : protocol.getDefaultPort();
+ Endpoint endpoint = resolve(protocol, port, true);
+ return ClickHouseNode.builder(template).address(protocol, new InetSocketAddress(endpoint.host, endpoint.port))
+ .credentials(new ClickHouseCredentials(getUsername(), getPassword()))
.build();
}
public static ClickHouseNode getClickHouseNode(ClickHouseProtocol protocol, int port) {
- String host = clickhouseServer;
-
- if (isCloud) {
- host = System.getenv("CLICKHOUSE_CLOUD_HOST");
- port = 8443;
- return ClickHouseNode.builder().
- address(protocol, new InetSocketAddress(host, port))
- .credentials(new ClickHouseCredentials("default", getPassword()))
- .database(database)
+ if (isCloud()) {
+ Endpoint endpoint = cloudHttpEndpoint();
+ return ClickHouseNode.builder()
+ .address(protocol, new InetSocketAddress(endpoint.host, endpoint.port))
+ .credentials(new ClickHouseCredentials(getUsername(), getPassword()))
+ .database(getDatabase())
.build();
}
- if (clickhouseContainer != null) {
- host = clickhouseContainer.getHost();
- port = clickhouseContainer.getMappedPort(port);
- }
- return ClickHouseNode.builder().address(protocol, new InetSocketAddress(host, port)).build();
+ Endpoint endpoint = resolve(protocol, port, false);
+ return ClickHouseNode.builder().address(protocol, new InetSocketAddress(endpoint.host, endpoint.port)).build();
}
public static ClickHouseNode getClickHouseNode(ClickHouseProtocol protocol, Map options) {
- String host = clickhouseServer;
- String url = null;
- int port = protocol.getDefaultPort();
- if (isCloud) {
- host = System.getenv("CLICKHOUSE_CLOUD_HOST");
- port = 8443;
+ String url;
+ if (isCloud()) {
+ Endpoint endpoint = cloudHttpEndpoint();
options.put("password", getPassword());
- url = String.format("https://%s:%d/%s", host, port, database);
- } else if (clickhouseContainer != null) {
- host = clickhouseContainer.getHost();
- port = clickhouseContainer.getMappedPort(port);
- url = String.format("http://%s:%d/default", host, port);//TODO: Should this always be http?
+ url = String.format("https://%s:%d/%s", endpoint.host, endpoint.port, getDatabase());
+ } else {
+ Endpoint endpoint = resolve(protocol, protocol.getDefaultPort(), true);
+ url = String.format("http://%s:%d/default", endpoint.host, endpoint.port);
}
return ClickHouseNode.of(url, options);
}
@@ -309,132 +160,158 @@ public static Network getNetwork() {
}
public static String getUsername() {
- // For cloud, the username is set in environment variable
- if (isCloud) {
- return System.getenv("CLICKHOUSE_CLOUD_USERNAME") == null ? "default" : System.getenv("CLICKHOUSE_CLOUD_USERNAME");
- } else {
- return "default";
- }
+ return environment.getUser();
}
public static String getPassword() {
- // For cloud, the password is set in environment variable
- if (isCloud) {
- return System.getenv("CLICKHOUSE_CLOUD_PASSWORD");
- } else {
- return "test_default_password";
- }
+ return environment.getPassword();
}
public static boolean isCloud() {
- return isCloud;
+ return environment.isSecure();
+ }
+
+ public static boolean isCluster() {
+ return environment.getContainerMode() == ContainerMode.CLUSTER;
}
@BeforeSuite(groups = {"integration"})
public static void beforeSuite() {
- if (isCloud) {
- if (localDatabase) {
- if (!runQuery("CREATE DATABASE IF NOT EXISTS " + database)) {
- throw new RuntimeException("Failed to create database for testing.");
+ if (starter != null) {
+ if (!starter.isRunning()) {
+ try {
+ starter.start();
+ } catch (RuntimeException e) {
+ throw new IllegalStateException(new StringBuilder()
+ .append("Failed to start docker container for integration test.\r\n")
+ .append("To use an existing server, set TEST_CLICKHOUSE_CONTAINER=none ")
+ .append("and TEST_CLICKHOUSE_HOST. See ")
+ .append("https://github.com/ClickHouse/clickhouse-java#testing")
+ .toString(), e);
}
}
+ if (starter.isRunning()) {
+ createDatabaseOnServers();
+ }
return;
}
- if (clickhouseContainer != null) {
- if (clickhouseContainer.isRunning()) {
- return;
- }
-
- try {
- clickhouseContainer.start();
-
- if (clickhouseContainer.isRunning()) {
- if (!runQuery("CREATE DATABASE IF NOT EXISTS `" + getDatabase() + "`")) {
- throw new RuntimeException("Failed to create database");
- }
- }
- } catch (RuntimeException e) {
- throw new IllegalStateException(new StringBuilder()
- .append("Failed to start docker container for integration test.\r\n")
- .append("If you prefer to run tests without docker, ")
- .append("please follow instructions at https://github.com/ClickHouse/clickhouse-java#testing")
- .toString(), e);
+ if (isCloud() && environment.isLocalDatabase()) {
+ if (!runQuery("CREATE DATABASE IF NOT EXISTS `" + getDatabase() + "`")) {
+ throw new RuntimeException("Failed to create database for testing.");
}
}
}
@AfterSuite(groups = {"integration"})
public static void afterSuite() {
- if (clickhouseContainer != null) {
-// clickhouseContainer.copyFileFromContainer("/var/log/clickhouse-server/clickhouse-server.log", "server-container.log");
- clickhouseContainer.stop();
+ if (starter != null) {
+ starter.stop();
}
- if (isCloud) {
- if (localDatabase) {
- if (!runQuery("DROP DATABASE IF EXISTS `" + database + "`")) {
- LOGGER.warn("Failed to drop database for testing.");
- }
+ if (isCloud() && environment.isLocalDatabase() && starter == null) {
+ if (!runQuery("DROP DATABASE IF EXISTS `" + getDatabase() + "`")) {
+ LOGGER.warn("Failed to drop database for testing.");
}
}
}
public static String getDatabase() {
- return database;
+ return environment.getDatabase();
}
- public static boolean runQuery(String sql) {
- LOGGER.info("runQuery: (\"" + sql + "\")");
- if (clickhouseContainer != null) {
+ private static void createDatabaseOnServers() {
+ String database = getDatabase();
+ Exception lastFailure = null;
+ for (int attempt = 1; attempt <= 10; attempt++) {
try {
- Container.ExecResult res = clickhouseContainer.execInContainer("clickhouse-client",
- "-u", "default", "--password", getPassword(), "--query", sql);
- if (res.getExitCode() != 0) {
- LOGGER.error("query execution result: stderr={}, stdout={}", res.getStderr(), res.getStdout() );
- }
- return res.getExitCode() == 0;
+ starter.createDatabase(database, getUsername(), getPassword());
+ return;
} catch (Exception e) {
- throw new RuntimeException("runQuery('" + sql + "') failed", e);
+ lastFailure = e;
+ LOGGER.warn("Creating database {} failed on attempt {}", database, attempt);
+ try {
+ Thread.sleep(2000L);
+ } catch (InterruptedException interrupted) {
+ Thread.currentThread().interrupt();
+ break;
+ }
}
- } else {
- //Create database for testing
-
- ClickHouseNode server = getClickHouseNode(ClickHouseProtocol.HTTP, isCloud(), ClickHouseNode.builder().build());
+ }
+ throw new RuntimeException("Failed to create database " + database, lastFailure);
+ }
- String uri = server.getBaseUri();
+ public static boolean runQuery(String sql) {
+ LOGGER.info("runQuery: (\"{}\")", sql);
+ ClickHouseNode server = getClickHouseNode(ClickHouseProtocol.HTTP, isCloud(), ClickHouseNode.builder().build());
+ String uri = server.getBaseUri();
+
+ try {
+ URL serverURL = new URL(uri);
+ LOGGER.info("sending request to {} (uri={})", serverURL, uri);
+ byte[] postData = sql.getBytes(StandardCharsets.UTF_8);
+ String authorization = Base64.getEncoder()
+ .encodeToString((getUsername() + ":" + getPassword()).getBytes(StandardCharsets.UTF_8));
+ for (int attempts = 0; attempts < 10; attempts++) {
+ HttpURLConnection httpConn = (HttpURLConnection) serverURL.openConnection();
+ try {
+ httpConn.setRequestMethod("POST");
+ httpConn.setDoOutput(true);
+ httpConn.setRequestProperty("Authorization", "Basic " + authorization);
+ httpConn.setFixedLengthStreamingMode(postData.length);
+
+ try (OutputStream out = httpConn.getOutputStream()) {
+ out.write(postData, 0, postData.length);
+ out.flush();
+ }
- try {
- URL serverURL = new URL(uri);
- LOGGER.info("sending request to {} (uri={})", serverURL, uri);
- byte[] postData = sql.getBytes(StandardCharsets.UTF_8);
- for (int attempts = 0; attempts < 10; attempts++) {
- HttpURLConnection httpConn = (HttpURLConnection) serverURL.openConnection();
- try {
- httpConn.setRequestMethod("POST");
- httpConn.setDoOutput(true);
- httpConn.setRequestProperty("Authorization", "Basic " + Base64.getEncoder().encodeToString(("default:" + getPassword()).getBytes()));
- httpConn.setFixedLengthStreamingMode(postData.length);
-
- try (OutputStream out = httpConn.getOutputStream()) {
- out.write(postData, 0, postData.length);
- out.flush();
- }
-
- if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
- return true;
- }
- } finally {
- if (httpConn != null) {
- httpConn.disconnect();
- }
+ if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
+ return true;
}
+ } finally {
+ httpConn.disconnect();
}
- } catch (Exception e) {
- LOGGER.error("failed to run query", e);
}
+ } catch (Exception e) {
+ LOGGER.error("failed to run query", e);
+ }
+
+ return false;
+ }
+
+ private static Endpoint resolve(ClickHouseProtocol protocol, int port, boolean applyOverride) {
+ if (starter != null) {
+ int containerPort = (port == ClickHouseProtocol.HTTP.getDefaultPort())
+ ? ClickHouseContainerStarter.HTTP_PORT
+ : port;
+ return new Endpoint(starter.getHost(), starter.getMappedPort(containerPort));
+ }
+ if (applyOverride) {
+ String override = environment.portOverride(protocol);
+ if (override != null) {
+ port = Integer.parseInt(override);
+ }
+ }
+ return new Endpoint(environment.getHost(), port);
+ }
+
+ private static Endpoint cloudHttpEndpoint() {
+ if (starter != null) {
+ int port = ClickHouseProtocol.HTTP.getDefaultSecurePort();
+ return new Endpoint(starter.getHost(), starter.getMappedPort(port));
+ }
+ String override = environment.portOverride(ClickHouseProtocol.HTTP);
+ int port = override != null ? Integer.parseInt(override) : ClickHouseProtocol.HTTP.getDefaultSecurePort();
+ return new Endpoint(environment.getHost(), port);
+ }
+
+ private static final class Endpoint {
+ private final String host;
+ private final int port;
- return false;
+ private Endpoint(String host, int port) {
+ this.host = host;
+ this.port = port;
}
}
}
diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironment.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironment.java
new file mode 100644
index 000000000..4029ace5e
--- /dev/null
+++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironment.java
@@ -0,0 +1,295 @@
+package com.clickhouse.client;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.UUID;
+
+/**
+ * Integration-test target read from {@code TEST_*} environment variables.
+ */
+final class ClickHouseTestEnvironment {
+ static final String CONTAINER = "TEST_CLICKHOUSE_CONTAINER";
+ static final String IMAGE = "TEST_CLICKHOUSE_IMAGE";
+ static final String IMAGE_VERSION = "TEST_CLICKHOUSE_IMAGE_VERSION";
+ static final String VERSION = "TEST_CLICKHOUSE_VERSION";
+ static final String HOST = "TEST_CLICKHOUSE_HOST";
+ static final String USER = "TEST_CLICKHOUSE_USER";
+ static final String PASSWORD = "TEST_CLICKHOUSE_PASSWORD";
+ static final String SECURE = "TEST_CLICKHOUSE_SECURE";
+ static final String TIMEZONE = "TEST_CLICKHOUSE_TIMEZONE";
+ static final String ADDITIONAL_PACKAGES = "TEST_CLICKHOUSE_ADDITIONAL_PACKAGES";
+ static final String CONTAINER_ID = "TEST_CLICKHOUSE_CONTAINER_ID";
+ static final String DATABASE = "TEST_DB_NAME";
+ static final String PROXY_ADDRESS = "TEST_PROXY_ADDRESS";
+ static final String PROXY_IMAGE = "TEST_PROXY_IMAGE";
+
+ static final String DEFAULT_IMAGE = "clickhouse/clickhouse-server";
+ static final String DEFAULT_HOST = "localhost";
+ static final String DEFAULT_USER = "default";
+ static final String DEFAULT_PASSWORD = "test_default_password";
+ static final String DEFAULT_TIMEZONE = "UTC";
+ static final String DEFAULT_PROXY_IMAGE = "ghcr.io/shopify/toxiproxy:2.5.0";
+
+ enum ContainerMode {
+ SINGLE, CLUSTER, NONE
+ }
+
+ private final Map env;
+ private final ContainerMode containerMode;
+ private final String imageRef;
+ private final String clickHouseVersion;
+ private final String additionalPackages;
+ private final String host;
+ private final String user;
+ private final String password;
+ private final boolean secure;
+ private final String timezone;
+ private final String containerName;
+ private final String database;
+ private final boolean localDatabase;
+ private final String proxyHost;
+ private final int proxyPort;
+ private final String proxyImage;
+
+ private ClickHouseTestEnvironment(Map env, ContainerMode containerMode, String imageRef,
+ String clickHouseVersion, String additionalPackages, String host, String user, String password,
+ boolean secure, String timezone, String containerName, String database, boolean localDatabase,
+ String proxyHost, int proxyPort, String proxyImage) {
+ this.env = env;
+ this.containerMode = containerMode;
+ this.imageRef = imageRef;
+ this.clickHouseVersion = clickHouseVersion;
+ this.additionalPackages = additionalPackages;
+ this.host = host;
+ this.user = user;
+ this.password = password;
+ this.secure = secure;
+ this.timezone = timezone;
+ this.containerName = containerName;
+ this.database = database;
+ this.localDatabase = localDatabase;
+ this.proxyHost = proxyHost;
+ this.proxyPort = proxyPort;
+ this.proxyImage = proxyImage;
+ }
+
+ static final String REMOVED_VERSION_PROPERTY = "clickhouseVersion";
+
+ /**
+ * Fails the run when the removed {@code clickhouseVersion} system property is set.
+ * Image selection is {@code TEST_CLICKHOUSE_IMAGE_VERSION}.
+ */
+ static void rejectRemovedOptions(Properties properties) {
+ if (properties == null) {
+ return;
+ }
+ String version = properties.getProperty(REMOVED_VERSION_PROPERTY);
+ if (version != null && !version.trim().isEmpty()) {
+ throw new IllegalArgumentException("System property clickhouseVersion is no longer supported"
+ + " (was '" + version.trim() + "'). Set TEST_CLICKHOUSE_IMAGE_VERSION to select the"
+ + " container image.");
+ }
+ }
+
+ static ClickHouseTestEnvironment from(Map env) {
+ Map source = new HashMap();
+ if (env != null) {
+ source.putAll(env);
+ }
+
+ ContainerMode containerMode = parseMode(value(source, CONTAINER));
+
+ String imageName = value(source, IMAGE);
+ if (imageName == null) {
+ imageName = DEFAULT_IMAGE;
+ }
+ String requestedVersion = value(source, IMAGE_VERSION);
+ if (requestedVersion == null) {
+ requestedVersion = value(source, VERSION);
+ }
+ String clickHouseVersion;
+ String imageRef;
+ int tagIndex = imageName.indexOf(':');
+ int digestIndex = imageName.indexOf('@');
+ if (digestIndex > 0 && (tagIndex < 0 || digestIndex < tagIndex)) {
+ clickHouseVersion = "";
+ imageRef = imageName;
+ } else if (tagIndex > 0) {
+ clickHouseVersion = digestIndex > tagIndex ? imageName.substring(tagIndex + 1, digestIndex)
+ : imageName.substring(tagIndex + 1);
+ imageRef = imageName;
+ } else if (requestedVersion == null) {
+ clickHouseVersion = "";
+ imageRef = imageName;
+ } else {
+ clickHouseVersion = ClickHouseVersionUtils.of(requestedVersion).getYear() == 0 ? "" : requestedVersion;
+ imageRef = imageName + ":" + requestedVersion;
+ }
+
+ String additionalPackages = value(source, ADDITIONAL_PACKAGES);
+ if (ClickHouseVersionUtils.check(clickHouseVersion, "(,21.3]")) {
+ if (additionalPackages == null) {
+ additionalPackages = "tzdata";
+ } else if (!additionalPackages.contains("tzdata")) {
+ additionalPackages = additionalPackages + " tzdata";
+ }
+ }
+
+ String externalDatabase = value(source, DATABASE);
+ final String database;
+ final boolean localDatabase;
+ if (externalDatabase != null) {
+ if (!externalDatabase.startsWith("clickhouse_java_test_")) {
+ throw new RuntimeException("external database for tests should start with 'clickhouse_java_test_'");
+ }
+ localDatabase = false;
+ database = externalDatabase;
+ } else {
+ localDatabase = true;
+ database = "clickhouse_java_" + UUID.randomUUID().toString().substring(0, 8) + "_test_"
+ + System.currentTimeMillis();
+ }
+
+ String proxy = value(source, PROXY_ADDRESS);
+ final String proxyHost;
+ final int proxyPort;
+ final String proxyImage;
+ if (proxy != null) {
+ int index = proxy.indexOf(':');
+ if (index > 0) {
+ proxyHost = proxy.substring(0, index);
+ proxyPort = Integer.parseInt(proxy.substring(index + 1));
+ } else {
+ proxyHost = proxy;
+ proxyPort = 8666;
+ }
+ proxyImage = "";
+ } else {
+ proxyHost = "";
+ proxyPort = -1;
+ String image = value(source, PROXY_IMAGE);
+ proxyImage = image == null ? DEFAULT_PROXY_IMAGE : image;
+ }
+
+ String host = value(source, HOST);
+ String user = value(source, USER);
+ String password = value(source, PASSWORD);
+ String timezone = value(source, TIMEZONE);
+
+ return new ClickHouseTestEnvironment(Collections.unmodifiableMap(source), containerMode, imageRef,
+ clickHouseVersion, additionalPackages,
+ host == null ? DEFAULT_HOST : host,
+ user == null ? DEFAULT_USER : user,
+ password == null ? DEFAULT_PASSWORD : password,
+ parseSecure(value(source, SECURE)),
+ timezone == null ? DEFAULT_TIMEZONE : timezone,
+ value(source, CONTAINER_ID),
+ database, localDatabase, proxyHost, proxyPort, proxyImage);
+ }
+
+ String portOverride(ClickHouseProtocol protocol) {
+ return value(env, "TEST_CLICKHOUSE_" + protocol.name() + "_PORT");
+ }
+
+ ContainerMode getContainerMode() {
+ return containerMode;
+ }
+
+ String getImageRef() {
+ return imageRef;
+ }
+
+ String getClickHouseVersion() {
+ return clickHouseVersion;
+ }
+
+ String getAdditionalPackages() {
+ return additionalPackages;
+ }
+
+ String getHost() {
+ return host;
+ }
+
+ String getUser() {
+ return user;
+ }
+
+ String getPassword() {
+ return password;
+ }
+
+ boolean isSecure() {
+ return secure;
+ }
+
+ String getTimezone() {
+ return timezone;
+ }
+
+ String getContainerName() {
+ return containerName;
+ }
+
+ String getDatabase() {
+ return database;
+ }
+
+ boolean isLocalDatabase() {
+ return localDatabase;
+ }
+
+ String getProxyHost() {
+ return proxyHost;
+ }
+
+ int getProxyPort() {
+ return proxyPort;
+ }
+
+ String getProxyImage() {
+ return proxyImage;
+ }
+
+ private static ContainerMode parseMode(String raw) {
+ if (raw == null) {
+ return ContainerMode.SINGLE;
+ }
+ if ("single".equalsIgnoreCase(raw)) {
+ return ContainerMode.SINGLE;
+ }
+ if ("cluster".equalsIgnoreCase(raw)) {
+ return ContainerMode.CLUSTER;
+ }
+ if ("none".equalsIgnoreCase(raw)) {
+ return ContainerMode.NONE;
+ }
+ throw new IllegalArgumentException(
+ "TEST_CLICKHOUSE_CONTAINER must be single, cluster, or none, but was '" + raw + "'");
+ }
+
+ private static boolean parseSecure(String raw) {
+ if (raw == null) {
+ return false;
+ }
+ if ("true".equalsIgnoreCase(raw) || "1".equals(raw)) {
+ return true;
+ }
+ if ("false".equalsIgnoreCase(raw) || "0".equals(raw)) {
+ return false;
+ }
+ throw new IllegalArgumentException(
+ "TEST_CLICKHOUSE_SECURE must be true or false, but was '" + raw + "'");
+ }
+
+ private static String value(Map env, String key) {
+ String raw = env.get(key);
+ if (raw == null) {
+ return null;
+ }
+ String trimmed = raw.trim();
+ return trimmed.isEmpty() ? null : trimmed;
+ }
+}
diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironmentTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironmentTest.java
new file mode 100644
index 000000000..d3eddcfeb
--- /dev/null
+++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseTestEnvironmentTest.java
@@ -0,0 +1,176 @@
+package com.clickhouse.client;
+
+import org.testng.Assert;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+public class ClickHouseTestEnvironmentTest {
+ @DataProvider(name = "containerModes")
+ public static Object[][] containerModes() {
+ return new Object[][] {
+ { null, ClickHouseTestEnvironment.ContainerMode.SINGLE },
+ { "", ClickHouseTestEnvironment.ContainerMode.SINGLE },
+ { "single", ClickHouseTestEnvironment.ContainerMode.SINGLE },
+ { "SINGLE", ClickHouseTestEnvironment.ContainerMode.SINGLE },
+ { "cluster", ClickHouseTestEnvironment.ContainerMode.CLUSTER },
+ { " none ", ClickHouseTestEnvironment.ContainerMode.NONE }
+ };
+ }
+
+ @Test(dataProvider = "containerModes", groups = { "unit" })
+ public void testContainerMode(String raw, ClickHouseTestEnvironment.ContainerMode expected) {
+ ClickHouseTestEnvironment environment = ClickHouseTestEnvironment.from(env(ClickHouseTestEnvironment.CONTAINER, raw));
+ Assert.assertEquals(environment.getContainerMode(), expected);
+ }
+
+ @Test(groups = { "unit" })
+ public void testClickHouseVersionSystemPropertyIsRejected() {
+ Properties properties = new Properties();
+ properties.setProperty(ClickHouseTestEnvironment.REMOVED_VERSION_PROPERTY, "24.8");
+ try {
+ ClickHouseTestEnvironment.rejectRemovedOptions(properties);
+ Assert.fail("clickhouseVersion must be rejected");
+ } catch (IllegalArgumentException expected) {
+ Assert.assertTrue(expected.getMessage().contains("clickhouseVersion"));
+ Assert.assertTrue(expected.getMessage().contains("TEST_CLICKHOUSE_IMAGE_VERSION"));
+ }
+ }
+
+ @Test(groups = { "unit" })
+ public void testAbsentClickHouseVersionPropertyIsAllowed() {
+ ClickHouseTestEnvironment.rejectRemovedOptions(new Properties());
+ ClickHouseTestEnvironment.rejectRemovedOptions(null);
+ }
+
+ @Test(groups = { "unit" })
+ public void testRejectsUnknownContainerMode() {
+ try {
+ ClickHouseTestEnvironment.from(env(ClickHouseTestEnvironment.CONTAINER, "cloud"));
+ Assert.fail("cloud is not a container mode");
+ } catch (IllegalArgumentException expected) {
+ Assert.assertTrue(expected.getMessage().contains("single, cluster, or none"));
+ }
+ }
+
+ @DataProvider(name = "images")
+ public static Object[][] images() {
+ return new Object[][] {
+ { null, null, "clickhouse/clickhouse-server", "" },
+ { null, "24.8", "clickhouse/clickhouse-server:24.8", "24.8" },
+ { null, "latest", "clickhouse/clickhouse-server:latest", "" },
+ { "repo/clickhouse:24.3", "25.8", "repo/clickhouse:24.3", "24.3" },
+ { "repo/clickhouse:24.3@sha256:abc", null, "repo/clickhouse:24.3@sha256:abc", "24.3" },
+ { "repo/clickhouse@sha256:abc", null, "repo/clickhouse@sha256:abc", "" }
+ };
+ }
+
+ @Test(dataProvider = "images", groups = { "unit" })
+ public void testImageRef(String image, String version, String expectedRef, String expectedVersion) {
+ Map values = new HashMap();
+ if (image != null) {
+ values.put(ClickHouseTestEnvironment.IMAGE, image);
+ }
+ if (version != null) {
+ values.put(ClickHouseTestEnvironment.IMAGE_VERSION, version);
+ }
+ ClickHouseTestEnvironment environment = ClickHouseTestEnvironment.from(values);
+ Assert.assertEquals(environment.getImageRef(), expectedRef);
+ Assert.assertEquals(environment.getClickHouseVersion(), expectedVersion);
+ }
+
+ @Test(groups = { "unit" })
+ public void testVersionFallback() {
+ Map values = new HashMap();
+ values.put(ClickHouseTestEnvironment.VERSION, "26.9");
+ ClickHouseTestEnvironment environment = ClickHouseTestEnvironment.from(values);
+ Assert.assertEquals(environment.getImageRef(), "clickhouse/clickhouse-server:26.9");
+ Assert.assertEquals(environment.getClickHouseVersion(), "26.9");
+
+ // IMAGE_VERSION takes precedence over VERSION
+ values.put(ClickHouseTestEnvironment.IMAGE_VERSION, "25.8");
+ environment = ClickHouseTestEnvironment.from(values);
+ Assert.assertEquals(environment.getImageRef(), "clickhouse/clickhouse-server:25.8");
+ Assert.assertEquals(environment.getClickHouseVersion(), "25.8");
+ }
+
+ @Test(groups = { "unit" })
+ public void testOldClickHouseImageInstallsTzdata() {
+ ClickHouseTestEnvironment environment = ClickHouseTestEnvironment.from(
+ env(ClickHouseTestEnvironment.IMAGE_VERSION, "21.3"));
+ Assert.assertEquals(environment.getAdditionalPackages(), "tzdata");
+
+ Map values = env(ClickHouseTestEnvironment.IMAGE_VERSION, "21.3");
+ values.put(ClickHouseTestEnvironment.ADDITIONAL_PACKAGES, "ca-certificates");
+ Assert.assertEquals(ClickHouseTestEnvironment.from(values).getAdditionalPackages(),
+ "ca-certificates tzdata");
+ }
+
+ @Test(groups = { "unit" })
+ public void testCurrentImageDoesNotInstallTzdata() {
+ ClickHouseTestEnvironment environment = ClickHouseTestEnvironment.from(
+ env(ClickHouseTestEnvironment.IMAGE_VERSION, "24.8"));
+ Assert.assertNull(environment.getAdditionalPackages());
+ }
+
+ @Test(groups = { "unit" })
+ public void testConnectionDefaults() {
+ ClickHouseTestEnvironment environment = ClickHouseTestEnvironment.from(Collections.emptyMap());
+ Assert.assertEquals(environment.getHost(), "localhost");
+ Assert.assertEquals(environment.getUser(), "default");
+ Assert.assertEquals(environment.getPassword(), "test_default_password");
+ Assert.assertFalse(environment.isSecure());
+ Assert.assertEquals(environment.getTimezone(), "UTC");
+ Assert.assertTrue(environment.isLocalDatabase());
+ Assert.assertTrue(environment.getDatabase().startsWith("clickhouse_java_"));
+ }
+
+ @Test(groups = { "unit" })
+ public void testConnectionOverrides() {
+ Map values = new HashMap();
+ values.put(ClickHouseTestEnvironment.HOST, "cloud.example");
+ values.put(ClickHouseTestEnvironment.USER, "demo");
+ values.put(ClickHouseTestEnvironment.PASSWORD, "secret");
+ values.put(ClickHouseTestEnvironment.SECURE, "true");
+ values.put(ClickHouseTestEnvironment.CONTAINER, "none");
+ values.put("TEST_CLICKHOUSE_HTTP_PORT", "9440");
+ ClickHouseTestEnvironment environment = ClickHouseTestEnvironment.from(values);
+
+ Assert.assertEquals(environment.getHost(), "cloud.example");
+ Assert.assertEquals(environment.getUser(), "demo");
+ Assert.assertEquals(environment.getPassword(), "secret");
+ Assert.assertTrue(environment.isSecure());
+ Assert.assertEquals(environment.getContainerMode(), ClickHouseTestEnvironment.ContainerMode.NONE);
+ Assert.assertEquals(environment.portOverride(ClickHouseProtocol.HTTP), "9440");
+ }
+
+ @Test(groups = { "unit" })
+ public void testExternalDatabaseMustUseTestPrefix() {
+ try {
+ ClickHouseTestEnvironment.from(env(ClickHouseTestEnvironment.DATABASE, "default"));
+ Assert.fail("external database name must be rejected");
+ } catch (RuntimeException expected) {
+ Assert.assertTrue(expected.getMessage().contains("clickhouse_java_test_"));
+ }
+ }
+
+ @Test(groups = { "unit" })
+ public void testExternalDatabase() {
+ ClickHouseTestEnvironment environment = ClickHouseTestEnvironment.from(
+ env(ClickHouseTestEnvironment.DATABASE, "clickhouse_java_test_ci"));
+ Assert.assertFalse(environment.isLocalDatabase());
+ Assert.assertEquals(environment.getDatabase(), "clickhouse_java_test_ci");
+ }
+
+ private static Map env(String key, String value) {
+ Map values = new HashMap();
+ if (value != null) {
+ values.put(key, value);
+ }
+ return values;
+ }
+}
diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClusterClickHouseContainerStarter.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClusterClickHouseContainerStarter.java
new file mode 100644
index 000000000..9cd96dd7f
--- /dev/null
+++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClusterClickHouseContainerStarter.java
@@ -0,0 +1,132 @@
+package com.clickhouse.client;
+
+import org.testcontainers.containers.BindMode;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.Network;
+import org.testcontainers.containers.wait.strategy.Wait;
+
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+
+import static java.time.temporal.ChronoUnit.SECONDS;
+
+/**
+ * Three ClickHouse replicas of one shard, with a shared Keeper and nginx in front.
+ */
+final class ClusterClickHouseContainerStarter extends ClickHouseContainerStarter {
+ static final String CLUSTER_NAME = "test_cluster";
+ static final int NODE_COUNT = 3;
+ private static final String NGINX_CONFIG = "containers/nginx/nginx.conf";
+ private static final String KEEPER_CONFIG = "containers/clickhouse-keeper/keeper_config.xml";
+ private static final int KEEPER_PORT = 9181;
+
+ private final GenericContainer> keeper;
+ private final List> nodes;
+ private final GenericContainer> nginx;
+
+ ClusterClickHouseContainerStarter(ClickHouseTestEnvironment environment, Network network) {
+ super(environment, network);
+ String baseName = environment.getContainerName();
+ this.keeper = new GenericContainer<>(environment.getImageRef())
+ .withCreateContainerCmdModifier(command -> {
+ command.withEntrypoint("/bin/sh");
+ if (baseName != null) {
+ command.withName(baseName + "-keeper");
+ }
+ })
+ .withNetwork(network)
+ .withNetworkAliases("clickhouse-keeper")
+ .withCommand("-c", "mkdir -p /var/lib/clickhouse/coordination/log"
+ + " /var/lib/clickhouse/coordination/snapshots"
+ + " && exec clickhouse-keeper --config-file=/etc/clickhouse-keeper/keeper_config.xml")
+ .withClasspathResourceMapping(KEEPER_CONFIG, "/etc/clickhouse-keeper/keeper_config.xml",
+ BindMode.READ_ONLY)
+ .withExposedPorts(KEEPER_PORT)
+ .waitingFor(Wait.forLogMessage(".*Listening for.*", 1)
+ .withStartupTimeout(Duration.of(120, SECONDS)));
+
+ List> created = new ArrayList>(NODE_COUNT);
+ for (int index = 1; index <= NODE_COUNT; index++) {
+ String name = baseName == null ? null : baseName + "-" + index;
+ created.add(newClickHouseServer("clickhouse-" + index, name, "r" + index));
+ }
+ this.nodes = created;
+
+ String nginxName = baseName == null ? null : baseName + "-nginx";
+ this.nginx = newNginx(nginxName, NGINX_CONFIG);
+ }
+
+ @Override
+ public String replicatedClusterName() {
+ return CLUSTER_NAME;
+ }
+
+ @Override
+ public void start() {
+ List> started = new ArrayList>();
+ try {
+ keeper.start();
+ for (GenericContainer> node : nodes) {
+ node.start();
+ started.add(node);
+ }
+ nginx.start();
+ } catch (RuntimeException failure) {
+ stopQuietly(nginx);
+ for (int index = started.size() - 1; index >= 0; index--) {
+ stopQuietly(started.get(index));
+ }
+ stopQuietly(keeper);
+ throw failure;
+ }
+ }
+
+ @Override
+ public void stop() {
+ stopQuietly(nginx);
+ for (int index = nodes.size() - 1; index >= 0; index--) {
+ stopQuietly(nodes.get(index));
+ }
+ stopQuietly(keeper);
+ }
+
+ @Override
+ public boolean isRunning() {
+ if (!keeper.isRunning() || !nginx.isRunning()) {
+ return false;
+ }
+ for (GenericContainer> node : nodes) {
+ if (!node.isRunning()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public String getHost() {
+ return nginx.getHost();
+ }
+
+ @Override
+ public int getMappedPort(int port) {
+ return nginx.getMappedPort(port);
+ }
+
+ @Override
+ public Container.ExecResult execInContainer(String... command) throws Exception {
+ return nodes.get(0).execInContainer(command);
+ }
+
+ @Override
+ public GenericContainer> getEndpointContainer() {
+ return nginx;
+ }
+
+ @Override
+ protected List> clickHouseServers() {
+ return nodes;
+ }
+}
diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/SingleClickHouseContainerStarter.java b/clickhouse-client/src/test/java/com/clickhouse/client/SingleClickHouseContainerStarter.java
new file mode 100644
index 000000000..c996ec62a
--- /dev/null
+++ b/clickhouse-client/src/test/java/com/clickhouse/client/SingleClickHouseContainerStarter.java
@@ -0,0 +1,60 @@
+package com.clickhouse.client;
+
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.Network;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * One ClickHouse server, published on the Docker host.
+ */
+final class SingleClickHouseContainerStarter extends ClickHouseContainerStarter {
+ private final GenericContainer> container;
+
+ SingleClickHouseContainerStarter(ClickHouseTestEnvironment environment, Network network) {
+ super(environment, network);
+ this.container = newClickHouseServer(FRONTEND_ALIAS, environment.getContainerName());
+ }
+
+ @Override
+ public void start() {
+ container.start();
+ }
+
+ @Override
+ public void stop() {
+ stopQuietly(container);
+ }
+
+ @Override
+ public boolean isRunning() {
+ return container.isRunning();
+ }
+
+ @Override
+ public String getHost() {
+ return container.getHost();
+ }
+
+ @Override
+ public int getMappedPort(int port) {
+ return container.getMappedPort(port);
+ }
+
+ @Override
+ public Container.ExecResult execInContainer(String... command) throws Exception {
+ return container.execInContainer(command);
+ }
+
+ @Override
+ public GenericContainer> getEndpointContainer() {
+ return container;
+ }
+
+ @Override
+ protected List> clickHouseServers() {
+ return Collections.singletonList(container);
+ }
+}
diff --git a/clickhouse-client/src/test/resources/containers/clickhouse-cluster/config.d/custom_config.xml b/clickhouse-client/src/test/resources/containers/clickhouse-cluster/config.d/custom_config.xml
new file mode 100644
index 000000000..db7774164
--- /dev/null
+++ b/clickhouse-client/src/test/resources/containers/clickhouse-cluster/config.d/custom_config.xml
@@ -0,0 +1,96 @@
+
+ 18123
+ 8443
+ 9000
+ 9440
+ 9004
+ 9005
+ 9009
+
+ 9100
+
+
+
+ /etc/clickhouse-server/certs/localhost.crt
+ /etc/clickhouse-server/certs/localhost.key
+ relaxed
+ /etc/clickhouse-server/certs/marsnet_ca.crt
+ true
+ sslv2,sslv3
+ true
+
+
+ false
+ /etc/clickhouse-server/certs/marsnet_ca.crt
+ true
+ sslv2,sslv3
+ true
+ relaxed
+
+ RejectCertificateHandler
+
+
+
+
+ custom_
+
+
+
+
+
+ true
+
+ clickhouse-1
+ 9000
+ default
+ test_default_password
+
+
+ clickhouse-2
+ 9000
+ default
+ test_default_password
+
+
+ clickhouse-3
+ 9000
+ default
+ test_default_password
+
+
+
+
+
+
+ /clickhouse/task_queue/ddl
+
+
+ /var/lib/clickhouse/format_schemas/
+
+
+ test_cluster
+ s1
+
+
+
+ /clickhouse/tables/{uuid}/{shard}
+ {replica}
+
+
+
+ clickhouse-keeper
+ 9181
+
+
+
+
+
+ /etc/clickhouse-server/users.xml
+
+
+ /clickhouse/access/
+
+
+
+ 42
+
diff --git a/clickhouse-client/src/test/resources/containers/clickhouse-cluster/users.d/cluster_quorum.xml b/clickhouse-client/src/test/resources/containers/clickhouse-cluster/users.d/cluster_quorum.xml
new file mode 100644
index 000000000..29528d8e5
--- /dev/null
+++ b/clickhouse-client/src/test/resources/containers/clickhouse-cluster/users.d/cluster_quorum.xml
@@ -0,0 +1,10 @@
+
+
+
+
+ 3
+ 600000
+ ReplicatedMergeTree
+
+
+
diff --git a/clickhouse-client/src/test/resources/containers/clickhouse-keeper/keeper_config.xml b/clickhouse-client/src/test/resources/containers/clickhouse-keeper/keeper_config.xml
new file mode 100644
index 000000000..fd66e5634
--- /dev/null
+++ b/clickhouse-client/src/test/resources/containers/clickhouse-keeper/keeper_config.xml
@@ -0,0 +1,25 @@
+
+
+ information
+ 1
+
+
+ 0.0.0.0
+
+ 9181
+ 1
+ /var/lib/clickhouse/coordination/log
+ /var/lib/clickhouse/coordination/snapshots
+
+ 10000
+ 30000
+
+
+
+ 1
+ clickhouse-keeper
+ 9234
+
+
+
+
diff --git a/clickhouse-client/src/test/resources/containers/clickhouse-server/config.d/custom_config.xml b/clickhouse-client/src/test/resources/containers/clickhouse-server/config.d/custom_config.xml
index 6d6b60d3c..ac0897704 100644
--- a/clickhouse-client/src/test/resources/containers/clickhouse-server/config.d/custom_config.xml
+++ b/clickhouse-client/src/test/resources/containers/clickhouse-server/config.d/custom_config.xml
@@ -1,5 +1,5 @@
- 8123
+ 18123
8443
9000
9440
diff --git a/clickhouse-client/src/test/resources/containers/nginx/nginx.conf b/clickhouse-client/src/test/resources/containers/nginx/nginx.conf
new file mode 100644
index 000000000..d735f7e30
--- /dev/null
+++ b/clickhouse-client/src/test/resources/containers/nginx/nginx.conf
@@ -0,0 +1,95 @@
+worker_processes 1;
+error_log stderr notice;
+pid /tmp/nginx.pid;
+
+events {
+ worker_connections 1024;
+}
+
+http {
+ upstream clickhouse_http {
+ hash $http_x_clickhouse_replica_tag consistent;
+ server clickhouse-1:18123;
+ server clickhouse-2:18123;
+ server clickhouse-3:18123;
+ }
+
+ server {
+ listen 18123;
+ client_max_body_size 0;
+
+ location / {
+ proxy_pass http://clickhouse_http;
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_http_version 1.1;
+ proxy_read_timeout 3600s;
+ proxy_send_timeout 3600s;
+ proxy_request_buffering off;
+ proxy_buffering off;
+ }
+ }
+}
+
+# TCP passthrough to clickhouse-1, clickhouse-2, and clickhouse-3.
+stream {
+ proxy_connect_timeout 60s;
+ proxy_timeout 24h;
+
+ upstream clickhouse_https {
+ server clickhouse-1:8443;
+ server clickhouse-2:8443;
+ server clickhouse-3:8443;
+ }
+ upstream clickhouse_tcp {
+ server clickhouse-1:9000;
+ server clickhouse-2:9000;
+ server clickhouse-3:9000;
+ }
+ upstream clickhouse_tcp_secure {
+ server clickhouse-1:9440;
+ server clickhouse-2:9440;
+ server clickhouse-3:9440;
+ }
+ upstream clickhouse_mysql {
+ server clickhouse-1:9004;
+ server clickhouse-2:9004;
+ server clickhouse-3:9004;
+ }
+ upstream clickhouse_postgresql {
+ server clickhouse-1:9005;
+ server clickhouse-2:9005;
+ server clickhouse-3:9005;
+ }
+ upstream clickhouse_grpc {
+ server clickhouse-1:9100;
+ server clickhouse-2:9100;
+ server clickhouse-3:9100;
+ }
+
+ server {
+ listen 8443;
+ proxy_pass clickhouse_https;
+ }
+ server {
+ listen 9000;
+ proxy_pass clickhouse_tcp;
+ }
+ server {
+ listen 9440;
+ proxy_pass clickhouse_tcp_secure;
+ }
+ server {
+ listen 9004;
+ proxy_pass clickhouse_mysql;
+ }
+ server {
+ listen 9005;
+ proxy_pass clickhouse_postgresql;
+ }
+ server {
+ listen 9100;
+ proxy_pass clickhouse_grpc;
+ }
+}
diff --git a/client-v2/src/test/java/com/clickhouse/client/ClientFailoverTest.java b/client-v2/src/test/java/com/clickhouse/client/ClientFailoverTest.java
index 6a724151d..0392c9fae 100644
--- a/client-v2/src/test/java/com/clickhouse/client/ClientFailoverTest.java
+++ b/client-v2/src/test/java/com/clickhouse/client/ClientFailoverTest.java
@@ -96,7 +96,7 @@ public void testInsertFailoverToBackupNode() throws Exception {
.setDefaultDatabase(ClickHouseServerForTest.getDatabase())
.build()) {
adminClient.execute("DROP TABLE IF EXISTS failover_insert_test").get(10, TimeUnit.SECONDS).close();
- adminClient.execute("CREATE TABLE failover_insert_test (val UInt32) ENGINE MergeTree ORDER BY ()").get(10, TimeUnit.SECONDS).close();
+ adminClient.execute("CREATE TABLE failover_insert_test (val UInt32) ORDER BY ()").get(10, TimeUnit.SECONDS).close();
}
try (Client client = new Client.Builder()
diff --git a/client-v2/src/test/java/com/clickhouse/client/ClientTests.java b/client-v2/src/test/java/com/clickhouse/client/ClientTests.java
index 30e96cf4c..12214c7f5 100644
--- a/client-v2/src/test/java/com/clickhouse/client/ClientTests.java
+++ b/client-v2/src/test/java/com/clickhouse/client/ClientTests.java
@@ -552,7 +552,7 @@ public void testLogComment() throws Exception {
public void testServerSettings() throws Exception {
try (Client client = newClient().build()) {
client.execute("DROP TABLE IF EXISTS server_settings_test_table");
- client.execute("CREATE TABLE server_settings_test_table (v Float) Engine MergeTree ORDER BY ()");
+ client.execute("CREATE TABLE server_settings_test_table (v Float) ORDER BY ()");
final String queryId = UUID.randomUUID().toString();
InsertSettings insertSettings = new InsertSettings()
diff --git a/client-v2/src/test/java/com/clickhouse/client/HttpTransportTests.java b/client-v2/src/test/java/com/clickhouse/client/HttpTransportTests.java
index d05e0ac68..1d28ed5c9 100644
--- a/client-v2/src/test/java/com/clickhouse/client/HttpTransportTests.java
+++ b/client-v2/src/test/java/com/clickhouse/client/HttpTransportTests.java
@@ -618,7 +618,7 @@ public void testServerErrorHandling(ClickHouseFormat format, boolean serverCompr
}
- try (QueryResponse response = client.query("CREATE TABLE table_from_csv ENGINE MergeTree ORDER BY () AS SELECT * FROM file('empty.csv') ", querySettings)
+ try (QueryResponse response = client.query("CREATE TABLE table_from_csv ORDER BY () AS SELECT * FROM file('empty.csv') ", querySettings)
.get(1, TimeUnit.SECONDS)) {
Assert.fail("Expected exception");
} catch (ServerException e) {
@@ -1144,7 +1144,7 @@ public void testErrorWithSendProgressHeaders() throws Exception {
try (CommandResponse resp = client.execute("DROP TABLE IF EXISTS test_omm_table").get()) {
}
- try (CommandResponse resp = client.execute("CREATE TABLE test_omm_table ( val String) Engine = MergeTree ORDER BY () ").get()) {
+ try (CommandResponse resp = client.execute("CREATE TABLE test_omm_table ( val String) ORDER BY () ").get()) {
}
QuerySettings settings = new QuerySettings()
diff --git a/client-v2/src/test/java/com/clickhouse/client/ParameterizedQueryTest.java b/client-v2/src/test/java/com/clickhouse/client/ParameterizedQueryTest.java
index 8b1d32035..f56c43ab6 100644
--- a/client-v2/src/test/java/com/clickhouse/client/ParameterizedQueryTest.java
+++ b/client-v2/src/test/java/com/clickhouse/client/ParameterizedQueryTest.java
@@ -233,7 +233,7 @@ void testStringParams(String paramValue) throws Exception {
String column = "val";
client.execute("DROP TABLE IF EXISTS " + table).get();
client.execute("CREATE TABLE " + table + "(" + column + " String) "
- + "ENGINE = MergeTree ORDER BY tuple()").get();
+ + "ORDER BY tuple()").get();
client.query(
"INSERT INTO " + table + "(" + column + ") VALUES ('" + paramValue + "')").get();
try (QueryResponse r = client.query(
@@ -301,7 +301,7 @@ private void prepareDataSet(String table, List columns, List simplePOJOs = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
@@ -217,6 +218,7 @@ private Client.Builder clientBuilder(int proxyPort, boolean onlyNewImplementatio
.addEndpoint(Protocol.HTTP, "clickhouse", 8123, false)
.setUsername("default")
.setPassword(ClickHouseServerForTest.getPassword())
+ .setDefaultDatabase(ClickHouseServerForTest.getDatabase())
.addProxy(ProxyType.HTTP, "localhost", proxyPort);
}
diff --git a/client-v2/src/test/java/com/clickhouse/client/api/data_formats/AbstractJSONEachRowFormatReaderTests.java b/client-v2/src/test/java/com/clickhouse/client/api/data_formats/AbstractJSONEachRowFormatReaderTests.java
index b5225eb7b..a65d1269f 100644
--- a/client-v2/src/test/java/com/clickhouse/client/api/data_formats/AbstractJSONEachRowFormatReaderTests.java
+++ b/client-v2/src/test/java/com/clickhouse/client/api/data_formats/AbstractJSONEachRowFormatReaderTests.java
@@ -64,6 +64,7 @@ public void setUpPrimitivesTable() throws Exception {
.addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isCloud())
.setUsername("default")
.setPassword(ClickHouseServerForTest.getPassword())
+ .setDefaultDatabase(ClickHouseServerForTest.getDatabase())
.build()) {
setupClient.execute("DROP TABLE IF EXISTS " + primitivesTable).get().close();
@@ -74,7 +75,7 @@ public void setUpPrimitivesTable() throws Exception {
for (PrimitiveTypeCase c : PRIMITIVE_CASES) {
create.append(", ").append(c.columnName).append(' ').append(c.chType);
}
- create.append(") ENGINE = MergeTree ORDER BY id");
+ create.append(") ORDER BY id");
setupClient.execute(create.toString()).get().close();
StringBuilder insert = new StringBuilder("INSERT INTO ")
@@ -103,6 +104,7 @@ public void tearDownPrimitivesTable() throws Exception {
.addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isCloud())
.setUsername("default")
.setPassword(ClickHouseServerForTest.getPassword())
+ .setDefaultDatabase(ClickHouseServerForTest.getDatabase())
.build()) {
teardownClient.execute("DROP TABLE IF EXISTS " + primitivesTable).get().close();
}
@@ -115,6 +117,7 @@ public void setUp() {
.addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isCloud())
.setUsername("default")
.setPassword(ClickHouseServerForTest.getPassword())
+ .setDefaultDatabase(ClickHouseServerForTest.getDatabase())
.build();
}
diff --git a/client-v2/src/test/java/com/clickhouse/client/api/data_formats/GsonJSONEachRowFormatReaderTests.java b/client-v2/src/test/java/com/clickhouse/client/api/data_formats/GsonJSONEachRowFormatReaderTests.java
index 57f4e1abe..1953ce587 100644
--- a/client-v2/src/test/java/com/clickhouse/client/api/data_formats/GsonJSONEachRowFormatReaderTests.java
+++ b/client-v2/src/test/java/com/clickhouse/client/api/data_formats/GsonJSONEachRowFormatReaderTests.java
@@ -43,7 +43,7 @@ public void testRowToObject() throws Exception {
};
final String table = "test_row_to_object_json";
- final String createStmt = "CREATE TABLE IF NOT EXISTS " + table + " (key String, sensor1 Decimal, sensor2 Decimal, params JSON) Engine MergeTree Order By (key)";
+ final String createStmt = "CREATE TABLE IF NOT EXISTS " + table + " (key String, sensor1 Decimal, sensor2 Decimal, params JSON) Order By (key)";
client.execute(createStmt).get().close();
client.execute("TRUNCATE " + table).get().close();
diff --git a/client-v2/src/test/java/com/clickhouse/client/api/data_formats/RowBinaryTest.java b/client-v2/src/test/java/com/clickhouse/client/api/data_formats/RowBinaryTest.java
index 3235e2ec2..fef431e80 100644
--- a/client-v2/src/test/java/com/clickhouse/client/api/data_formats/RowBinaryTest.java
+++ b/client-v2/src/test/java/com/clickhouse/client/api/data_formats/RowBinaryTest.java
@@ -43,8 +43,7 @@ void testDefaultWithFunction() {
" v Int64 DEFAULT 10, " +
" fingerPrint UInt64 DEFAULT xxHash64(name)," +
" comments String" +
- ") ENGINE = MergeTree()" +
- "ORDER BY name;";
+ ") ORDER BY name;";
try (Client client = newClient().build()){
@@ -81,7 +80,7 @@ void testGetObjectArray1D() {
"fstr_arr Array(FixedString(4)), " +
"str_arr Array(String), " +
"int_arr Array(Int32)" +
- ") ENGINE = MergeTree() ORDER BY tuple()");
+ ") ORDER BY tuple()");
client.execute("INSERT INTO " + table + " VALUES (" +
"[100, 200, 18000044073709551615], " +
@@ -166,7 +165,7 @@ void testGetObjectArray2D() {
client.execute("CREATE TABLE " + table + " (" +
"arr2d_int Array(Array(Int64)), " +
"arr2d_str Array(Array(String))" +
- ") ENGINE = MergeTree() ORDER BY tuple()");
+ ") ORDER BY tuple()");
client.execute("INSERT INTO " + table + " VALUES (" +
"[[1, 2, 3], [4, 5]], " +
@@ -221,7 +220,7 @@ void testGetObjectArray3D() {
client.execute("DROP TABLE IF EXISTS " + table);
client.execute("CREATE TABLE " + table + " (" +
"arr3d Array(Array(Array(Int32)))" +
- ") ENGINE = MergeTree() ORDER BY tuple()");
+ ") ORDER BY tuple()");
client.execute("INSERT INTO " + table + " VALUES (" +
"[[[1, 2], [3]], [[4, 5, 6]]])");
@@ -280,7 +279,7 @@ void testGetObjectArrayWithEmptyArrays() {
client.execute("CREATE TABLE " + table + " (" +
"empty_arr Array(Int32), " +
"empty_2d Array(Array(String))" +
- ") ENGINE = MergeTree() ORDER BY tuple()");
+ ") ORDER BY tuple()");
client.execute("INSERT INTO " + table + " VALUES ([], [])");
@@ -313,7 +312,7 @@ void testGetObjectArrayMultipleRows() {
client.execute("CREATE TABLE " + table + " (" +
"id UInt32, " +
"arr Array(UInt64)" +
- ") ENGINE = MergeTree() ORDER BY id");
+ ") ORDER BY id");
client.execute("INSERT INTO " + table + " VALUES " +
"(1, [100, 200]), " +
diff --git a/client-v2/src/test/java/com/clickhouse/client/api/data_formats/internal/BaseReaderTests.java b/client-v2/src/test/java/com/clickhouse/client/api/data_formats/internal/BaseReaderTests.java
index 2cfea137d..2451cc35c 100644
--- a/client-v2/src/test/java/com/clickhouse/client/api/data_formats/internal/BaseReaderTests.java
+++ b/client-v2/src/test/java/com/clickhouse/client/api/data_formats/internal/BaseReaderTests.java
@@ -557,7 +557,7 @@ public static String tableDefinition(String table, String... columns) {
sb.append(s).append(", ");
});
sb.setLength(sb.length() - 2);
- sb.append(") Engine = MergeTree ORDER BY ()");
+ sb.append(") ORDER BY ()");
return sb.toString();
}
@@ -571,8 +571,9 @@ private Client.Builder newClient() {
ClickHouseNode node = getServer(ClickHouseProtocol.HTTP);
return new Client.Builder()
.addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isCloud())
- .setUsername("default")
- .setPassword(ClickHouseServerForTest.getPassword());
+ .setUsername(ClickHouseServerForTest.getUsername())
+ .setPassword(ClickHouseServerForTest.getPassword())
+ .setDefaultDatabase(ClickHouseServerForTest.getDatabase());
}
@Test(groups = {"integration"})
@@ -580,7 +581,7 @@ public void testReadingStringValue() throws Exception {
final String table = "test_reading_stringvalue";
client.execute("DROP TABLE IF EXISTS " + table).get();
- client.execute("CREATE TABLE " + table + " (id Int32, s String, fs FixedString(5), e FixedString(1)) ENGINE = MergeTree ORDER BY id").get();
+ client.execute("CREATE TABLE " + table + " (id Int32, s String, fs FixedString(5), e FixedString(1)) ORDER BY id").get();
client.execute("INSERT INTO " + table + " VALUES (1, 'hello', 'world', 'a'), (2, 'ClickHouse', 'Rocks', 'b')").get();
Client customClient = newClient()
@@ -703,7 +704,7 @@ public void testJsonStringPathsStayStringWithBinaryStringSupport() throws Except
CommandSettings commandSettings = new CommandSettings();
commandSettings.serverSetting("allow_experimental_json_type", "1");
client.execute("DROP TABLE IF EXISTS " + table, commandSettings).get();
- client.execute("CREATE TABLE " + table + " (id Int32, json JSON) ENGINE = MergeTree ORDER BY id", commandSettings).get();
+ client.execute("CREATE TABLE " + table + " (id Int32, json JSON) ORDER BY id", commandSettings).get();
client.execute("INSERT INTO " + table + " VALUES (1, '{\"name\" : \"hello\"}')", commandSettings).get();
Client customClient = newClient()
diff --git a/client-v2/src/test/java/com/clickhouse/client/api/data_formats/internal/BinaryReaderBackedRecordTest.java b/client-v2/src/test/java/com/clickhouse/client/api/data_formats/internal/BinaryReaderBackedRecordTest.java
index a73b36f7b..866a96055 100644
--- a/client-v2/src/test/java/com/clickhouse/client/api/data_formats/internal/BinaryReaderBackedRecordTest.java
+++ b/client-v2/src/test/java/com/clickhouse/client/api/data_formats/internal/BinaryReaderBackedRecordTest.java
@@ -58,7 +58,7 @@ public void testGetObjectArray() throws Exception {
"int_arr Array(Int32), " +
"arr2d Array(Array(Int64)), " +
"arr3d Array(Array(Array(Int32)))" +
- ") Engine = MergeTree ORDER BY rowId").get();
+ ") ORDER BY rowId").get();
client.execute("INSERT INTO " + table + " VALUES " +
"(1, " +
@@ -150,7 +150,7 @@ public void testGetObjectArrayEmptyAndEdgeCases() throws Exception {
"empty_arr Array(Int32), " +
"single_arr Array(String), " +
"arr2d_empty Array(Array(Int64))" +
- ") Engine = MergeTree ORDER BY rowId").get();
+ ") ORDER BY rowId").get();
client.execute("INSERT INTO " + table + " VALUES (1, [], ['single'], [[]])").get();
diff --git a/client-v2/src/test/java/com/clickhouse/client/api/transport/TransportBaseTests.java b/client-v2/src/test/java/com/clickhouse/client/api/transport/TransportBaseTests.java
index 3103cac5c..df4a8e0a0 100644
--- a/client-v2/src/test/java/com/clickhouse/client/api/transport/TransportBaseTests.java
+++ b/client-v2/src/test/java/com/clickhouse/client/api/transport/TransportBaseTests.java
@@ -509,7 +509,7 @@ public void testCancelRequest(String name, boolean async, boolean isInsert) thro
Runnable operation;
if (isInsert) {
Assert.assertTrue(runQuery("CREATE TABLE " + table +
- " (number UInt64) ENGINE = MergeTree ORDER BY number"), "[" + name + "] failed to create table");
+ " (number UInt64) ORDER BY number"), "[" + name + "] failed to create table");
operation = () -> {
// Endless input stream so the insert stays active on the server until the request is cancelled.
try (InsertResponse response = client.insert(table, endlessTsvStream(), ClickHouseFormat.TSV,
diff --git a/client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypeTests.java b/client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypeTests.java
index 70ba11b23..06a6da63c 100644
--- a/client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypeTests.java
+++ b/client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypeTests.java
@@ -82,8 +82,9 @@ public void setUp() throws IOException {
ClickHouseNode node = getServer(ClickHouseProtocol.HTTP);
client = new Client.Builder()
.addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isCloud())
- .setUsername("default")
+ .setUsername(ClickHouseServerForTest.getUsername())
.setPassword(ClickHouseServerForTest.getPassword())
+ .setDefaultDatabase(ClickHouseServerForTest.getDatabase())
.compressClientRequest(useClientCompression)
.useHttpCompression(useHttpCompression)
.build();
@@ -608,7 +609,7 @@ public void testBFloat16ReadFromServerWrittenValues() throws Exception {
final int batchSize = 4096; // keep each INSERT well under max_query_size
client.execute("DROP TABLE IF EXISTS " + table).get();
client.execute("CREATE TABLE " + table
- + " (rowId Int32, v BFloat16, vNull Nullable(BFloat16)) ENGINE = MergeTree ORDER BY rowId").get();
+ + " (rowId Int32, v BFloat16, vNull Nullable(BFloat16)) ORDER BY rowId").get();
for (int start = 0; start < count; start += batchSize) {
int end = Math.min(start + batchSize, count);
@@ -839,7 +840,7 @@ public void testVariantWithSimpleDataTypes() throws Exception {
continue dataTypesLoop;
}
- b.append(")) Engine = MergeTree ORDER BY ()");
+ b.append(")) ORDER BY ()");
client.execute(b.toString(),
(CommandSettings) new CommandSettings().serverSetting("allow_experimental_variant_type", "1"));
@@ -1236,7 +1237,7 @@ public void testDynamicWithPrimitives() throws Exception {
client.execute("DROP TABLE IF EXISTS " + table).get();
String createTableStatement = " CREATE TABLE " + table + "( rowId Int64, field Dynamic ) " +
- "Engine = MergeTree ORDER BY ()";
+ "ORDER BY ()";
client.execute(createTableStatement, (CommandSettings) new CommandSettings().serverSetting("allow_experimental_dynamic_type", "1"));
client.register(DTOForDynamicPrimitivesTests.class, client.getTableSchema(table));
@@ -2656,7 +2657,7 @@ public void testGetObjectArrayMethods() throws Exception {
"int_arr Array(Int32), " +
"arr2d Array(Array(Int64)), " +
"arr3d Array(Array(Array(Int32)))" +
- ") Engine = MergeTree ORDER BY rowId").get();
+ ") ORDER BY rowId").get();
client.execute("INSERT INTO " + table + " VALUES " +
"(1, " +
@@ -2838,7 +2839,7 @@ public void testGetStringArrayAndGetObjectArrayWhenValueIsList() throws Exceptio
"rowId Int32, " +
"str_arr Array(String), " +
"arr2d Array(Array(Int32))" +
- ") Engine = MergeTree ORDER BY rowId").get();
+ ") ORDER BY rowId").get();
client.execute("INSERT INTO " + table + " VALUES " +
"(1, ['hello', 'world'], [[1, 2], [3]])").get();
@@ -2934,7 +2935,7 @@ public void testJSONSubPathAccess(String query, Object[] expectedValues) throws
CommandSettings jsonSettings = (CommandSettings) new CommandSettings()
.serverSetting("enable_json_type", "1")
.serverSetting("allow_experimental_json_type", "1");
- client.execute("CREATE TABLE " + table + " (`i` Int64, `j` JSON) ENGINE = MergeTree ORDER BY i",
+ client.execute("CREATE TABLE " + table + " (`i` Int64, `j` JSON) ORDER BY i",
jsonSettings).get().close();
client.execute("INSERT INTO " + table + " VALUES " +
"(1, '{\"m\":{\"a\":[{\"d\": 9000}]}}'), " +
@@ -3199,7 +3200,7 @@ public static String tableDefinition(String table, String... columns) {
sb.append(s).append(", ");
});
sb.setLength(sb.length() - 2);
- sb.append(") Engine = MergeTree ORDER BY ()");
+ sb.append(") ORDER BY ()");
return sb.toString();
}
@@ -3231,6 +3232,7 @@ private Client.Builder newClient() {
.addEndpoint(Protocol.HTTP, node.getHost(), node.getPort(), isCloud())
.setUsername("default")
.setPassword(ClickHouseServerForTest.getPassword())
+ .setDefaultDatabase(ClickHouseServerForTest.getDatabase())
.compressClientRequest(useClientCompression)
.useHttpCompression(useHttpCompression);
}
diff --git a/client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypesTestingPOJO.java b/client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypesTestingPOJO.java
index bc8a431d0..cfb9915c9 100644
--- a/client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypesTestingPOJO.java
+++ b/client-v2/src/test/java/com/clickhouse/client/datatypes/DataTypesTestingPOJO.java
@@ -332,7 +332,7 @@ public static String generateTableCreateSQL(String tableName) {
"intervalMillisecond IntervalNanosecond, " +
"intervalMicrosecond IntervalNanosecond, " +
"intervalNanosecond IntervalNanosecond " +
- ") ENGINE = MergeTree ORDER BY ()";
+ ") ORDER BY ()";
}
public enum SmallEnum {
diff --git a/client-v2/src/test/java/com/clickhouse/client/datatypes/RowBinaryFormatWriterTest.java b/client-v2/src/test/java/com/clickhouse/client/datatypes/RowBinaryFormatWriterTest.java
index 78ed3f698..a59c1e40c 100644
--- a/client-v2/src/test/java/com/clickhouse/client/datatypes/RowBinaryFormatWriterTest.java
+++ b/client-v2/src/test/java/com/clickhouse/client/datatypes/RowBinaryFormatWriterTest.java
@@ -253,7 +253,7 @@ public void writeMissingFieldsTest() throws Exception {
String tableCreate = "CREATE TABLE \"" + tableName + "\" " +
" (id Int32, " +
" int8 Int8, int8_nullable Nullable(Int8), int8_default Int8 DEFAULT 3 " +
- " ) Engine = MergeTree ORDER BY id";
+ " ) ORDER BY id";
// Insert random (valid) values
long seed = System.currentTimeMillis();
@@ -277,7 +277,7 @@ public void writeEnumZeroLikeValuesTest() throws Exception {
" e8 Enum8('' = 0, 'a' = 1, 'neg' = -5), " +
" e16 Enum16('zero' = 0, 'big' = 30000, 'nb' = -20000), " +
" tail Float64" +
- " ) Engine = MergeTree ORDER BY id";
+ " ) ORDER BY id";
Field[][] rows = new Field[][] {
// Zero-like written by enum name: an empty-string name and a named zero both map to 0.
@@ -314,7 +314,7 @@ private Object[][] nullEnumContainers() {
public void writeNullEnumInContainerThrowsTest(String columnType, Object valueWithNullEnum) throws Exception {
String tableName = "rowBinaryFormatWriterTest_enumContainerNull_" + UUID.randomUUID().toString().replace('-', '_');
initTable(tableName,
- "CREATE TABLE \"" + tableName + "\" (id Int32, c " + columnType + ") Engine = MergeTree ORDER BY id",
+ "CREATE TABLE \"" + tableName + "\" (id Int32, c " + columnType + ") ORDER BY id",
new CommandSettings());
TableSchema schema = client.getTableSchema(tableName);
ClickHouseFormat format = ClickHouseFormat.RowBinaryWithDefaults;
@@ -360,7 +360,7 @@ private Object[][] rowBinaryWriterFormats() {
public void writeNullIntoNonNullableArrayThrowsTest(ClickHouseFormat format) throws Exception {
String tableName = "rowBinaryFormatWriterTest_nonNullableArrayNull_" + UUID.randomUUID().toString().replace('-', '_');
initTable(tableName,
- "CREATE TABLE \"" + tableName + "\" (id Int32, arr Array(Int32), tail Int32) Engine = MergeTree ORDER BY id",
+ "CREATE TABLE \"" + tableName + "\" (id Int32, arr Array(Int32), tail Int32) ORDER BY id",
new CommandSettings());
TableSchema schema = client.getTableSchema(tableName);
@@ -391,7 +391,7 @@ public void writeNullIntoNonNullableArrayThrowsTest(ClickHouseFormat format) thr
public void writeNonNullableArrayRoundTripsTest(ClickHouseFormat format) throws Exception {
String tableName = "rowBinaryFormatWriterTest_nonNullableArrayRoundTrip_" + UUID.randomUUID().toString().replace('-', '_');
initTable(tableName,
- "CREATE TABLE \"" + tableName + "\" (id Int32, arr Array(Int32), tail Int32) Engine = MergeTree ORDER BY id",
+ "CREATE TABLE \"" + tableName + "\" (id Int32, arr Array(Int32), tail Int32) ORDER BY id",
new CommandSettings());
TableSchema schema = client.getTableSchema(tableName);
@@ -429,7 +429,7 @@ public void writeNonNullableArrayRoundTripsTest(ClickHouseFormat format) throws
public void writeNullIntoDefaultedArrayUsesDefaultTest() throws Exception {
String tableName = "rowBinaryFormatWriterTest_defaultedArrayNull_" + UUID.randomUUID().toString().replace('-', '_');
initTable(tableName,
- "CREATE TABLE \"" + tableName + "\" (id Int32, arr Array(Int32) DEFAULT [1, 2], tail Int32) Engine = MergeTree ORDER BY id",
+ "CREATE TABLE \"" + tableName + "\" (id Int32, arr Array(Int32) DEFAULT [1, 2], tail Int32) ORDER BY id",
new CommandSettings());
TableSchema schema = client.getTableSchema(tableName);
ClickHouseFormat format = ClickHouseFormat.RowBinaryWithDefaults;
@@ -474,7 +474,7 @@ public void writeNumbersTest() throws Exception {
" float32 Float32, float32_nullable Nullable(Float32), float32_default Float32 DEFAULT 3, " +
" float64 Float64, float64_nullable Nullable(Float64), float64_default Float64 DEFAULT 3, " +
// " bfloat16 BFloat16, bfloat16_nullable Nullable(BFloat16), bfloat16_default BFloat16 DEFAULT 3, " +
- " ) Engine = MergeTree ORDER BY id";
+ " ) ORDER BY id";
// Insert random (valid) values
long seed = System.currentTimeMillis();
@@ -514,7 +514,7 @@ public void writeDecimalsTest() throws Exception {
" decimal64 Decimal(18, 6), decimal64_nullable Nullable(Decimal(18, 6)), decimal64_default Decimal(18, 6) DEFAULT 3, " +
" decimal128 Decimal(36, 8), decimal128_nullable Nullable(Decimal(36, 8)), decimal128_default Decimal(36, 8) DEFAULT 3, " +
" decimal256 Decimal(74, 10), decimal256_nullable Nullable(Decimal(74, 10)), decimal256_default Decimal(74, 10) DEFAULT 3" +
- " ) Engine = MergeTree ORDER BY id";
+ " ) ORDER BY id";
// Insert random (valid) values
long seed = System.currentTimeMillis();
@@ -551,7 +551,7 @@ public void writeStringsTest() throws Exception {
" enum Enum('a' = 1, 'b' = 2), enum_nullable Nullable(Enum('a' = 1, 'b' = 2)), enum_default Enum('a' = 1, 'b' = 2) DEFAULT 'a', " +
" enum8 Enum8('a' = 1, 'b' = 2), enum8_nullable Nullable(Enum8('a' = 1, 'b' = 2)), enum8_default Enum8('a' = 1, 'b' = 2) DEFAULT 'a', " +
" enum16 Enum16('a' = 1, 'b' = 2), enum16_nullable Nullable(Enum16('a' = 1, 'b' = 2)), enum16_default Enum16('a' = 1, 'b' = 2) DEFAULT 'a', " +
- " ) Engine = MergeTree ORDER BY id";
+ " ) ORDER BY id";
// Insert random (valid) values
Field[][] rows = new Field[][] {{
@@ -594,7 +594,7 @@ private Object[][] stringValuesForUInt64AndUUID() {
public void writeStringIntoUInt64AndUUIDTest(String columnType, Object value, String expected) throws Exception {
String tableName = "rowBinaryFormatWriterTest_stringUInt64UUID_" + UUID.randomUUID().toString().replace('-', '_');
initTable(tableName,
- "CREATE TABLE \"" + tableName + "\" (id Int32, c " + columnType + ", tail Float64) Engine = MergeTree ORDER BY id",
+ "CREATE TABLE \"" + tableName + "\" (id Int32, c " + columnType + ", tail Float64) ORDER BY id",
new CommandSettings());
TableSchema schema = client.getTableSchema(tableName);
ClickHouseFormat format = ClickHouseFormat.RowBinaryWithDefaults;
@@ -625,7 +625,7 @@ public void writeBinaryStringsTest() throws Exception {
" string String, " +
" fixed_string FixedString(5), " +
" fixed_string_one FixedString(1) " +
- " ) Engine = MergeTree ORDER BY id";
+ " ) ORDER BY id";
// Row 1 is written via setValue(byte[]), row 2 via setString(byte[]); use distinct
// payloads per row so the rows are not identical (identical rows would be collapsed
@@ -691,7 +691,7 @@ public void writeAndReadImageTest() throws Exception {
String tableName = "rowBinaryFormatWriterTest_writeAndReadImageTest_" + UUID.randomUUID().toString().replace('-', '_');
String tableCreate = "CREATE TABLE \"" + tableName + "\" " +
- " (id Int32, image String) Engine = MergeTree ORDER BY id";
+ " (id Int32, image String) ORDER BY id";
initTable(tableName, tableCreate, new CommandSettings());
TableSchema schema = client.getTableSchema(tableName);
@@ -761,7 +761,7 @@ public void writeDatetimeTests() throws Exception {
" datetime64 DateTime64, datetime64_nullable Nullable(DateTime64), datetime64_default DateTime64 DEFAULT '2025-01-01 00:00:00', " +
" date Date, date_nullable Nullable(Date), date_default Date DEFAULT '2020-01-01', " +
" date32 Date32, date32_nullable Nullable(Date32), date32_default Date32 DEFAULT '2025-01-01', " +
- " ) Engine = MergeTree ORDER BY id";
+ " ) ORDER BY id";
// Insert random (valid) values
Field[][] rows = new Field[][] {{
@@ -783,7 +783,7 @@ public void writeTupleTests() throws Exception {
String tableCreate = "CREATE TABLE \"" + tableName + "\" " +
" (id Int32, " +
" tuple Tuple(Int8, Int16), tuple_default Tuple(Int8, Int16) DEFAULT (3, 4), " +
- " ) Engine = MergeTree ORDER BY id";
+ " ) ORDER BY id";
// Insert random (valid) values
Field[][] rows = new Field[][] {{
@@ -802,7 +802,7 @@ public void writeIpAddressTests() throws Exception {
" (id Int32, " +
" ipv4 IPv4, ipv4_nullable Nullable(IPv4), ipv4_default IPv4 DEFAULT '127.0.0.1', " +
" ipv6 IPv6, ipv6_nullable Nullable(IPv6), ipv6_default IPv6 DEFAULT '::1', " +
- " ) Engine = MergeTree ORDER BY id";
+ " ) ORDER BY id";
// Insert random (valid) values
Field[][] rows = new Field[][] {{
@@ -820,7 +820,7 @@ public void writeArrayTests() throws Exception {
String tableCreate = "CREATE TABLE \"" + tableName + "\" " +
" (id Int32, " +
" array Array(Int8), array_default Array(Int8) DEFAULT [3], " +
- " ) Engine = MergeTree ORDER BY id";
+ " ) ORDER BY id";
// Insert random (valid) values
Field[][] rows = new Field[][] {{
@@ -848,7 +848,7 @@ public void writeGeometryTests() throws Exception {
" multilinestring MultiLineString, multilinestring_default MultiLineString DEFAULT [[(0, 0), (10, 0), (10, 10), (0, 10)]], " +
" polygon Polygon, polygon_default Polygon DEFAULT [[(0, 0), (10, 0), (10, 10), (0, 10)]], " +
" multipolygon MultiPolygon, multipolygon_default MultiPolygon DEFAULT [[[(0, 0), (10, 0), (10, 10), (0, 10)]]], " +
- " ) Engine = MergeTree ORDER BY id";
+ " ) ORDER BY id";
// Insert random (valid) values
Field[][] rows = new Field[][] {{
@@ -873,7 +873,7 @@ public void writeMapTests() throws Exception {
String tableCreate = "CREATE TABLE \"" + tableName + "\" " +
" (id Int32, " +
" map Map(String, Int16) " +
- " ) Engine = MergeTree ORDER BY id";
+ " ) ORDER BY id";
Map tmpMap = new HashMap<>();
tmpMap.put("a", 1);
@@ -895,7 +895,7 @@ public void writeNestedTests() throws Exception {
String tableCreate = "CREATE TABLE \"" + tableName + "\" " +
" (id Int32, " +
" nested Nested(n1 Int8, n2 Int16) " +
- " ) Engine = MergeTree ORDER BY id";
+ " ) ORDER BY id";
// Insert random (valid) values
Field[][] rows = new Field[][] {{
@@ -917,7 +917,7 @@ public void writeNestedTypeTests() throws Exception {
String tableCreate = "CREATE TABLE \"" + tableName + "\" " +
" (id Int32, " +
" n Nested(a UInt32, b Nullable(String)) " +
- " ) Engine = MergeTree ORDER BY id SETTINGS flatten_nested = 0";
+ " ) ORDER BY id SETTINGS flatten_nested = 0";
List