Skip to content

Commit 6e8ea2d

Browse files
authored
Merge pull request #2772 from ClickHouse/03/02/26/clickhouse_java_tests
[repo] Adopt CLI tests from ClickHouse client
2 parents 97fec31 + 98694ef commit 6e8ea2d

4 files changed

Lines changed: 896 additions & 0 deletions

File tree

tests/clickhouse-client/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# clickhouse-client-cli
2+
3+
A simple CLI tool that mimics `clickhouse-client` for executing SQL queries against a ClickHouse server.
4+
Used to test with ClickHouse test framework designed for `clickhouse-client` (https://github.com/ClickHouse/ClickHouse/blob/master/tests/clickhouse-test).
5+
Note: do not clone ClickHouse repo - it takes a lot of time. Download zip instead.
6+
7+
## Build Java Application
8+
9+
```bash
10+
cd tests/clickhouse-client
11+
mvn package -DskipTests
12+
```
13+
14+
This produces an executable fat JAR at `target/clickhouse-client-cli-1.0.0.jar`.
15+
16+
## Wrapper executable
17+
18+
A wrapper script named `clickhouse-client` is provided in `bin/` directory. It is a simple shell script that calls
19+
java application. It is required because `clickhouse-test` script calls `clickhouse-client` binary found in `PATH` environment variable.
20+
It is recommended to set `PATH` locally in terminal session to not override real `clickhouse-client`.
21+
22+
## Environment variables
23+
24+
| Variable | Description |
25+
|---|---|
26+
| `CLICKHOUSE_CLIENT_CLI_IMPL` | Backend implementation to use: `client` (default, uses client-v2 API) or `jdbc` (uses ClickHouse JDBC driver) |
27+
| `CLICKHOUSE_CLIENT_CLI_LOG` | Path to log file for troubleshooting |
28+
29+
## Examples
30+
31+
Run tests using the default client-v2 backend:
32+
33+
```shell
34+
cd ClickHouse-master
35+
CLICKHOUSE_CLIENT_CLI_LOG=./test-run.log PATH="$PATH:/home/someuser/clickhouse-java/tests/clickhouse-client/bin/" tests/clickhouse-test 01428_hash_set_nan_key
36+
```
37+
38+
Run tests using the JDBC backend:
39+
40+
```shell
41+
cd ClickHouse-master
42+
CLICKHOUSE_CLIENT_CLI_IMPL=jdbc CLICKHOUSE_CLIENT_CLI_LOG=./test-run.log PATH="$PATH:/home/someuser/clickhouse-java/tests/clickhouse-client/bin/" tests/clickhouse-test 01428_hash_set_nan_key
43+
```
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
JAR_PATH="${SCRIPT_DIR}/../target/clickhouse-client-cli-1.0.0.jar"
6+
7+
if [[ "${1:-}" == "extract-from-config" ]]; then
8+
shift
9+
key=""
10+
while [[ $# -gt 0 ]]; do
11+
case "$1" in
12+
--key)
13+
key="${2:-}"
14+
shift 2
15+
;;
16+
--key=*)
17+
key="${1#--key=}"
18+
shift
19+
;;
20+
*)
21+
shift
22+
;;
23+
esac
24+
done
25+
26+
# Minimal compatibility for clickhouse-test usage.
27+
if [[ "${key}" == "listen_host" ]]; then
28+
echo "127.0.0.1"
29+
fi
30+
exit 0
31+
fi
32+
33+
if [[ ! -f "${JAR_PATH}" ]]; then
34+
echo "Jar not found: ${JAR_PATH}" >&2
35+
echo "Build it first: (cd ${SCRIPT_DIR} && mvn package -DskipTests)" >&2
36+
exit 1
37+
fi
38+
39+
exec java -jar "${JAR_PATH}" "$@"

tests/clickhouse-client/pom.xml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.clickhouse</groupId>
8+
<artifactId>clickhouse-client-cli</artifactId>
9+
<version>1.0.0</version>
10+
<packaging>jar</packaging>
11+
12+
<name>clickhouse-client-cli</name>
13+
<description>Simple CLI tool that mimics clickhouse-client for executing SQL queries</description>
14+
15+
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<maven.compiler.source>17</maven.compiler.source>
18+
<maven.compiler.target>17</maven.compiler.target>
19+
<clickhouse-java.version>0.9.6-SNAPSHOT</clickhouse-java.version>
20+
<main.class>com.clickhouse.client.cli.Main</main.class>
21+
</properties>
22+
23+
<dependencies>
24+
<dependency>
25+
<groupId>com.clickhouse</groupId>
26+
<artifactId>clickhouse-jdbc</artifactId>
27+
<version>${clickhouse-java.version}</version>
28+
<classifier>all</classifier>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>org.slf4j</groupId>
33+
<artifactId>slf4j-api</artifactId>
34+
<version>2.0.13</version>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>org.apache.commons</groupId>
39+
<artifactId>commons-csv</artifactId>
40+
<version>1.14.1</version>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>commons-cli</groupId>
45+
<artifactId>commons-cli</artifactId>
46+
<version>1.11.0</version>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>org.slf4j</groupId>
51+
<artifactId>slf4j-simple</artifactId>
52+
<version>2.0.13</version>
53+
<scope>runtime</scope>
54+
</dependency>
55+
</dependencies>
56+
57+
<build>
58+
<plugins>
59+
<plugin>
60+
<groupId>org.apache.maven.plugins</groupId>
61+
<artifactId>maven-jar-plugin</artifactId>
62+
<version>3.3.0</version>
63+
<configuration>
64+
<archive>
65+
<manifest>
66+
<mainClass>${main.class}</mainClass>
67+
</manifest>
68+
</archive>
69+
</configuration>
70+
</plugin>
71+
72+
<plugin>
73+
<groupId>org.apache.maven.plugins</groupId>
74+
<artifactId>maven-shade-plugin</artifactId>
75+
<version>3.5.1</version>
76+
<executions>
77+
<execution>
78+
<phase>package</phase>
79+
<goals>
80+
<goal>shade</goal>
81+
</goals>
82+
<configuration>
83+
<transformers>
84+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
85+
<mainClass>${main.class}</mainClass>
86+
</transformer>
87+
</transformers>
88+
<filters>
89+
<filter>
90+
<artifact>*:*</artifact>
91+
<excludes>
92+
<exclude>META-INF/*.SF</exclude>
93+
<exclude>META-INF/*.DSA</exclude>
94+
<exclude>META-INF/*.RSA</exclude>
95+
</excludes>
96+
</filter>
97+
</filters>
98+
</configuration>
99+
</execution>
100+
</executions>
101+
</plugin>
102+
</plugins>
103+
</build>
104+
</project>

0 commit comments

Comments
 (0)