diff --git a/clickhouse-cli-client/src/test/java/com/clickhouse/client/cli/ClickHouseCommandLineClientTest.java b/clickhouse-cli-client/src/test/java/com/clickhouse/client/cli/ClickHouseCommandLineClientTest.java
index 4e278b18d..b608f0429 100644
--- a/clickhouse-cli-client/src/test/java/com/clickhouse/client/cli/ClickHouseCommandLineClientTest.java
+++ b/clickhouse-cli-client/src/test/java/com/clickhouse/client/cli/ClickHouseCommandLineClientTest.java
@@ -2,12 +2,15 @@
import com.clickhouse.client.ClickHouseClient;
import com.clickhouse.client.ClickHouseClientBuilder;
+import com.clickhouse.client.ClickHouseException;
import com.clickhouse.client.ClickHouseNode;
import com.clickhouse.client.ClickHouseProtocol;
import com.clickhouse.client.ClickHouseServerForTest;
import com.clickhouse.client.ClientIntegrationTest;
import com.clickhouse.client.cli.config.ClickHouseCommandLineOption;
+import java.io.IOException;
+
import org.testcontainers.containers.GenericContainer;
import org.testng.Assert;
import org.testng.SkipException;
@@ -49,19 +52,19 @@ protected ClickHouseNode getServer() {
@Test(groups = { "integration" })
@Override
- public void testCustomLoad() throws Exception {
+ public void testCustomLoad() throws ClickHouseException {
throw new SkipException("Skip due to time out error");
}
@Test(groups = { "integration" })
@Override
- public void testLoadRawData() throws Exception {
+ public void testLoadRawData() throws ClickHouseException, IOException {
throw new SkipException("Skip due to response summary is always empty");
}
@Test(groups = { "integration" })
@Override
- public void testMultipleQueries() throws Exception {
+ public void testMultipleQueries() throws ClickHouseException {
// FIXME not sure if the occasional "Stream closed" exception is related to
// zeroturnaround/zt-exec#30 or not
/*
diff --git a/clickhouse-client/pom.xml b/clickhouse-client/pom.xml
index 506ccfb86..f3f4c20fc 100644
--- a/clickhouse-client/pom.xml
+++ b/clickhouse-client/pom.xml
@@ -88,7 +88,7 @@
- META-INF/services
+ META-INF/services/*
diff --git a/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseRequest.java b/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseRequest.java
index 9e06714d2..4a3caf04f 100644
--- a/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseRequest.java
+++ b/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseRequest.java
@@ -65,6 +65,11 @@ public static class Mutation extends ClickHouseRequest {
protected Mutation(ClickHouseRequest> request, boolean sealed) {
super(request.getClient(), request.server, request.serverRef, request.options, sealed);
+ // use headless format if possible
+ if (!sealed) {
+ format(request.getFormat().defaultInputFormat());
+ }
+
this.settings.putAll(request.settings);
this.txRef.set(request.txRef.get());
@@ -117,8 +122,7 @@ protected String getQuery() {
}
return builder.length() > 0 && index == len ? sql
- : new StringBuilder().append(sql).append("\n FORMAT ").append(getInputFormat().name())
- .toString();
+ : new StringBuilder().append(sql).append("\n FORMAT ").append(getFormat().name()).toString();
}
return super.getQuery();
@@ -239,6 +243,11 @@ public Mutation data(ClickHouseDeferredValue input) {
return this;
}
+ @Override
+ public ClickHouseFormat getInputFormat() {
+ return getFormat();
+ }
+
@Override
public CompletableFuture execute() {
if (writer != null) {
@@ -646,7 +655,10 @@ public ClickHouseFormat getFormat() {
* Gets data format used for input(e.g. writing data into server).
*
* @return data format for input
+ * @deprecated will be removed in v0.3.3, please use
+ * {@code getFormat().defaultInputFormat()} instead
*/
+ @Deprecated
public ClickHouseFormat getInputFormat() {
return getFormat().defaultInputFormat();
}
diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseClientTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseClientTest.java
index 9cd1c7c3e..e272c509e 100644
--- a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseClientTest.java
+++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseClientTest.java
@@ -4,12 +4,14 @@
import org.testng.annotations.Test;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.concurrent.ExecutionException;
import com.clickhouse.client.ClickHouseRequest.Mutation;
public class ClickHouseClientTest {
@Test(groups = { "unit" })
- public void testGetAsyncRequestOutputStream() throws Exception {
+ public void testGetAsyncRequestOutputStream() throws IOException {
ClickHouseConfig config = new ClickHouseConfig();
for (int i = 0; i < 256; i++) {
ByteArrayOutputStream bas = new ByteArrayOutputStream();
@@ -21,7 +23,7 @@ public void testGetAsyncRequestOutputStream() throws Exception {
}
@Test(groups = { "unit" })
- public void testGetRequestOutputStream() throws Exception {
+ public void testGetRequestOutputStream() throws IOException {
ClickHouseConfig config = new ClickHouseConfig();
for (int i = 0; i < 256; i++) {
ByteArrayOutputStream bas = new ByteArrayOutputStream();
@@ -33,7 +35,7 @@ public void testGetRequestOutputStream() throws Exception {
}
@Test(groups = { "unit" })
- public void testQuery() throws Exception {
+ public void testQuery() throws ExecutionException, InterruptedException {
ClickHouseClient client = ClickHouseClient.builder().build();
Assert.assertNotNull(client);
ClickHouseRequest> req = client.connect(ClickHouseNode.builder().build());
@@ -48,7 +50,7 @@ public void testQuery() throws Exception {
}
@Test(groups = { "unit" })
- public void testMutation() throws Exception {
+ public void testMutation() throws ExecutionException, InterruptedException {
ClickHouseClient client = ClickHouseClient.builder().build();
Assert.assertNotNull(client);
Mutation req = client.connect(ClickHouseNode.builder().build()).write();
diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseClusterTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseClusterTest.java
index cbd5ccd96..1f155787b 100644
--- a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseClusterTest.java
+++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseClusterTest.java
@@ -35,7 +35,7 @@ private Object[][] getNodeSelectors() {
}
@Test(dataProvider = "nodeSelectorProvider", groups = { "unit" })
- public void testGetNode(ClickHouseNodeSelector nodeSelector) throws Exception {
+ public void testGetNode(ClickHouseNodeSelector nodeSelector) throws InterruptedException {
int size = 5;
int requests = 500;
int len = size * requests;
diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseColumnTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseColumnTest.java
index ecdea0727..e4d812e17 100644
--- a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseColumnTest.java
+++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseColumnTest.java
@@ -141,7 +141,7 @@ public void testReadNestedColumn() {
}
@Test(groups = { "unit" })
- public void testParse() throws Exception {
+ public void testParse() {
ClickHouseColumn column = ClickHouseColumn.of("arr", "Nullable(Array(Nullable(UInt8))");
Assert.assertNotNull(column);
@@ -156,7 +156,7 @@ public void testParse() throws Exception {
}
@Test(groups = { "unit" })
- public void testAggregationFunction() throws Exception {
+ public void testAggregationFunction() {
ClickHouseColumn column = ClickHouseColumn.of("aggFunc", "AggregateFunction(groupBitmap, UInt32)");
Assert.assertTrue(column.isAggregateFunction());
Assert.assertEquals(column.getDataType(), ClickHouseDataType.AggregateFunction);
@@ -178,7 +178,7 @@ public void testAggregationFunction() throws Exception {
}
@Test(groups = { "unit" })
- public void testArray() throws Exception {
+ public void testArray() {
ClickHouseColumn column = ClickHouseColumn.of("arr",
"Array(Array(Array(Array(Array(Map(LowCardinality(String), Tuple(Array(UInt8),LowCardinality(String))))))))");
Assert.assertTrue(column.isArray());
@@ -204,7 +204,7 @@ public void testArray() throws Exception {
}
@Test(dataProvider = "enumTypesProvider", groups = { "unit" })
- public void testEnum(String typeName) throws Exception {
+ public void testEnum(String typeName) {
Assert.assertThrows(IllegalArgumentException.class,
() -> ClickHouseColumn.of("e", typeName + "('Query''Start' = a)"));
Assert.assertThrows(IllegalArgumentException.class, () -> ClickHouseColumn.of("e", typeName + "(aa,1)"));
@@ -236,7 +236,7 @@ public void testObjectType(String typeName) {
}
@Test(groups = { "unit" })
- public void testSimpleAggregationFunction() throws Exception {
+ public void testSimpleAggregationFunction() {
ClickHouseColumn c = ClickHouseColumn.of("a", "SimpleAggregateFunction(max, UInt64)");
Assert.assertEquals(c.getDataType(), ClickHouseDataType.SimpleAggregateFunction);
Assert.assertEquals(c.getNestedColumns().get(0).getDataType(), ClickHouseDataType.UInt64);
diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseConfigTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseConfigTest.java
index 4a5bf6fe3..d6c46a6f2 100644
--- a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseConfigTest.java
+++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseConfigTest.java
@@ -34,7 +34,7 @@ public void testDefaultValues() {
}
@Test(groups = { "unit" })
- public void testCustomValues() throws Exception {
+ public void testCustomValues() {
String clientName = "test client";
String cluster = "test cluster";
String database = "test_database";
diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseDataStreamFactoryTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseDataStreamFactoryTest.java
index f8335f359..600ed1677 100644
--- a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseDataStreamFactoryTest.java
+++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseDataStreamFactoryTest.java
@@ -1,18 +1,20 @@
package com.clickhouse.client;
+import java.io.IOException;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
import org.testng.Assert;
import org.testng.annotations.Test;
public class ClickHouseDataStreamFactoryTest {
@Test(groups = { "unit" })
- public void testGetInstance() throws Exception {
+ public void testGetInstance() {
Assert.assertNotNull(ClickHouseDataStreamFactory.getInstance());
}
@Test(groups = { "unit" })
- public void testCreatePipedOutputStream() throws Exception {
+ public void testCreatePipedOutputStream() throws ExecutionException, IOException, InterruptedException {
ClickHouseConfig config = new ClickHouseConfig();
// read in worker thread
diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseLoadBalancingPolicyTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseLoadBalancingPolicyTest.java
index 1c19b5bf5..4422fc2d4 100644
--- a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseLoadBalancingPolicyTest.java
+++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseLoadBalancingPolicyTest.java
@@ -71,7 +71,7 @@ public void testGetOrCreate() {
}
@Test(dataProvider = "nodeSelectorProvider", groups = { "unit" })
- public void testDummy(ClickHouseNodeSelector nodeSelector) throws Exception {
+ public void testDummy(ClickHouseNodeSelector nodeSelector) throws InterruptedException {
int size = 5;
int requests = 500;
int len = size * requests;
@@ -130,7 +130,7 @@ public void testDummy(ClickHouseNodeSelector nodeSelector) throws Exception {
}
@Test(dataProvider = "nodeSelectorProvider", groups = { "unit" })
- public void testFirstAlive(ClickHouseNodeSelector nodeSelector) throws Exception {
+ public void testFirstAlive(ClickHouseNodeSelector nodeSelector) throws InterruptedException {
int size = 5;
int requests = 500;
int len = size * requests;
@@ -189,7 +189,7 @@ public void testFirstAlive(ClickHouseNodeSelector nodeSelector) throws Exception
}
@Test(dataProvider = "nodeSelectorProvider", groups = { "unit" })
- public void testFirstAliveWithFailures(ClickHouseNodeSelector nodeSelector) throws Exception {
+ public void testFirstAliveWithFailures(ClickHouseNodeSelector nodeSelector) throws InterruptedException {
int size = 5;
int requests = 500;
int len = size * requests;
@@ -238,7 +238,7 @@ public void testFirstAliveWithFailures(ClickHouseNodeSelector nodeSelector) thro
}
@Test(dataProvider = "nodeSelectorProvider", groups = { "unit" })
- public void testRoundRobin(ClickHouseNodeSelector nodeSelector) throws Exception {
+ public void testRoundRobin(ClickHouseNodeSelector nodeSelector) throws InterruptedException {
int size = 5;
int requests = 500;
int len = size * requests;
@@ -297,7 +297,7 @@ public void testRoundRobin(ClickHouseNodeSelector nodeSelector) throws Exception
}
@Test(dataProvider = "nodeSelectorProvider", groups = { "unit" })
- public void testRandom(ClickHouseNodeSelector nodeSelector) throws Exception {
+ public void testRandom(ClickHouseNodeSelector nodeSelector) throws InterruptedException {
int size = 5;
int requests = 500;
int len = size * requests;
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 a0eb4601b..95b22ee8b 100644
--- a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseNodeTest.java
+++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseNodeTest.java
@@ -4,6 +4,7 @@
import org.testng.annotations.Test;
import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -367,7 +368,7 @@ public void testCaseInsensitiveEnumValue() {
}
@Test(groups = { "unit" })
- public void testQueryWithSlash() throws Exception {
+ public void testQueryWithSlash() throws URISyntaxException {
ClickHouseNode server = ClickHouseNode.of("http://localhost?a=/b/c/d");
Assert.assertEquals(server.getDatabase().orElse(null), null);
Assert.assertEquals(server.getOptions(), Collections.singletonMap("a", "/b/c/d"));
diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseNodesTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseNodesTest.java
index 20cb76796..9fe9ac4d6 100644
--- a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseNodesTest.java
+++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseNodesTest.java
@@ -7,8 +7,10 @@
import java.util.Optional;
import java.util.Properties;
import java.util.TreeMap;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
import com.clickhouse.client.ClickHouseNode.Status;
import com.clickhouse.client.config.ClickHouseClientOption;
@@ -185,7 +187,7 @@ public void testGetNodes() {
}
@Test(groups = { "unit" })
- public void testNodeGrouping() throws Exception {
+ public void testNodeGrouping() throws ExecutionException, InterruptedException, TimeoutException {
ClickHouseNodes nodes = ClickHouseNodes
.of("http://(a?node_group_size=1),(tcp://b?x=1)/test?x=2&node_group_size=0");
Assert.assertTrue(nodes.getPolicy() == ClickHouseLoadBalancingPolicy.DEFAULT,
@@ -213,7 +215,7 @@ public void testNodeGrouping() throws Exception {
}
@Test(groups = { "unit" })
- public void testQueryWithSlash() throws Exception {
+ public void testQueryWithSlash() {
ClickHouseNodes servers = ClickHouseNodes
.of("https://node1?a=/b/c/d,node2/db2?/a/b/c=d,node3/db1?a=/d/c.b");
Assert.assertEquals(servers.nodes.get(0).getDatabase().orElse(null), "db1");
diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseValuesTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseValuesTest.java
index bb0bb6215..76a4fa5fc 100644
--- a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseValuesTest.java
+++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseValuesTest.java
@@ -142,7 +142,7 @@ public void testConvertToDateTime() {
}
@Test(groups = { "unit" })
- public void testConvertToIpv4() throws Exception {
+ public void testConvertToIpv4() throws UnknownHostException {
Assert.assertEquals(ClickHouseValues.convertToIpv4((String) null), null);
Assert.assertEquals(ClickHouseValues.convertToIpv4("127.0.0.1"), Inet4Address.getByName("127.0.0.1"));
Assert.assertEquals(ClickHouseValues.convertToIpv4("0:0:0:0:0:ffff:7f00:1"),
@@ -150,7 +150,7 @@ public void testConvertToIpv4() throws Exception {
}
@Test(groups = { "unit" })
- public void testConvertToIpv6() throws Exception {
+ public void testConvertToIpv6() throws UnknownHostException {
Assert.assertEquals(ClickHouseValues.convertToIpv6((String) null), null);
Assert.assertEquals(ClickHouseValues.convertToIpv6("::1"), Inet6Address.getByName("::1"));
Assert.assertEquals(ClickHouseValues.convertToIpv6("127.0.0.1").getClass(), Inet6Address.class);
diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClientIntegrationTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClientIntegrationTest.java
index 9c4e616fb..0e2f42b8b 100644
--- a/clickhouse-client/src/test/java/com/clickhouse/client/ClientIntegrationTest.java
+++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClientIntegrationTest.java
@@ -16,6 +16,7 @@
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -81,6 +82,24 @@ protected void checkRowCount(ClickHouseRequest> request, String queryOrTableNa
}
}
+ protected List sendAndWait(ClickHouseNode server, String sql, String... more)
+ throws ClickHouseException {
+ try {
+ return ClickHouseClient.send(server, sql, more).get();
+ } catch (InterruptedException | ExecutionException e) {
+ throw ClickHouseException.of(e, server);
+ }
+ }
+
+ protected List sendAndWait(ClickHouseNode server, String sql,
+ ClickHouseValue[] templates, Object[]... params) throws ClickHouseException {
+ try {
+ return ClickHouseClient.send(server, sql, templates, params).get();
+ } catch (InterruptedException | ExecutionException e) {
+ throw ClickHouseException.of(e, server);
+ }
+ }
+
protected ClickHouseResponseSummary execute(ClickHouseRequest> request, String sql) throws ClickHouseException {
try (ClickHouseResponse response = request.query(sql).executeAndWait()) {
for (ClickHouseRecord record : response.records()) {
@@ -223,7 +242,7 @@ protected Object[][] getSimpleTypes() {
}
@Test(groups = { "unit" })
- public void testInitialization() throws Exception {
+ public void testInitialization() {
Assert.assertNotNull(getProtocol(), "The client should support a non-null protocol");
Assert.assertNotEquals(getProtocol(), ClickHouseProtocol.ANY,
"The client should support a specific protocol instead of ANY");
@@ -244,13 +263,13 @@ public void testInitialization() throws Exception {
}
@Test(groups = { "integration" })
- public void testOpenCloseClient() throws Exception {
+ public void testOpenCloseClient() throws ClickHouseException {
int count = 10;
int timeout = 3000;
ClickHouseNode server = getServer();
for (int i = 0; i < count; i++) {
try (ClickHouseClient client = getClient();
- ClickHouseResponse response = client.connect(server).query("select 1").execute().get()) {
+ ClickHouseResponse response = client.connect(server).query("select 1").executeAndWait()) {
Assert.assertEquals(response.firstRecord().getValue(0).asInteger(), 1);
}
Assert.assertTrue(getClient().ping(server, timeout));
@@ -258,15 +277,13 @@ public void testOpenCloseClient() throws Exception {
}
@Test(dataProvider = "compressionMatrix", groups = { "integration" })
- public void testCompression(ClickHouseFormat format, ClickHouseBufferingMode bufferingMode,
- boolean compressRequest, boolean compressResponse) throws Exception {
+ public void testCompression(ClickHouseFormat format, ClickHouseBufferingMode bufferingMode, boolean compressRequest,
+ boolean compressResponse) throws ClickHouseException {
ClickHouseNode server = getServer();
String uuid = UUID.randomUUID().toString();
- ClickHouseClient.send(server, "create table if not exists test_compress_decompress(id UUID)engine=Memory")
- .get();
+ sendAndWait(server, "create table if not exists test_compress_decompress(id UUID)engine=Memory");
try (ClickHouseClient client = getClient()) {
- ClickHouseRequest> request = client.connect(server)
- .format(format)
+ ClickHouseRequest> request = client.connect(server).format(format)
.option(ClickHouseClientOption.RESPONSE_BUFFERING, bufferingMode)
.compressServerResponse(compressResponse)
.decompressClientRequest(compressRequest);
@@ -298,9 +315,7 @@ public void testCompression(ClickHouseFormat format, ClickHouseBufferingMode buf
Assert.assertTrue(hasResult, "Should have at least one result");
// empty results
- try (ClickHouseResponse resp = request
- .query("create database if not exists system")
- .executeAndWait()) {
+ try (ClickHouseResponse resp = request.query("create database if not exists system").executeAndWait()) {
ClickHouseResponseSummary summary = resp.getSummary();
Assert.assertEquals(summary.getReadRows(), 0L);
Assert.assertEquals(summary.getWrittenRows(), 0L);
@@ -308,8 +323,7 @@ public void testCompression(ClickHouseFormat format, ClickHouseBufferingMode buf
// let's also check if failures can be captured successfully as well
ClickHouseException exp = null;
- try (ClickHouseResponse resp = request
- .use(uuid)
+ try (ClickHouseResponse resp = request.use(uuid)
.query("select currentUser(), timezone(), version(), getSetting('readonly') readonly FORMAT RowBinaryWithNamesAndTypes")
.executeAndWait()) {
Assert.fail("Query should fail");
@@ -358,7 +372,7 @@ public void testFormat() throws ClickHouseException {
}
@Test(groups = "integration")
- public void testNonExistDb() throws Exception {
+ public void testNonExistDb() throws ClickHouseException {
ClickHouseNode server = getServer();
try {
@@ -367,6 +381,8 @@ public void testNonExistDb() throws Exception {
} catch (ExecutionException e) {
ClickHouseException ce = ClickHouseException.of(e.getCause(), server);
Assert.assertEquals(ce.getErrorCode(), 81);
+ } catch (InterruptedException e) {
+ Assert.fail("Failed execute due to interruption", e);
}
try (ClickHouseClient client = getClient();
@@ -376,6 +392,8 @@ public void testNonExistDb() throws Exception {
} catch (ExecutionException e) {
ClickHouseException ce = ClickHouseException.of(e.getCause(), server);
Assert.assertEquals(ce.getErrorCode(), 81);
+ } catch (InterruptedException e) {
+ Assert.fail("Failed execute due to interruption", e);
}
try (ClickHouseClient client = getClient();
@@ -399,7 +417,7 @@ public void testNonExistDb() throws Exception {
}
@Test(groups = { "integration" })
- public void testQueryWithNoResult() throws Exception {
+ public void testQueryWithNoResult() throws ExecutionException, InterruptedException {
String sql = "select * from system.numbers limit 0";
try (ClickHouseClient client = getClient()) {
@@ -434,7 +452,7 @@ public void testQueryWithNoResult() throws Exception {
}
@Test(groups = { "integration" })
- public void testQuery() throws Exception {
+ public void testQuery() {
ClickHouseNode server = getServer();
try (ClickHouseClient client = getClient()) {
@@ -479,7 +497,7 @@ public void testQuery() throws Exception {
}
@Test(groups = "integration")
- public void testQueryInSameThread() throws Exception {
+ public void testQueryInSameThread() throws ExecutionException, InterruptedException {
ClickHouseNode server = getServer();
try (ClickHouseClient client = ClickHouseClient.builder().nodeSelector(ClickHouseNodeSelector.EMPTY)
@@ -503,7 +521,7 @@ public void testQueryInSameThread() throws Exception {
}
@Test(groups = { "integration" })
- public void testMutation() throws Exception {
+ public void testMutation() throws ClickHouseException {
ClickHouseNode node = getServer();
try (ClickHouseClient client = getClient()) {
@@ -519,7 +537,7 @@ public void testMutation() throws Exception {
}
@Test(groups = "integration")
- public void testQueryIntervalTypes() throws Exception {
+ public void testQueryIntervalTypes() throws ExecutionException, InterruptedException {
ClickHouseNode server = getServer();
try (ClickHouseClient client = getClient()) {
@@ -551,13 +569,12 @@ public void testQueryIntervalTypes() throws Exception {
}
@Test(groups = "integration")
- public void testReadWriteDateTimeTypes() throws Exception {
+ public void testReadWriteDateTimeTypes() throws ClickHouseException {
ClickHouseNode server = getServer();
- ClickHouseClient.send(server, "drop table if exists test_datetime_types",
- "create table test_datetime_types(no UInt8, d0 DateTime32, d1 DateTime64(5), d2 DateTime(3), d3 DateTime64(3, 'Asia/Chongqing')) engine=Memory")
- .get();
- ClickHouseClient.send(server, "insert into test_datetime_types values(:no, :d0, :d1, :d2, :d3)",
+ sendAndWait(server, "drop table if exists test_datetime_types",
+ "create table test_datetime_types(no UInt8, d0 DateTime32, d1 DateTime64(5), d2 DateTime(3), d3 DateTime64(3, 'Asia/Chongqing')) engine=Memory");
+ sendAndWait(server, "insert into test_datetime_types values(:no, :d0, :d1, :d2, :d3)",
new ClickHouseValue[] { ClickHouseIntegerValue.ofNull(),
ClickHouseDateTimeValue.ofNull(0, ClickHouseValues.UTC_TIMEZONE),
ClickHouseDateTimeValue.ofNull(3, ClickHouseValues.UTC_TIMEZONE),
@@ -566,11 +583,11 @@ public void testReadWriteDateTimeTypes() throws Exception {
new Object[] { 0, "1970-01-01 00:00:00", "1970-01-01 00:00:00.123456",
"1970-01-01 00:00:00.123456789", "1970-02-01 12:34:56.789" },
new Object[] { 1, -1, -1, -1, -1 }, new Object[] { 2, 1, 1, 1, 1 },
- new Object[] { 3, 2.1, 2.1, 2.1, 2.1 }).get();
+ new Object[] { 3, 2.1, 2.1, 2.1, 2.1 });
try (ClickHouseClient client = getClient();
ClickHouseResponse resp = client.connect(server).format(ClickHouseFormat.RowBinaryWithNamesAndTypes)
- .query("select * except(no) from test_datetime_types order by no").execute().get()) {
+ .query("select * except(no) from test_datetime_types order by no").executeAndWait()) {
List list = new ArrayList<>();
for (ClickHouseRecord record : resp.records()) {
list.add(record);
@@ -581,43 +598,47 @@ public void testReadWriteDateTimeTypes() throws Exception {
}
@Test(groups = "integration")
- public void testReadWriteDomains() throws Exception {
+ public void testReadWriteDomains() throws ClickHouseException, UnknownHostException {
ClickHouseNode server = getServer();
- ClickHouseClient.send(server, "drop table if exists test_domain_types",
- "create table test_domain_types(no UInt8, ipv4 IPv4, nipv4 Nullable(IPv4), ipv6 IPv6, nipv6 Nullable(IPv6)) engine=Memory")
- .get();
+ sendAndWait(server, "drop table if exists test_domain_types",
+ "create table test_domain_types(no UInt8, ipv4 IPv4, nipv4 Nullable(IPv4), ipv6 IPv6, nipv6 Nullable(IPv6)) engine=Memory");
- ClickHouseClient.send(server, "insert into test_domain_types values(:no, :i0, :i1, :i2, :i3)",
+ sendAndWait(server, "insert into test_domain_types values(:no, :i0, :i1, :i2, :i3)",
new ClickHouseValue[] { ClickHouseIntegerValue.ofNull(), ClickHouseIpv4Value.ofNull(),
ClickHouseIpv4Value.ofNull(), ClickHouseIpv6Value.ofNull(), ClickHouseIpv6Value.ofNull() },
new Object[] { 0,
- (Inet4Address) InetAddress.getByAddress(new byte[] { (byte) 0, (byte) 0, (byte) 0, (byte) 0 }),
+ (Inet4Address) InetAddress
+ .getByAddress(new byte[] { (byte) 0, (byte) 0, (byte) 0, (byte) 0 }),
null,
Inet6Address.getByAddress(null,
new byte[] { (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,
- (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,
+ (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,
+ (byte) 0,
(byte) 0 },
null),
null },
new Object[] { 1,
- (Inet4Address) InetAddress.getByAddress(new byte[] { (byte) 0, (byte) 0, (byte) 0, (byte) 1 }),
+ (Inet4Address) InetAddress
+ .getByAddress(new byte[] { (byte) 0, (byte) 0, (byte) 0, (byte) 1 }),
(Inet4Address) InetAddress
.getByAddress(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }),
Inet6Address.getByAddress(null,
new byte[] { (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,
- (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,
+ (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,
+ (byte) 0,
(byte) 1 },
null),
Inet6Address.getByAddress(null,
new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ (byte) 0xFF,
(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF },
- null) })
- .get();
+ null) });
+
try (ClickHouseClient client = getClient();
ClickHouseResponse resp = client.connect(server).format(ClickHouseFormat.RowBinaryWithNamesAndTypes)
- .query("select * except(no) from test_domain_types order by no").execute().get()) {
+ .query("select * except(no) from test_domain_types order by no").executeAndWait()) {
List list = new ArrayList<>();
for (ClickHouseRecord record : resp.records()) {
list.add(record);
@@ -628,14 +649,13 @@ public void testReadWriteDomains() throws Exception {
}
@Test(groups = "integration")
- public void testReadWriteEnumTypes() throws Exception {
+ public void testReadWriteEnumTypes() throws ClickHouseException {
ClickHouseNode server = getServer();
- ClickHouseClient.send(server, "drop table if exists test_enum_types",
+ sendAndWait(server, "drop table if exists test_enum_types",
"create table test_enum_types(no UInt8, e01 Nullable(Enum8('a'=-1,'b'=2,'c'=0)), e1 Enum8('a'=-1,'b'=2,'c'=0), "
- + "e02 Nullable(Enum16('a'=-1,'b'=2,'c'=0)), e2 Enum16('a'=-1,'b'=2,'c'=0)) engine=Memory")
- .get();
- ClickHouseClient.send(server, "insert into test_enum_types values(:no, :e01, :e1, :e02, :e2)",
+ + "e02 Nullable(Enum16('a'=-1,'b'=2,'c'=0)), e2 Enum16('a'=-1,'b'=2,'c'=0)) engine=Memory");
+ sendAndWait(server, "insert into test_enum_types values(:no, :e01, :e1, :e02, :e2)",
new ClickHouseValue[] { ClickHouseByteValue.ofNull(),
ClickHouseEnumValue
.ofNull(ClickHouseColumn.of("column", "Enum8('dunno'=-1)").getEnumConstants()),
@@ -646,11 +666,11 @@ public void testReadWriteEnumTypes() throws Exception {
ClickHouseEnumValue
.ofNull(ClickHouseColumn.of("column", "Enum16('dunno'=2)").getEnumConstants()), },
new Object[] { 0, null, "b", null, "dunno" },
- new Object[] { 1, "dunno", 2, "a", 2 }).get();
+ new Object[] { 1, "dunno", 2, "a", 2 });
try (ClickHouseClient client = getClient();
ClickHouseResponse resp = client.connect(server).format(ClickHouseFormat.RowBinaryWithNamesAndTypes)
- .query("select * except(no) from test_enum_types order by no").execute().get()) {
+ .query("select * except(no) from test_enum_types order by no").executeAndWait()) {
int count = 0;
for (ClickHouseRecord r : resp.records()) {
if (count++ == 0) {
@@ -687,28 +707,26 @@ public void testReadWriteEnumTypes() throws Exception {
}
@Test(groups = "integration")
- public void testReadWriteGeoTypes() throws Exception {
+ public void testReadWriteGeoTypes() throws ClickHouseException {
ClickHouseNode server = getServer();
- ClickHouseClient.send(server, "set allow_experimental_geo_types=1", "drop table if exists test_geo_types",
- "create table test_geo_types(no UInt8, p Point, r Ring, pg Polygon, mp MultiPolygon) engine=Memory")
- .get();
+ sendAndWait(server, "set allow_experimental_geo_types=1", "drop table if exists test_geo_types",
+ "create table test_geo_types(no UInt8, p Point, r Ring, pg Polygon, mp MultiPolygon) engine=Memory");
// write
- ClickHouseClient.send(server,
+ sendAndWait(server,
"insert into test_geo_types values(0, (0,0), " + "[(0,0),(0,0)], [[(0,0),(0,0)],[(0,0),(0,0)]], "
+ "[[[(0,0),(0,0)],[(0,0),(0,0)]],[[(0,0),(0,0)],[(0,0),(0,0)]]])",
"insert into test_geo_types values(1, (-1,-1), "
+ "[(-1,-1),(-1,-1)], [[(-1,-1),(-1,-1)],[(-1,-1),(-1,-1)]], "
+ "[[[(-1,-1),(-1,-1)],[(-1,-1),(-1,-1)]],[[(-1,-1),(-1,-1)],[(-1,-1),(-1,-1)]]])",
"insert into test_geo_types values(2, (1,1), " + "[(1,1),(1,1)], [[(1,1),(1,1)],[(1,1),(1,1)]], "
- + "[[[(1,1),(1,1)],[(1,1),(1,1)]],[[(1,1),(1,1)],[(1,1),(1,1)]]])")
- .get();
+ + "[[[(1,1),(1,1)],[(1,1),(1,1)]],[[(1,1),(1,1)],[(1,1),(1,1)]]])");
// read
try (ClickHouseClient client = getClient();
ClickHouseResponse resp = client.connect(server).format(ClickHouseFormat.RowBinaryWithNamesAndTypes)
- .query("select * except(no) from test_geo_types order by no").execute().get()) {
+ .query("select * except(no) from test_geo_types order by no").executeAndWait()) {
List records = new ArrayList<>();
for (ClickHouseRecord record : resp.records()) {
String[] values = new String[record.size()];
@@ -740,7 +758,7 @@ public void testReadWriteGeoTypes() throws Exception {
@Test(dataProvider = "simpleTypeProvider", groups = "integration")
public void testReadWriteSimpleTypes(String dataType, String zero, String negativeOne, String positiveOne)
- throws Exception {
+ throws ClickHouseException {
ClickHouseNode server = getServer();
String typeName = dataType;
@@ -780,6 +798,8 @@ public void testReadWriteSimpleTypes(String dataType, String zero, String negati
Throwable cause = e.getCause();
Assert.assertTrue(cause instanceof ClickHouseException);
return;
+ } catch (InterruptedException e) {
+ Assert.fail("Test was interrupted", e);
}
ClickHouseVersion version = null;
@@ -787,7 +807,7 @@ public void testReadWriteSimpleTypes(String dataType, String zero, String negati
ClickHouseResponse resp = client
.connect(server).format(ClickHouseFormat.RowBinaryWithNamesAndTypes).query(ClickHouseUtils
.format("select * except(no), version() from test_%s order by no", columnName))
- .execute().get()) {
+ .executeAndWait()) {
List records = new ArrayList<>();
for (ClickHouseRecord record : resp.records()) {
String[] values = new String[record.size()];
@@ -823,7 +843,7 @@ public void testReadWriteSimpleTypes(String dataType, String zero, String negati
}
@Test(groups = "integration")
- public void testReadWriteMap() throws Exception {
+ public void testReadWriteMap() throws ClickHouseException {
ClickHouseNode server = getServer();
try {
@@ -836,24 +856,29 @@ public void testReadWriteMap() throws Exception {
Throwable cause = e.getCause();
Assert.assertTrue(cause instanceof ClickHouseException);
return;
+ } catch (InterruptedException e) {
+ Assert.fail("Test was interrupted", e);
}
// write
- ClickHouseClient.send(server, "insert into test_map_types values (1, {'key1' : 1}, {'a' : [], 'b' : [null]})")
- .get();
- ClickHouseClient.send(server, "insert into test_map_types values (:n,:m,:x)",
- new String[][] {
- new String[] { "-1", "{'key-1' : -1}",
- "{'a' : [], 'b' : [ '2022-03-30 00:00:00.123', null ]}" },
- new String[] { "-2", "{'key-2' : -2}", "{'key-2' : [null]}" } })
- .get();
- ClickHouseClient.send(server, "insert into test_map_types values (3, :m, {})",
- Collections.singletonMap("m", "{'key3' : 3}")).get();
+ sendAndWait(server, "insert into test_map_types values (1, {'key1' : 1}, {'a' : [], 'b' : [null]})");
+ try {
+ ClickHouseClient.send(server, "insert into test_map_types values (:n,:m,:x)",
+ new String[][] {
+ new String[] { "-1", "{'key-1' : -1}",
+ "{'a' : [], 'b' : [ '2022-03-30 00:00:00.123', null ]}" },
+ new String[] { "-2", "{'key-2' : -2}", "{'key-2' : [null]}" } })
+ .get();
+ ClickHouseClient.send(server, "insert into test_map_types values (3, :m, {})",
+ Collections.singletonMap("m", "{'key3' : 3}")).get();
+ } catch (Exception e) {
+ Assert.fail("Insertion failed", e);
+ }
// read
try (ClickHouseClient client = getClient();
ClickHouseResponse resp = client.connect(server).format(ClickHouseFormat.RowBinaryWithNamesAndTypes)
- .query("select * except(no) from test_map_types order by no").execute().get()) {
+ .query("select * except(no) from test_map_types order by no").executeAndWait()) {
List