Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add product tests for clickhouse clusters #10956

Merged
Merged
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: 0 additions & 7 deletions plugin/trino-clickhouse/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,7 @@
<dependency>
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.3.2-patch3</version>
<classifier>all</classifier>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,19 @@
<version>2.9.5</version>
</dependency>

<dependency>
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.3.2-patch3</version>
<classifier>all</classifier>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.esri.geometry</groupId>
<artifactId>esri-geometry-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ private static void enablePrestoJavaDebugger(DockerContainer container, String c
try {
FileAttribute<Set<PosixFilePermission>> rwx = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwxrwxrwx"));
Path script = Files.createTempFile("enable-java-debugger", ".sh", rwx);
script.toFile().deleteOnExit();
Files.writeString(
script,
format(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.tests.product.launcher.env.environment;

import io.trino.tests.product.launcher.docker.DockerFiles;
import io.trino.tests.product.launcher.docker.DockerFiles.ResourceProvider;
import io.trino.tests.product.launcher.env.DockerContainer;
import io.trino.tests.product.launcher.env.Environment.Builder;
import io.trino.tests.product.launcher.env.EnvironmentProvider;
import io.trino.tests.product.launcher.env.common.StandardMultinode;
import io.trino.tests.product.launcher.env.common.TestsEnvironment;
import io.trino.tests.product.launcher.testcontainers.PortBinder;
import org.testcontainers.containers.startupcheck.IsRunningStartupCheckStrategy;

import javax.inject.Inject;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.time.Duration;
import java.util.Set;

import static io.trino.tests.product.launcher.docker.ContainerUtil.forSelectedPorts;
import static io.trino.tests.product.launcher.env.EnvironmentContainers.COORDINATOR;
import static io.trino.tests.product.launcher.env.EnvironmentContainers.WORKER;
import static io.trino.tests.product.launcher.env.EnvironmentContainers.configureTempto;
import static io.trino.tests.product.launcher.env.common.Standard.CONTAINER_PRESTO_ETC;
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import static org.testcontainers.utility.MountableFile.forHostPath;

@TestsEnvironment
public class EnvMultinodeClickhouse
extends EnvironmentProvider
{
private static final String ZOOKEEPER = "zookeeper";

private static final String CLICKHOUSE = "clickhouse";
private static final String CLICKHOUSE_NTH = CLICKHOUSE + "-";
private static final String CONTAINER_CLICKHOUSE_CONFIG_DIR = "/etc/clickhouse-server/";
private static final String CONTAINER_CLICKHOUSE_USERS_D = CONTAINER_CLICKHOUSE_CONFIG_DIR + "users.d/";
private static final String CONTAINER_CLICKHOUSE_CONFIG_D = CONTAINER_CLICKHOUSE_CONFIG_DIR + "config.d/";
private static final int CLICKHOUSE_DEFAULT_HTTP_PORT = 8123;
private static final int CLICKHOUSE_DEFAULT_NATIVE_PORT = 9000;

private final DockerFiles dockerFiles;
private final ResourceProvider configDir;
private final PortBinder portBinder;

@Inject
public EnvMultinodeClickhouse(StandardMultinode standardMultinode, DockerFiles dockerFiles, PortBinder portBinder)
{
super(standardMultinode);
this.dockerFiles = requireNonNull(dockerFiles, "dockerFiles is null");
this.configDir = requireNonNull(dockerFiles, "dockerFiles is null").getDockerFilesHostDirectory("conf/environment/multinode-clickhouse/");
this.portBinder = requireNonNull(portBinder, "portBinder is null");
}

@Override
public void extendEnvironment(Builder builder)
{
builder.configureContainer(COORDINATOR, this::addCatalogs);
builder.configureContainer(WORKER, this::addCatalogs);

builder.addContainers(
createZookeeper(portBinder),
createClickHouse(1, dockerFiles, portBinder),
createClickHouse(2, dockerFiles, portBinder),
createClickHouse(3, dockerFiles, portBinder))
.containerDependsOn(logicalName(1), ZOOKEEPER)
.containerDependsOn(logicalName(2), ZOOKEEPER)
.containerDependsOn(logicalName(3), ZOOKEEPER);

builder.configureContainer(ZOOKEEPER, container -> container.withNetworkAliases(container.getLogicalName(), "localhost"));
builder.configureContainer(logicalName(1), container -> container.withNetworkAliases(CLICKHOUSE, container.getLogicalName(), "localhost"));
builder.configureContainer(logicalName(2), container -> container.withNetworkAliases(container.getLogicalName(), "localhost"));
builder.configureContainer(logicalName(3), container -> container.withNetworkAliases(container.getLogicalName(), "localhost"));

configureTempto(builder, configDir);
}

private void addCatalogs(DockerContainer container)
{
container
.withCopyFileToContainer(
forHostPath(configDir.getPath("clickhouse.properties")),
CONTAINER_PRESTO_ETC + "/catalog/clickhouse.properties");
}

private static DockerContainer createZookeeper(PortBinder portBinder)
{
DockerContainer container = new DockerContainer("zookeeper:3.7.0", ZOOKEEPER)
.withEnv("ZOOKEEPER_CLIENT_PORT", "2181")
.withEnv("ZOOKEEPER_TICK_TIME", "2000")
.withStartupCheckStrategy(new IsRunningStartupCheckStrategy())
.waitingFor(forSelectedPorts(2181))
.withStartupTimeout(Duration.ofMinutes(5));

portBinder.exposePort(container, 2181);

return container;
}

private static DockerContainer createClickHouse(int number, DockerFiles dockerFiles, PortBinder portBinder)
{
int httpPort = CLICKHOUSE_DEFAULT_HTTP_PORT + number;
int nativePort = CLICKHOUSE_DEFAULT_NATIVE_PORT + number;

DockerContainer container = new DockerContainer("yandex/clickhouse-server:21.3.2.5", logicalName(number))
.withCopyFileToContainer(
forHostPath(dockerFiles.getDockerFilesHostPath("conf/environment/multinode-clickhouse/test.xml")),
CONTAINER_CLICKHOUSE_USERS_D + "test.xml")
.withCopyFileToContainer(
forHostPath(dockerFiles.getDockerFilesHostPath("conf/environment/multinode-clickhouse/metrika.xml")),
CONTAINER_CLICKHOUSE_CONFIG_D + "metrika.xml")
.withStartupCheckStrategy(new IsRunningStartupCheckStrategy())
.waitingFor(forSelectedPorts(httpPort, nativePort))
.withStartupTimeout(Duration.ofMinutes(5));

modifyDefaultPorts(container, httpPort, nativePort);

portBinder.exposePort(container, httpPort);
portBinder.exposePort(container, nativePort);

return container;
}

private static String logicalName(int number)
{
return CLICKHOUSE_NTH + number;
}

private static void modifyDefaultPorts(DockerContainer container, int httpPort, int nativePort)
{
try {
FileAttribute<Set<PosixFilePermission>> rwx = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwxrwxrwx"));
Path customConfig = Files.createTempFile("custom", ".xml", rwx);
customConfig.toFile().deleteOnExit();
Files.writeString(
customConfig,
format(
"<?xml version=\"1.0\"?>\n" +
"<yandex>\n" +
" <http_port>%s</http_port>\n" +
" <tcp_port>%s</tcp_port>\n" +
"</yandex>\n",
httpPort,
nativePort),
UTF_8);
container.withCopyFileToContainer(forHostPath(customConfig), CONTAINER_CLICKHOUSE_CONFIG_D + "custom.xml");
}
catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.google.common.collect.ImmutableList;
import io.trino.tests.product.launcher.env.EnvironmentConfig;
import io.trino.tests.product.launcher.env.EnvironmentDefaults;
import io.trino.tests.product.launcher.env.environment.EnvMultinodeClickhouse;
import io.trino.tests.product.launcher.env.environment.EnvSinglenodeHiveIcebergRedirections;
import io.trino.tests.product.launcher.env.environment.EnvSinglenodeKerberosHdfsImpersonationCrossRealm;
import io.trino.tests.product.launcher.env.environment.EnvSinglenodeMysql;
Expand Down Expand Up @@ -45,6 +46,7 @@ public List<SuiteTestRun> getTestRuns(EnvironmentConfig config)
testOnEnvironment(EnvSinglenodeMysql.class).withGroups("mysql").build(),
testOnEnvironment(EnvSinglenodePostgresql.class).withGroups("postgresql").build(),
testOnEnvironment(EnvSinglenodeSqlserver.class).withGroups("sqlserver").build(),
testOnEnvironment(EnvMultinodeClickhouse.class).withGroups("clickhouse").build(),
testOnEnvironment(EnvSinglenodeSparkHive.class).withGroups("hive_spark").build(),
testOnEnvironment(EnvSinglenodeSparkIceberg.class).withGroups("iceberg").withExcludedGroups("storage_formats").build(),
testOnEnvironment(EnvSinglenodeHiveIcebergRedirections.class).withGroups("hive_iceberg_redirections").build(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
connector.name=clickhouse
connection-url=jdbc:clickhouse://clickhouse:8124/
tangjiangling marked this conversation as resolved.
Show resolved Hide resolved
connection-user=test
connection-password=test
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0"?>
<yandex>
<remote_servers>
<test_cluster>
<shard>
<replica>
<host>clickhouse-1</host>
<port>9001</port>
</replica>
</shard>
<shard>
<replica>
<host>clickhouse-2</host>
<port>9002</port>
</replica>
</shard>
<shard>
<replica>
<host>clickhouse-3</host>
<port>9003</port>
</replica>
</shard>
</test_cluster>
</remote_servers>

<zookeeper>
<node>
<host>zookeeper</host>
<port>2181</port>
</node>
</zookeeper>

<macros>
<shard>01</shard>
<replica>01</replica>
</macros>
</yandex>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
databases:
presto:
jdbc_url: "jdbc:trino://${databases.presto.host}:${databases.presto.port}/clickhouse/default"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<yandex>
<users>
<test>
<password>test</password>
<networks>
<ip>::/0</ip>
</networks>
<profile>default</profile>
<quota>default</quota>
</test>
</users>
</yandex>
7 changes: 7 additions & 0 deletions testing/trino-product-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<classifier>all</classifier>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public final class TestGroups
public static final String ICEBERG = "iceberg";
public static final String AVRO = "avro";
public static final String PHOENIX = "phoenix";
public static final String CLICKHOUSE = "clickhouse";

private TestGroups() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.tests.product.clickhouse;

import io.trino.tempto.ProductTest;
import io.trino.tempto.query.QueryResult;
import org.testng.annotations.Test;

import static io.trino.tempto.assertions.QueryAssert.Row.row;
import static io.trino.tempto.assertions.QueryAssert.assertThat;
import static io.trino.tests.product.TestGroups.CLICKHOUSE;
import static io.trino.tests.product.TestGroups.PROFILE_SPECIFIC_TESTS;
import static io.trino.tests.product.utils.QueryExecutors.onTrino;

public class TestClickHouse
extends ProductTest
{
@Test(groups = {CLICKHOUSE, PROFILE_SPECIFIC_TESTS})
public void testCreateTableAsSelect()
{
QueryResult result = onTrino().executeQuery("CREATE TABLE nation AS SELECT * FROM tpch.tiny.nation");
try {
assertThat(result).updatedRowsCountIsEqualTo(25);
assertThat(onTrino().executeQuery("SELECT COUNT(*) FROM nation"))
.containsOnly(row(25));
}
finally {
onTrino().executeQuery("DROP TABLE nation");
}
}
}