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 records = new ArrayList<>(); for (ClickHouseRecord r : resp.records()) { Object[] values = new Object[r.size()]; @@ -869,14 +894,13 @@ public void testReadWriteMap() throws Exception { } @Test(groups = "integration") - public void testReadWriteUInt64() throws Exception { + public void testReadWriteUInt64() throws ClickHouseException { ClickHouseNode server = getServer(); // INSERT INTO test_table VALUES (10223372036854775100) - ClickHouseClient.send(server, "drop table if exists test_uint64_values", - "create table test_uint64_values(no UInt8, v0 UInt64, v1 UInt64, v2 UInt64, v3 UInt64) engine=Memory") - .get(); - ClickHouseClient.send(server, "insert into test_uint64_values values(:no, :v0, :v1, :v2, :v3)", + sendAndWait(server, "drop table if exists test_uint64_values", + "create table test_uint64_values(no UInt8, v0 UInt64, v1 UInt64, v2 UInt64, v3 UInt64) engine=Memory"); + sendAndWait(server, "insert into test_uint64_values values(:no, :v0, :v1, :v2, :v3)", new ClickHouseValue[] { ClickHouseIntegerValue.ofNull(), ClickHouseLongValue.ofNull(true), ClickHouseStringValue.ofNull(), ClickHouseBigIntegerValue.ofNull(), ClickHouseBigDecimalValue.ofNull() }, @@ -885,12 +909,11 @@ public void testReadWriteUInt64() throws Exception { new Object[] { 2, Long.MAX_VALUE, Long.toString(Long.MAX_VALUE), BigInteger.valueOf(Long.MAX_VALUE), BigDecimal.valueOf(Long.MAX_VALUE) }, new Object[] { 3, -8223372036854776516L, "10223372036854775100", new BigInteger("10223372036854775100"), - new BigDecimal("10223372036854775100") }) - .get(); + new BigDecimal("10223372036854775100") }); try (ClickHouseClient client = getClient(); ClickHouseResponse resp = client.connect(server).format(ClickHouseFormat.RowBinaryWithNamesAndTypes) - .query("select * except(no) from test_uint64_values order by no").execute().get()) { + .query("select * except(no) from test_uint64_values order by no").executeAndWait()) { int count = 0; for (ClickHouseRecord r : resp.records()) { if (count == 0) { @@ -922,7 +945,7 @@ public void testReadWriteUInt64() throws Exception { } @Test(groups = "integration") - public void testQueryWithMultipleExternalTables() throws Exception { + public void testQueryWithMultipleExternalTables() throws ExecutionException, InterruptedException { ClickHouseNode server = getServer(); int tables = 30; @@ -973,7 +996,7 @@ public void testQueryWithMultipleExternalTables() throws Exception { } @Test(groups = { "integration" }) - public void testCustomRead() throws Exception { + public void testCustomRead() throws ClickHouseException, IOException { long limit = 1000L; long count = 0L; ClickHouseNode server = getServer(); @@ -1001,11 +1024,10 @@ public void testCustomRead() throws Exception { } @Test(groups = { "integration" }) - public void testCustomWriter() throws Exception { + public void testCustomWriter() throws ClickHouseException { ClickHouseNode server = getServer(); - ClickHouseClient.send(server, "drop table if exists test_custom_writer", - "create table test_custom_writer(a Int8) engine=Memory") - .get(); + sendAndWait(server, "drop table if exists test_custom_writer", + "create table test_custom_writer(a Int8) engine=Memory"); try (ClickHouseClient client = getClient()) { AtomicInteger i = new AtomicInteger(1); @@ -1018,6 +1040,8 @@ public void testCustomWriter() throws Exception { try (ClickHouseResponse resp = req.send().get()) { Assert.assertNotNull(resp); + } catch (Exception e) { + Assert.fail("Failed to call send() followed by get()", e); } try (ClickHouseResponse resp = req.sendAndWait()) { @@ -1026,6 +1050,8 @@ public void testCustomWriter() throws Exception { try (ClickHouseResponse resp = req.execute().get()) { Assert.assertNotNull(resp); + } catch (Exception e) { + Assert.fail("Failed to call execute() followed by get()", e); } try (ClickHouseResponse resp = req.executeAndWait()) { @@ -1041,24 +1067,31 @@ public void testCustomWriter() throws Exception { } @Test(groups = { "integration" }) - public void testDumpAndLoadFile() throws Exception { + public void testDumpAndLoadFile() throws ClickHouseException, IOException { ClickHouseNode server = getServer(); - ClickHouseClient.send(server, "drop table if exists test_dump_load_file", - "create table test_dump_load_file(a UInt64, b Nullable(String)) engine=MergeTree() order by tuple()") - .get(); + sendAndWait(server, "drop table if exists test_dump_load_file", + "create table test_dump_load_file(a UInt64, b Nullable(String)) engine=MergeTree() order by tuple()"); final int rows = 10000; final Path tmp = Paths.get(System.getProperty("java.io.tmpdir"), "file.json"); ClickHouseFile file = ClickHouseFile.of(tmp); - ClickHouseClient.dump(server, - ClickHouseUtils.format( - "select number a, if(modulo(number, 2) = 0, null, toString(number)) b from numbers(%d)", - rows), - file).get(); + try { + ClickHouseClient.dump(server, + ClickHouseUtils.format( + "select number a, if(modulo(number, 2) = 0, null, toString(number)) b from numbers(%d)", + rows), + file).get(); + } catch (Exception e) { + Assert.fail("Failed to dump data", e); + } Assert.assertTrue(Files.exists(tmp), ClickHouseUtils.format("File [%s] should exist", tmp)); Assert.assertTrue(Files.size(tmp) > 0, ClickHouseUtils.format("File [%s] should have content", tmp)); - ClickHouseClient.load(server, "test_dump_load_file", file).get(); + try { + ClickHouseClient.load(server, "test_dump_load_file", file).get(); + } catch (Exception e) { + Assert.fail("Failed to load file", e); + } try (ClickHouseClient client = getClient(); ClickHouseResponse response = client.connect(server).query("select count(1) from test_dump_load_file") @@ -1068,14 +1101,13 @@ public void testDumpAndLoadFile() throws Exception { try (ClickHouseClient client = getClient(); ClickHouseResponse response = client.connect(server) - .query("select count(1) from test_dump_load_file where b is null") - .executeAndWait()) { + .query("select count(1) from test_dump_load_file where b is null").executeAndWait()) { Assert.assertEquals(response.firstRecord().getValue(0).asInteger(), rows / 2); } } @Test(groups = { "integration" }) - public void testDump() throws Exception { + public void testDump() throws ExecutionException, InterruptedException, IOException { ClickHouseNode server = getServer(); Path temp = Files.createTempFile("dump", ".tsv"); @@ -1098,7 +1130,8 @@ public void testDump() throws Exception { } @Test(dataProvider = "fileProcessMatrix", groups = "integration") - public void testDumpFile(boolean gzipCompressed, boolean useOneLiner) throws Exception { + public void testDumpFile(boolean gzipCompressed, boolean useOneLiner) + throws ExecutionException, InterruptedException, IOException { ClickHouseNode server = getServer(); if (server.getProtocol() != ClickHouseProtocol.HTTP) { throw new SkipException("Skip as only http implementation works well"); @@ -1113,8 +1146,8 @@ public void testDumpFile(boolean gzipCompressed, boolean useOneLiner) throws Exc ClickHouseClient.dump(server, query, wrappedFile).get(); } else { try (ClickHouseClient client = getClient(); - ClickHouseResponse response = client.connect(server).query(query).output(wrappedFile) - .executeAndWait()) { + ClickHouseResponse response = client.connect(server).query(query).output(wrappedFile).execute() + .get()) { // ignore } } @@ -1139,24 +1172,28 @@ public void testDumpFile(boolean gzipCompressed, boolean useOneLiner) throws Exc } @Test(groups = { "integration" }) - public void testCustomLoad() throws Exception { + public void testCustomLoad() throws ClickHouseException { ClickHouseNode server = getServer(); - ClickHouseClient.send(server, "drop table if exists test_custom_load", - "create table test_custom_load(n UInt32, s Nullable(String)) engine = Memory").get(); + sendAndWait(server, "drop table if exists test_custom_load", + "create table test_custom_load(n UInt32, s Nullable(String)) engine = Memory"); - ClickHouseClient.load(server, "test_custom_load", ClickHouseFormat.TabSeparated, - ClickHouseCompression.NONE, new ClickHouseWriter() { - @Override - public void write(ClickHouseOutputStream output) throws IOException { - output.write("1\t\\N\n".getBytes(StandardCharsets.US_ASCII)); - output.write("2\t123".getBytes(StandardCharsets.US_ASCII)); - } - }).get(); + try { + ClickHouseClient.load(server, "test_custom_load", ClickHouseFormat.TabSeparated, + ClickHouseCompression.NONE, new ClickHouseWriter() { + @Override + public void write(ClickHouseOutputStream output) throws IOException { + output.write("1\t\\N\n".getBytes(StandardCharsets.US_ASCII)); + output.write("2\t123".getBytes(StandardCharsets.US_ASCII)); + } + }).get(); + } catch (Exception e) { + Assert.fail("Faile to load data", e); + } try (ClickHouseClient client = getClient(); ClickHouseResponse resp = client.connect(server).query("select * from test_custom_load order by n") - .format(ClickHouseFormat.RowBinaryWithNamesAndTypes).execute().get()) { + .format(ClickHouseFormat.RowBinaryWithNamesAndTypes).executeAndWait()) { Assert.assertNotNull(resp.getColumns()); List values = new ArrayList<>(); for (ClickHouseRecord record : resp.records()) { @@ -1173,7 +1210,7 @@ public void write(ClickHouseOutputStream output) throws IOException { } @Test(groups = { "integration" }) - public void testLoadCsv() throws Exception { + public void testLoadCsv() throws ExecutionException, InterruptedException, IOException { ClickHouseNode server = getServer(); List summaries = ClickHouseClient @@ -1221,7 +1258,7 @@ public void testLoadCsv() throws Exception { } @Test(dataProvider = "fileProcessMatrix", groups = "integration") - public void testLoadFile(boolean gzipCompressed, boolean useOneLiner) throws Exception { + public void testLoadFile(boolean gzipCompressed, boolean useOneLiner) throws ClickHouseException, IOException { ClickHouseNode server = getServer(); if (server.getProtocol() != ClickHouseProtocol.HTTP) { throw new SkipException("Skip as only http implementation works well"); @@ -1246,15 +1283,17 @@ public void testLoadFile(boolean gzipCompressed, boolean useOneLiner) throws Exc out.flush(); } - ClickHouseClient.send(server, "drop table if exists test_load_file", - "create table test_load_file(a Int32, b Nullable(String))engine=Memory").get(); + sendAndWait(server, "drop table if exists test_load_file", + "create table test_load_file(a Int32, b Nullable(String))engine=Memory"); ClickHouseFile wrappedFile = ClickHouseFile.of(file, gzipCompressed ? ClickHouseCompression.GZIP : ClickHouseCompression.NONE, 0, ClickHouseFormat.CSV); if (useOneLiner) { - ClickHouseClient - .load(server, "test_load_file", wrappedFile) - .get(); + try { + ClickHouseClient.load(server, "test_load_file", wrappedFile).get(); + } catch (Exception e) { + Assert.fail("Failed to load file", e); + } } else { try (ClickHouseClient client = getClient(); ClickHouseResponse response = client.connect(server).write().table("test_load_file") @@ -1281,10 +1320,10 @@ public void testLoadFile(boolean gzipCompressed, boolean useOneLiner) throws Exc } @Test(groups = { "integration" }) - public void testLoadRawData() throws Exception { + public void testLoadRawData() throws ClickHouseException, IOException { ClickHouseNode server = getServer(); - ClickHouseClient.send(server, "drop table if exists test_load_raw_data", - "create table test_load_raw_data(a Int64)engine=Memory").get(); + sendAndWait(server, "drop table if exists test_load_raw_data", + "create table test_load_raw_data(a Int64)engine=Memory"); int rows = 10; try (ClickHouseClient client = getClient()) { @@ -1295,22 +1334,26 @@ public void testLoadRawData() throws Exception { .set("send_progress_in_http_headers", 1); ClickHouseConfig config = request.getConfig(); - CompletableFuture future; + CompletableFuture future = null; // single producer → single consumer // important to close the stream *before* retrieving response try (ClickHousePipedOutputStream stream = ClickHouseDataStreamFactory.getInstance() .createPipedOutputStream(config, null)) { // start the worker thread which transfer data from the input into ClickHouse - future = request.data(stream.getInputStream()).send(); + future = request.data(stream.getInputStream()).execute(); // write bytes into the piped stream for (int i = 0; i < rows; i++) { BinaryStreamUtils.writeInt64(stream, i); } + } catch (Exception e) { + Assert.fail("Failed to execute", e); } - ClickHouseResponseSummary summary; + ClickHouseResponseSummary summary = null; try (ClickHouseResponse response = future.get()) { summary = response.getSummary(); + } catch (Exception e) { + Assert.fail("Failed to get result", e); } Assert.assertEquals(summary.getWrittenRows(), rows); @@ -1318,16 +1361,16 @@ public void testLoadRawData() throws Exception { } @Test(groups = { "integration" }) - public void testMultipleQueries() throws Exception { + public void testMultipleQueries() throws ClickHouseException { ClickHouseNode server = getServer(); try (ClickHouseClient client = getClient()) { ClickHouseRequest req = client.connect(server).format(ClickHouseFormat.RowBinaryWithNamesAndTypes); int result1 = 1; int result2 = 2; - ClickHouseResponse queryResp = req.copy().query("select 1").execute().get(); + ClickHouseResponse queryResp = req.copy().query("select 1").executeAndWait(); - try (ClickHouseResponse resp = req.copy().query("select 2").execute().get()) { + try (ClickHouseResponse resp = req.copy().query("select 2").executeAndWait()) { Assert.assertEquals(resp.firstRecord().getValue(0).asInteger(), result2); } @@ -1341,7 +1384,7 @@ public void testMultipleQueries() throws Exception { } @Test(groups = { "integration" }) - public void testExternalTableAsParameter() throws Exception { + public void testExternalTableAsParameter() throws ClickHouseException { ClickHouseNode server = getServer(); try (ClickHouseClient client = getClient(); ClickHouseResponse resp = client.connect(server).format(ClickHouseFormat.RowBinaryWithNamesAndTypes) @@ -1352,7 +1395,7 @@ public void testExternalTableAsParameter() throws Exception { .content(new ByteArrayInputStream( "\"1,2,3\",\\N\n2,333".getBytes(StandardCharsets.US_ASCII))) .build()) - .execute().get()) { + .executeAndWait()) { for (ClickHouseRecord r : resp.records()) { Assert.assertNotNull(r); } @@ -1360,10 +1403,39 @@ public void testExternalTableAsParameter() throws Exception { } @Test(groups = { "integration" }) - public void testInsertWithInputFunction() throws Exception { + public void testInsertWithCustomFormat() throws ClickHouseException { + ClickHouseNode server = getServer(); + sendAndWait(server, "drop table if exists test_custom_input_format", + "create table test_custom_input_format(i Int8, f String)engine=Memory"); + try (ClickHouseClient client = getClient()) { + ClickHouseRequest request = client.connect(server).format(ClickHouseFormat.RowBinaryWithNamesAndTypes); + try (ClickHouseResponse response = request.write().table("test_custom_input_format") + .data(o -> o.writeByte((byte) 1).writeUnicodeString("RowBinary")).executeAndWait()) { + // ignore + } + try (ClickHouseResponse response = request.write().format(ClickHouseFormat.CSVWithNames) + .table("test_custom_input_format") + .data(o -> o.writeBytes("i,f\n2,CSVWithNames".getBytes())).executeAndWait()) { + // ignore + } + try (ClickHouseResponse response = request.query("select * from test_custom_input_format order by i") + .executeAndWait()) { + int count = 0; + for (ClickHouseRecord r : response.records()) { + Assert.assertEquals(r.getValue(0).asInteger(), count + 1); + Assert.assertEquals(r.getValue(1).asString(), count == 0 ? "RowBinary" : "CSVWithNames"); + count++; + } + Assert.assertEquals(count, 2); + } + } + } + + @Test(groups = { "integration" }) + public void testInsertWithInputFunction() throws ClickHouseException { ClickHouseNode server = getServer(); - ClickHouseClient.send(server, "drop table if exists test_input_function", - "create table test_input_function(name String, value Nullable(Int32))engine=Memory").get(); + sendAndWait(server, "drop table if exists test_input_function", + "create table test_input_function(name String, value Nullable(Int32))engine=Memory"); try (ClickHouseClient client = getClient()) { // default format ClickHouseFormat.TabSeparated @@ -1371,13 +1443,13 @@ public void testInsertWithInputFunction() throws Exception { try (ClickHouseResponse resp = req.write().query( "insert into test_input_function select col2, col3 from " + "input('col1 UInt8, col2 String, col3 Int32')") - .data(new ByteArrayInputStream("1\t2\t33\n2\t3\t333".getBytes(StandardCharsets.US_ASCII))).execute() - .get()) { + .data(new ByteArrayInputStream("1\t2\t33\n2\t3\t333".getBytes(StandardCharsets.US_ASCII))) + .executeAndWait()) { } List values = new ArrayList<>(); - try (ClickHouseResponse resp = req.query("select * from test_input_function").execute().get()) { + try (ClickHouseResponse resp = req.query("select * from test_input_function").executeAndWait()) { for (ClickHouseRecord r : resp.records()) { values.add(new Object[] { r.getValue(0).asObject() }); } @@ -1389,13 +1461,13 @@ public void testInsertWithInputFunction() throws Exception { @Test(dataProvider = "renameMethods", groups = "integration") public void testRenameResponseColumns(ClickHouseRenameMethod m, String col1, String col2, String col3) - throws Exception { + throws ClickHouseException { ClickHouseNode server = getServer(); try (ClickHouseClient client = getClient(); ClickHouseResponse resp = client.connect(server) .format(ClickHouseFormat.RowBinaryWithNamesAndTypes) .option(ClickHouseClientOption.RENAME_RESPONSE_COLUMN, m) - .query("select 1 `a b c`, 2 ` `, 3 `d.E_f`").execute().get()) { + .query("select 1 `a b c`, 2 ` `, 3 `d.E_f`").executeAndWait()) { Assert.assertEquals(resp.getColumns().get(0).getColumnName(), col1); Assert.assertEquals(resp.getColumns().get(1).getColumnName(), col2); Assert.assertEquals(resp.getColumns().get(2).getColumnName(), col3); @@ -1403,15 +1475,15 @@ public void testRenameResponseColumns(ClickHouseRenameMethod m, String col1, Str } @Test(groups = "integration") - public void testTempTable() throws Exception { + public void testTempTable() throws ClickHouseException { ClickHouseNode server = getServer(); String sessionId = UUID.randomUUID().toString(); try (ClickHouseClient client = getClient()) { ClickHouseRequest request = client.connect(server).format(ClickHouseFormat.RowBinary) .session(sessionId); - request.query("drop temporary table if exists my_temp_table").execute().get(); - request.query("create temporary table my_temp_table(a Int8)").execute().get(); - request.query("insert into my_temp_table values(2)").execute().get(); + request.query("drop temporary table if exists my_temp_table").executeAndWait(); + request.query("create temporary table my_temp_table(a Int8)").executeAndWait(); + request.query("insert into my_temp_table values(2)").executeAndWait(); try (ClickHouseResponse resp = request.write().table("my_temp_table") .data(new ByteArrayInputStream(new byte[] { 3 })).executeAndWait()) { // ignore @@ -1419,7 +1491,7 @@ public void testTempTable() throws Exception { int count = 0; try (ClickHouseResponse resp = request.format(ClickHouseFormat.RowBinaryWithNamesAndTypes) - .query("select * from my_temp_table order by a").execute().get()) { + .query("select * from my_temp_table order by a").executeAndWait()) { for (ClickHouseRecord r : resp.records()) { Assert.assertEquals(r.getValue(0).asInteger(), count++ == 0 ? 2 : 3); } @@ -1429,10 +1501,10 @@ public void testTempTable() throws Exception { } @Test(groups = "integration") - public void testErrorDuringInsert() throws Exception { + public void testErrorDuringInsert() throws ClickHouseException { ClickHouseNode server = getServer(); - ClickHouseClient.send(server, "drop table if exists error_during_insert", - "create table error_during_insert(n UInt64, flag UInt8)engine=Null").get(); + sendAndWait(server, "drop table if exists error_during_insert", + "create table error_during_insert(n UInt64, flag UInt8)engine=Null"); boolean success = true; try (ClickHouseClient client = getClient(); ClickHouseResponse resp = client.connect(server).write().format(ClickHouseFormat.RowBinary) @@ -1457,7 +1529,7 @@ public void testErrorDuringInsert() throws Exception { } @Test(groups = "integration") - public void testErrorDuringQuery() throws Exception { + public void testErrorDuringQuery() throws ClickHouseException { ClickHouseNode server = getServer(); String query = "select number, throwIf(number>=100000000) from numbers(500000000)"; long count = 0L; @@ -1480,7 +1552,7 @@ public void testErrorDuringQuery() throws Exception { } @Test(groups = "integration") - public void testSession() throws Exception { + public void testSession() throws ClickHouseException { ClickHouseNode server = getServer(); String sessionId = ClickHouseRequestManager.getInstance().createSessionId(); try (ClickHouseClient client = getClient()) { @@ -1505,7 +1577,7 @@ public void testSession() throws Exception { } @Test(groups = "integration") - public void testSessionLock() throws Exception { + public void testSessionLock() throws ClickHouseException { ClickHouseNode server = getServer(); String sessionId = ClickHouseRequestManager.getInstance().createSessionId(); try (ClickHouseClient client = getClient()) { @@ -1539,11 +1611,11 @@ public void testSessionLock() throws Exception { } @Test // (groups = "integration") - public void testAbortTransaction() throws Exception { + public void testAbortTransaction() throws ClickHouseException { ClickHouseNode server = getServer(); String tableName = "test_abort_transaction"; - ClickHouseClient.send(server, "drop table if exists " + tableName, - "create table " + tableName + " (id Int64)engine=MergeTree order by id").get(); + sendAndWait(server, "drop table if exists " + tableName, + "create table " + tableName + " (id Int64)engine=MergeTree order by id"); try (ClickHouseClient client = getClient()) { ClickHouseRequest txRequest = client.connect(server).transaction(); try (ClickHouseResponse response = txRequest.query("insert into " + tableName + " values(1)(2)(3)") @@ -1631,10 +1703,10 @@ public void testJoinTransaction() throws ClickHouseException { } @Test // (groups = "integration") - public void testCommitTransaction() throws Exception { + public void testCommitTransaction() throws ClickHouseException { ClickHouseNode server = getServer(); - ClickHouseClient.send(server, "drop table if exists test_tx_commit", - "create table test_tx_commit(a Int64, b String)engine=MergeTree order by a").get(); + sendAndWait(server, "drop table if exists test_tx_commit", + "create table test_tx_commit(a Int64, b String)engine=MergeTree order by a"); try (ClickHouseClient client = getClient()) { ClickHouseRequest request = client.connect(server).transaction(); ClickHouseTransaction tx = request.getTransaction(); @@ -1657,11 +1729,11 @@ public void testCommitTransaction() throws Exception { } @Test // (groups = "integration") - public void testRollbackTransaction() throws Exception { + public void testRollbackTransaction() throws ClickHouseException { String tableName = "test_tx_rollback"; ClickHouseNode server = getServer(); - ClickHouseClient.send(server, "drop table if exists " + tableName, - "create table " + tableName + "(a Int64, b String)engine=MergeTree order by a").get(); + sendAndWait(server, "drop table if exists " + tableName, + "create table " + tableName + "(a Int64, b String)engine=MergeTree order by a"); checkRowCount(tableName, 0); try (ClickHouseClient client = getClient()) { @@ -1718,11 +1790,11 @@ public void testRollbackTransaction() throws Exception { } @Test // (groups = "integration") - public void testTransactionSnapshot() throws Exception { + public void testTransactionSnapshot() throws ClickHouseException { String tableName = "test_tx_snapshots"; ClickHouseNode server = getServer(); - ClickHouseClient.send(server, "drop table if exists " + tableName, - "create table " + tableName + "(a Int64)engine=MergeTree order by a").get(); + sendAndWait(server, "drop table if exists " + tableName, + "create table " + tableName + "(a Int64)engine=MergeTree order by a"); try (ClickHouseClient client = getClient()) { ClickHouseRequest req1 = client.connect(server).transaction(); ClickHouseRequest req2 = client.connect(server).transaction(); @@ -1796,11 +1868,11 @@ public void testTransactionSnapshot() throws Exception { } @Test // (groups = "integration") - public void testTransactionTimeout() throws Exception { + public void testTransactionTimeout() throws ClickHouseException { String tableName = "test_tx_timeout"; ClickHouseNode server = getServer(); - ClickHouseClient.send(server, "drop table if exists " + tableName, - "create table " + tableName + "(a UInt64)engine=MergeTree order by a").get(); + sendAndWait(server, "drop table if exists " + tableName, + "create table " + tableName + "(a UInt64)engine=MergeTree order by a"); try (ClickHouseClient client = getClient()) { ClickHouseRequest request = client.connect(server).transaction(1); ClickHouseTransaction tx = request.getTransaction(); @@ -1814,7 +1886,11 @@ public void testTransactionTimeout() throws Exception { Assert.assertEquals(tx.getState(), ClickHouseTransaction.ROLLED_BACK); tx.begin(); - Thread.sleep(3000L); + try { + Thread.sleep(3000L); + } catch (InterruptedException ex) { + Assert.fail("Sleep was interrupted", ex); + } try (ClickHouseResponse response = client.connect(server).transaction(tx).query("select 1") .executeAndWait()) { Assert.fail("Query should fail due to session timed out"); @@ -1859,7 +1935,11 @@ public void testTransactionTimeout() throws Exception { Assert.assertEquals(request.getTransaction().getState(), ClickHouseTransaction.ACTIVE); checkRowCount(tableName, 3); checkRowCount(request, tableName, 3); - Thread.sleep(3000L); + try { + Thread.sleep(3000L); + } catch (InterruptedException ex) { + Assert.fail("Sleep was interrupted", ex); + } checkRowCount(tableName, 0); try { checkRowCount(request, tableName, 3); @@ -1872,11 +1952,11 @@ public void testTransactionTimeout() throws Exception { } @Test // (groups = "integration") - public void testImplicitTransaction() throws Exception { + public void testImplicitTransaction() throws ClickHouseException { ClickHouseNode server = getServer(); String tableName = "test_implicit_transaction"; - ClickHouseClient.send(server, "drop table if exists " + tableName, - "create table " + tableName + " (id Int64)engine=MergeTree order by id").get(); + sendAndWait(server, "drop table if exists " + tableName, + "create table " + tableName + " (id Int64)engine=MergeTree order by id"); try (ClickHouseClient client = getClient()) { ClickHouseRequest request = client.connect(server); ClickHouseTransaction.setImplicitTransaction(request, true); diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/cache/CaffeineCacheTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/cache/CaffeineCacheTest.java index 19a1ae845..c6535a5db 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/cache/CaffeineCacheTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/cache/CaffeineCacheTest.java @@ -11,7 +11,7 @@ public class CaffeineCacheTest { @Test(groups = { "unit" }) - public void testCache() throws Exception { + public void testCache() { int capacity = 3; ClickHouseCache cache = CaffeineCache.create(capacity, 1L, (k) -> k); Assert.assertNotNull(cache); @@ -32,7 +32,11 @@ public void testCache() throws Exception { Assert.assertEquals(c.asMap().size(), 3); Assert.assertEquals(c.asMap(), m); - Thread.sleep(1500L); + try { + Thread.sleep(1500L); + } catch (InterruptedException e) { + Assert.fail("Sleep was interrupted", e); + } c.cleanUp(); Assert.assertEquals(cache.get("D"), "D"); diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseBoolValueTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseBoolValueTest.java index 789dfb6a2..6e10f6b62 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseBoolValueTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseBoolValueTest.java @@ -4,6 +4,7 @@ import java.math.BigInteger; import java.net.Inet4Address; import java.net.Inet6Address; +import java.net.UnknownHostException; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; @@ -17,7 +18,7 @@ public class ClickHouseBoolValueTest extends BaseClickHouseValueTest { @Test(groups = { "unit" }) - public void testUpdate() throws Exception { + public void testUpdate() { ClickHouseBoolValue v = ClickHouseBoolValue.of(0); Assert.assertEquals(v.getValue(), false); Assert.assertEquals(v.update(true).asByte(), (byte) 1); @@ -87,7 +88,7 @@ public void testUpdate() throws Exception { } @Test(groups = { "unit" }) - public void testValue() throws Exception { + public void testValue() throws UnknownHostException { // null value checkNull(ClickHouseBoolValue.ofNull()); checkNull(ClickHouseBoolValue.of(1).resetToNullOrEmpty()); diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseByteValueTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseByteValueTest.java index fa4db3792..d713d9e78 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseByteValueTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseByteValueTest.java @@ -4,6 +4,7 @@ import java.math.BigInteger; import java.net.Inet4Address; import java.net.Inet6Address; +import java.net.UnknownHostException; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; @@ -17,7 +18,7 @@ public class ClickHouseByteValueTest extends BaseClickHouseValueTest { @Test(groups = { "unit" }) - public void testUpdate() throws Exception { + public void testUpdate() { ClickHouseByteValue v = ClickHouseByteValue.of(-1); Assert.assertEquals(v.getValue(), (byte) -1); Assert.assertEquals(v.update(true).asByte(), (byte) 1); @@ -54,7 +55,7 @@ public void testUpdate() throws Exception { } @Test(groups = { "unit" }) - public void testValue() throws Exception { + public void testValue() throws UnknownHostException { // null value checkNull(ClickHouseByteValue.ofNull()); checkNull(ClickHouseByteValue.of(Byte.MIN_VALUE).resetToNullOrEmpty()); diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseDateTimeValueTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseDateTimeValueTest.java index 6616023d4..36a02d997 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseDateTimeValueTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseDateTimeValueTest.java @@ -4,6 +4,7 @@ import java.math.BigInteger; import java.net.Inet4Address; import java.net.Inet6Address; +import java.net.UnknownHostException; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; @@ -40,7 +41,7 @@ public void testUpdate() { } @Test(groups = { "unit" }) - public void testValueWithoutScale() throws Exception { + public void testValueWithoutScale() throws UnknownHostException { // null value checkNull(ClickHouseDateTimeValue.ofNull(0, ClickHouseValues.UTC_TIMEZONE)); checkNull( @@ -164,7 +165,7 @@ public void testValueWithoutScale() throws Exception { } @Test(groups = { "unit" }) - public void testValueWithScale() throws Exception { + public void testValueWithScale() throws UnknownHostException { // null value checkNull(ClickHouseDateTimeValue.ofNull(3, ClickHouseValues.UTC_TIMEZONE)); checkNull( diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseDateValueTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseDateValueTest.java index d799d23a2..f4a4aa9b1 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseDateValueTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseDateValueTest.java @@ -4,6 +4,7 @@ import java.math.BigInteger; import java.net.Inet4Address; import java.net.Inet6Address; +import java.net.UnknownHostException; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; @@ -15,7 +16,7 @@ public class ClickHouseDateValueTest extends BaseClickHouseValueTest { @Test(groups = { "unit" }) - public void testValue() throws Exception { + public void testValue() throws UnknownHostException { // null value checkNull(ClickHouseDateValue.ofNull()); checkNull(ClickHouseDateValue.of(LocalDate.now()).resetToNullOrEmpty()); diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseDoubleValueTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseDoubleValueTest.java index e91f7e173..e28e61584 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseDoubleValueTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseDoubleValueTest.java @@ -4,6 +4,7 @@ import java.math.BigInteger; import java.net.Inet4Address; import java.net.Inet6Address; +import java.net.UnknownHostException; import java.time.DateTimeException; import java.time.LocalDate; import java.time.LocalDateTime; @@ -18,7 +19,7 @@ public class ClickHouseDoubleValueTest extends BaseClickHouseValueTest { @Test(groups = { "unit" }) - public void testValue() throws Exception { + public void testValue() throws UnknownHostException { // null value checkNull(ClickHouseDoubleValue.ofNull()); checkNull(ClickHouseDoubleValue.of(Double.MAX_VALUE).resetToNullOrEmpty()); diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseFloatValueTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseFloatValueTest.java index 63b92b932..be121d2d7 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseFloatValueTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseFloatValueTest.java @@ -4,6 +4,7 @@ import java.math.BigInteger; import java.net.Inet4Address; import java.net.Inet6Address; +import java.net.UnknownHostException; import java.time.DateTimeException; import java.time.LocalDate; import java.time.LocalDateTime; @@ -17,7 +18,7 @@ public class ClickHouseFloatValueTest extends BaseClickHouseValueTest { @Test(groups = { "unit" }) - public void testValue() throws Exception { + public void testValue() throws UnknownHostException { // null value checkNull(ClickHouseFloatValue.ofNull()); checkNull(ClickHouseFloatValue.of(Float.MAX_VALUE).resetToNullOrEmpty()); diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseIntegerValueTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseIntegerValueTest.java index d2589dead..1fd9c857b 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseIntegerValueTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseIntegerValueTest.java @@ -4,6 +4,7 @@ import java.math.BigInteger; import java.net.Inet4Address; import java.net.Inet6Address; +import java.net.UnknownHostException; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; @@ -16,7 +17,7 @@ public class ClickHouseIntegerValueTest extends BaseClickHouseValueTest { @Test(groups = { "unit" }) - public void testValue() throws Exception { + public void testValue() throws UnknownHostException { // null value checkNull(ClickHouseIntegerValue.ofNull()); checkNull(ClickHouseIntegerValue.of(Integer.MAX_VALUE).resetToNullOrEmpty()); diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseLongValueTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseLongValueTest.java index 442a88bf5..4bf81cb11 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseLongValueTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseLongValueTest.java @@ -4,6 +4,7 @@ import java.math.BigInteger; import java.net.Inet4Address; import java.net.Inet6Address; +import java.net.UnknownHostException; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; @@ -18,7 +19,7 @@ public class ClickHouseLongValueTest extends BaseClickHouseValueTest { @Test(groups = { "unit" }) - public void testSignedValue() throws Exception { + public void testSignedValue() throws UnknownHostException { // null value checkNull(ClickHouseLongValue.ofNull(false)); checkNull(ClickHouseLongValue.of(Long.MAX_VALUE, false).resetToNullOrEmpty()); @@ -159,7 +160,7 @@ public void testSignedValue() throws Exception { } @Test(groups = { "unit" }) - public void testUnsignedValue() throws Exception { + public void testUnsignedValue() throws UnknownHostException { // null value checkNull(ClickHouseLongValue.ofNull(true)); checkNull(ClickHouseLongValue.of(Long.MAX_VALUE, true).resetToNullOrEmpty()); diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseNestedValueTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseNestedValueTest.java index d08bbd884..f6c194ab9 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseNestedValueTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseNestedValueTest.java @@ -8,7 +8,7 @@ public class ClickHouseNestedValueTest extends BaseClickHouseValueTest { @Test(groups = { "unit" }) - public void testMultipleValues() throws Exception { + public void testMultipleValues() { // single type checkValue( ClickHouseNestedValue.of(ClickHouseColumn.parse("a String not null, b String null"), @@ -96,7 +96,7 @@ public void testMultipleValues() throws Exception { } @Test(groups = { "unit" }) - public void testSingleValue() throws Exception { + public void testSingleValue() { // null value checkNull(ClickHouseNestedValue.ofEmpty(ClickHouseColumn.parse("a Nullable(String)")), false, 3, 9); checkNull(ClickHouseNestedValue.ofEmpty(ClickHouseColumn.parse("a String not null")), false, 3, 9); diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseOffsetDateTimeValueTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseOffsetDateTimeValueTest.java index f8cfc069e..af3426bc7 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseOffsetDateTimeValueTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseOffsetDateTimeValueTest.java @@ -4,6 +4,7 @@ import java.math.BigInteger; import java.net.Inet4Address; import java.net.Inet6Address; +import java.net.UnknownHostException; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; @@ -42,7 +43,7 @@ public void testUpdate() { } @Test(groups = { "unit" }) - public void testValueWithoutScale() throws Exception { + public void testValueWithoutScale() throws UnknownHostException { // null value checkNull(ClickHouseOffsetDateTimeValue.ofNull(0, null)); checkNull(ClickHouseOffsetDateTimeValue.of(LocalDateTime.now(), 0, null).resetToNullOrEmpty()); @@ -162,7 +163,7 @@ public void testValueWithoutScale() throws Exception { } @Test(groups = { "unit" }) - public void testValueWithScale() throws Exception { + public void testValueWithScale() throws UnknownHostException { // null value checkNull(ClickHouseOffsetDateTimeValue.ofNull(3, null)); checkNull(ClickHouseOffsetDateTimeValue.of(LocalDateTime.now(), 9, null).resetToNullOrEmpty()); @@ -207,7 +208,7 @@ public void testValueWithScale() throws Exception { } @Test(groups = { "unit" }) - public void testValueWithTimeZone() throws Exception { + public void testValueWithTimeZone() { LocalDateTime dateTime = LocalDateTime.of(2020, 2, 11, 0, 23, 33); TimeZone tz = null; ClickHouseOffsetDateTimeValue v = ClickHouseOffsetDateTimeValue.of(dateTime, 0, tz); diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHousePipedStreamTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHousePipedStreamTest.java index e793f3bd5..4460e7cf0 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHousePipedStreamTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHousePipedStreamTest.java @@ -20,7 +20,7 @@ public class ClickHousePipedStreamTest { @Test(groups = { "unit" }) - public void testRead() throws Exception { + public void testRead() throws InterruptedException, IOException { ClickHousePipedStream stream = new ClickHousePipedStream(4, 3, 1); Assert.assertEquals(stream.queue.size(), 0); try (InputStream in = stream.getInput()) { @@ -80,7 +80,7 @@ public void testRead() throws Exception { } @Test(groups = { "unit" }) - public void testReadBytes() throws Exception { + public void testReadBytes() throws InterruptedException, IOException { ClickHousePipedStream stream = new ClickHousePipedStream(4, 3, 1); Assert.assertEquals(stream.queue.size(), 0); byte[] bytes = new byte[3]; @@ -144,7 +144,7 @@ public void testReadBytes() throws Exception { } @Test(groups = { "unit" }) - public void testWrite() throws Exception { + public void testWrite() throws InterruptedException, IOException { ClickHousePipedStream stream = new ClickHousePipedStream(2, 3, 2); Assert.assertEquals(stream.queue.size(), 0); try (OutputStream out = stream) { @@ -184,7 +184,7 @@ public void testWrite() throws Exception { } @Test(groups = { "unit" }) - public void testWriteBytes() throws Exception { + public void testWriteBytes() throws InterruptedException, IOException { ClickHousePipedStream stream = new ClickHousePipedStream(2, 3, 2); Assert.assertEquals(stream.queue.size(), 0); try (OutputStream out = stream) { @@ -210,7 +210,7 @@ public void testWriteBytes() throws Exception { } @Test(groups = { "unit" }) - public void testPipedStream() throws Exception { + public void testPipedStream() throws InterruptedException, IOException { final int timeout = 10000; ExecutorService executor = Executors.newFixedThreadPool(2); for (int bufferSize = -1; bufferSize < 10; bufferSize++) { diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseShortValueTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseShortValueTest.java index b955bcfcf..05bd187c9 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseShortValueTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseShortValueTest.java @@ -4,6 +4,7 @@ import java.math.BigInteger; import java.net.Inet4Address; import java.net.Inet6Address; +import java.net.UnknownHostException; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; @@ -16,7 +17,7 @@ public class ClickHouseShortValueTest extends BaseClickHouseValueTest { @Test(groups = { "unit" }) - public void testValue() throws Exception { + public void testValue() throws UnknownHostException { // null value checkNull(ClickHouseShortValue.ofNull()); checkNull(ClickHouseShortValue.of(Short.MAX_VALUE).resetToNullOrEmpty()); diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseStringValueTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseStringValueTest.java index cd61357c1..71ff3ed67 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseStringValueTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseStringValueTest.java @@ -3,6 +3,7 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.net.Inet4Address; +import java.net.UnknownHostException; import java.time.LocalDateTime; import java.time.format.DateTimeParseException; import java.util.Arrays; @@ -78,7 +79,7 @@ public void testBinaryValue() { } @Test(groups = { "unit" }) - public void testValue() throws Exception { + public void testValue() throws UnknownHostException { // null value checkNull(ClickHouseStringValue.ofNull()); checkNull(ClickHouseStringValue.of("abc").resetToNullOrEmpty()); diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseTupleValueTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseTupleValueTest.java index d0f40dfbd..52b720acb 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseTupleValueTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/data/ClickHouseTupleValueTest.java @@ -6,7 +6,7 @@ public class ClickHouseTupleValueTest extends BaseClickHouseValueTest { @Test(groups = { "unit" }) - public void testMultipleValues() throws Exception { + public void testMultipleValues() { // single type checkValue(ClickHouseTupleValue.of("one", "two"), UnsupportedOperationException.class, // isInfinity UnsupportedOperationException.class, // isNan @@ -78,7 +78,7 @@ public void testMultipleValues() throws Exception { } @Test(groups = { "unit" }) - public void testSingleValue() throws Exception { + public void testSingleValue() { // null value checkNull(ClickHouseTupleValue.of().resetToNullOrEmpty(), false, 3, 9); checkNull(ClickHouseTupleValue.of(ClickHouseByteValue.of(0).asByte()).resetToNullOrEmpty(), false, 3, 9); diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/data/array/ClickHouseByteArrayValueTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/data/array/ClickHouseByteArrayValueTest.java index 6da44c153..f6cabfb1a 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/data/array/ClickHouseByteArrayValueTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/data/array/ClickHouseByteArrayValueTest.java @@ -5,7 +5,7 @@ public class ClickHouseByteArrayValueTest { @Test(groups = { "unit" }) - public void testConvertToBoolean() throws Exception { + public void testConvertToBoolean() { ClickHouseByteArrayValue v = ClickHouseByteArrayValue .of(new byte[] { 0, 1, -1 }); Assert.assertArrayEquals(v.getValue(), new byte[] { 0, 1, -1 }); @@ -13,7 +13,7 @@ public void testConvertToBoolean() throws Exception { } @Test(groups = { "unit" }) - public void testConvertFromBoolean() throws Exception { + public void testConvertFromBoolean() { ClickHouseByteArrayValue v = ClickHouseByteArrayValue.ofEmpty(); Assert.assertArrayEquals(v.getValue(), new byte[0]); v.update(new boolean[] { false, true, false }); diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/data/array/ClickHouseLongArrayValueTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/data/array/ClickHouseLongArrayValueTest.java index 3f5bdcfb9..57e68ee04 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/data/array/ClickHouseLongArrayValueTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/data/array/ClickHouseLongArrayValueTest.java @@ -7,7 +7,7 @@ public class ClickHouseLongArrayValueTest { @Test(groups = { "unit" }) - public void testConvertToBigInteger() throws Exception { + public void testConvertToBigInteger() { ClickHouseLongArrayValue v = ClickHouseLongArrayValue .of(new long[] { 1L, new BigInteger("9223372036854775808").longValue() }); Assert.assertArrayEquals(v.getValue(), new long[] { 1L, -9223372036854775808L }); @@ -16,7 +16,7 @@ public void testConvertToBigInteger() throws Exception { } @Test(groups = { "unit" }) - public void testConvertFromBigInteger() throws Exception { + public void testConvertFromBigInteger() { ClickHouseLongArrayValue v = ClickHouseLongArrayValue.ofEmpty(); Assert.assertArrayEquals(v.getValue(), new long[0]); v.update(new BigInteger[] { BigInteger.ONE, new BigInteger("9223372036854775808") }); diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/naming/SrvResolverTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/naming/SrvResolverTest.java index c97ce899a..0a4dd3c7f 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/naming/SrvResolverTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/naming/SrvResolverTest.java @@ -16,7 +16,7 @@ public void testLookup() { } @Test(groups = { "integration" }) - public void testResolv() throws Exception { + public void testResolv() { String host = "_sip._udp.sip.voice.google.com"; int port = 5060; diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/stream/NonBlockingPipedOutputStreamTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/stream/NonBlockingPipedOutputStreamTest.java index 572a7e6f7..f2d92d0cd 100644 --- a/clickhouse-client/src/test/java/com/clickhouse/client/stream/NonBlockingPipedOutputStreamTest.java +++ b/clickhouse-client/src/test/java/com/clickhouse/client/stream/NonBlockingPipedOutputStreamTest.java @@ -18,7 +18,7 @@ public class NonBlockingPipedOutputStreamTest { @Test(groups = { "unit" }) - public void testRead() throws Exception { + public void testRead() throws IOException { NonBlockingPipedOutputStream stream = new NonBlockingPipedOutputStream(4, 3, 1, CapacityPolicy.fixedCapacity(3), null); Assert.assertEquals(stream.queue.size(), 0); @@ -77,7 +77,7 @@ public void testRead() throws Exception { } @Test(groups = { "unit" }) - public void testReadBytes() throws Exception { + public void testReadBytes() throws IOException { NonBlockingPipedOutputStream stream = new NonBlockingPipedOutputStream(4, 3, 1, CapacityPolicy.fixedCapacity(3), null); Assert.assertEquals(stream.queue.size(), 0); @@ -140,7 +140,7 @@ public void testReadBytes() throws Exception { } @Test(groups = { "unit" }) - public void testWrite() throws Exception { + public void testWrite() throws IOException { NonBlockingPipedOutputStream stream = new NonBlockingPipedOutputStream(2, 3, 2, CapacityPolicy.fixedCapacity(3), null); Assert.assertEquals(stream.queue.size(), 0); @@ -181,7 +181,7 @@ public void testWrite() throws Exception { } @Test(groups = { "unit" }) - public void testWriteBytes() throws Exception { + public void testWriteBytes() throws IOException { NonBlockingPipedOutputStream stream = new NonBlockingPipedOutputStream(2, 3, 2, CapacityPolicy.fixedCapacity(3), null); Assert.assertEquals(stream.queue.size(), 0); @@ -208,7 +208,7 @@ public void testWriteBytes() throws Exception { } @Test(groups = { "unit" }) - public void testPipedStream() throws Exception { + public void testPipedStream() throws InterruptedException, IOException { final int timeout = 10000; ExecutorService executor = Executors.newFixedThreadPool(2); for (int bufferSize = -1; bufferSize < 10; bufferSize++) { diff --git a/clickhouse-grpc-client/src/test/java/com/clickhouse/client/grpc/ClickHouseGrpcChannelFactoryTest.java b/clickhouse-grpc-client/src/test/java/com/clickhouse/client/grpc/ClickHouseGrpcChannelFactoryTest.java index e40444a05..1e4d62177 100644 --- a/clickhouse-grpc-client/src/test/java/com/clickhouse/client/grpc/ClickHouseGrpcChannelFactoryTest.java +++ b/clickhouse-grpc-client/src/test/java/com/clickhouse/client/grpc/ClickHouseGrpcChannelFactoryTest.java @@ -11,7 +11,7 @@ public class ClickHouseGrpcChannelFactoryTest extends BaseIntegrationTest { @Test(groups = { "integration" }) - public void testGetFactory() throws Exception { + public void testGetFactory() { ClickHouseNode server = getServer(ClickHouseProtocol.GRPC); try (ClickHouseClient client = ClickHouseClient.newInstance()) { ClickHouseRequest request = client.connect(server); diff --git a/clickhouse-grpc-client/src/test/java/com/clickhouse/client/grpc/ClickHouseGrpcClientTest.java b/clickhouse-grpc-client/src/test/java/com/clickhouse/client/grpc/ClickHouseGrpcClientTest.java index 37e136f79..0de672edf 100644 --- a/clickhouse-grpc-client/src/test/java/com/clickhouse/client/grpc/ClickHouseGrpcClientTest.java +++ b/clickhouse-grpc-client/src/test/java/com/clickhouse/client/grpc/ClickHouseGrpcClientTest.java @@ -9,6 +9,7 @@ import java.io.IOException; import com.clickhouse.client.ClickHouseClient; +import com.clickhouse.client.ClickHouseException; import com.clickhouse.client.ClickHouseNode; import com.clickhouse.client.ClickHouseProtocol; import com.clickhouse.client.ClickHouseRecord; @@ -36,14 +37,14 @@ protected Class getClientClass() { } @Test(groups = "integration") - public void testResponseSummary() throws Exception { + public void testResponseSummary() throws ClickHouseException { ClickHouseNode server = getServer(); try (ClickHouseClient client = getClient(); ClickHouseResponse resp = client.connect(server) .option(ClickHouseClientOption.READ_BUFFER_SIZE, 8) .format(ClickHouseFormat.TabSeparatedWithNamesAndTypes) - .query("select number, number+1 from numbers(100)").execute().get()) { + .query("select number, number+1 from numbers(100)").executeAndWait()) { int n = 0; for (ClickHouseRecord record : resp.records()) { Assert.assertEquals(record.size(), 2); diff --git a/clickhouse-http-client/src/test/java/com/clickhouse/client/http/ClickHouseHttpClientTest.java b/clickhouse-http-client/src/test/java/com/clickhouse/client/http/ClickHouseHttpClientTest.java index c50cd83f7..7e57c06e4 100644 --- a/clickhouse-http-client/src/test/java/com/clickhouse/client/http/ClickHouseHttpClientTest.java +++ b/clickhouse-http-client/src/test/java/com/clickhouse/client/http/ClickHouseHttpClientTest.java @@ -5,6 +5,7 @@ import com.clickhouse.client.ClickHouseClient; import com.clickhouse.client.ClickHouseConfig; import com.clickhouse.client.ClickHouseCredentials; +import com.clickhouse.client.ClickHouseException; import com.clickhouse.client.ClickHouseFormat; import com.clickhouse.client.ClickHouseNode; import com.clickhouse.client.ClickHouseNodeSelector; @@ -37,7 +38,7 @@ protected Class getClientClass() { } @Test(groups = "integration") - public void testAuthentication() throws Exception { + public void testAuthentication() throws ClickHouseException { String sql = "select currentUser()"; try (ClickHouseClient client = getClient( new ClickHouseConfig(null, ClickHouseCredentials.fromUserAndPassword("dba", "dba"), null, null)); @@ -68,7 +69,7 @@ public void testAuthentication() throws Exception { @Test(groups = "integration") @Override - public void testSession() throws Exception { + public void testSession() throws ClickHouseException { super.testSession(); ClickHouseNode server = getServer(); @@ -90,7 +91,7 @@ public void testSession() throws Exception { } @Test(groups = { "integration" }) - public void testPing() throws Exception { + public void testPing() { try (ClickHouseClient client = ClickHouseClient.newInstance(ClickHouseProtocol.HTTP)) { Assert.assertTrue(client.ping(getServer(), 3000)); } @@ -124,7 +125,7 @@ public void testPing() throws Exception { } @Test // (groups = "integration") - public void testTransaction() throws Exception { + public void testTransaction() throws ClickHouseException { testAbortTransaction(); testNewTransaction(); testJoinTransaction(); @@ -136,7 +137,7 @@ public void testTransaction() throws Exception { } @Test // (groups = "integration") - public void testSslClientAuth() throws Exception { + public void testSslClientAuth() throws ClickHouseException { // NPE on JDK 8: // java.lang.NullPointerException // at sun.security.provider.JavaKeyStore.convertToBytes(JavaKeyStore.java:822) @@ -160,48 +161,48 @@ public void testSslClientAuth() throws Exception { @Test(groups = { "integration" }) @Override - public void testMutation() throws Exception { + public void testMutation() throws ClickHouseException { super.testMutation(); ClickHouseNode server = getServer(); - ClickHouseClient.send(server, "drop table if exists test_http_mutation", - "create table test_http_mutation(a String, b Nullable(Int64))engine=Memory").get(); + sendAndWait(server, "drop table if exists test_http_mutation", + "create table test_http_mutation(a String, b Nullable(Int64))engine=Memory"); try (ClickHouseClient client = getClient(); ClickHouseResponse response = client.connect(server).set("send_progress_in_http_headers", 1) .query("insert into test_http_mutation select toString(number), number from numbers(1)") - .execute().get()) { + .executeAndWait()) { ClickHouseResponseSummary summary = response.getSummary(); Assert.assertEquals(summary.getWrittenRows(), 1); } } @Test(groups = { "integration" }) - public void testLogComment() throws Exception { + public void testLogComment() throws ClickHouseException { ClickHouseNode server = getServer(ClickHouseProtocol.HTTP); String uuid = UUID.randomUUID().toString(); try (ClickHouseClient client = ClickHouseClient.newInstance()) { ClickHouseRequest request = client.connect(server).format(ClickHouseFormat.RowBinaryWithNamesAndTypes); try (ClickHouseResponse resp = request - .query("select version()").execute().get()) { + .query("select version()").executeAndWait()) { if (!ClickHouseVersion.of(resp.firstRecord().getValue(0).asString()).check("[21.2,)")) { return; } } try (ClickHouseResponse resp = request .option(ClickHouseClientOption.LOG_LEADING_COMMENT, true) - .query("-- select something\r\nselect 1", uuid).execute().get()) { + .query("-- select something\r\nselect 1", uuid).executeAndWait()) { } try (ClickHouseResponse resp = request .option(ClickHouseClientOption.LOG_LEADING_COMMENT, true) - .query("SYSTEM FLUSH LOGS", uuid).execute().get()) { + .query("SYSTEM FLUSH LOGS", uuid).executeAndWait()) { } try (ClickHouseResponse resp = request .option(ClickHouseClientOption.LOG_LEADING_COMMENT, true) .query(ClickHouseParameterizedQuery .of(request.getConfig(), "select log_comment from system.query_log where query_id = :qid")) - .params(ClickHouseStringValue.of(uuid)).execute().get()) { + .params(ClickHouseStringValue.of(uuid)).executeAndWait()) { int counter = 0; for (ClickHouseRecord r : resp.records()) { Assert.assertEquals(r.getValue(0).asString(), "select something"); @@ -213,7 +214,7 @@ public void testLogComment() throws Exception { } @Test(groups = { "integration" }) - public void testPost() throws Exception { + public void testPost() throws ClickHouseException { ClickHouseNode server = getServer(ClickHouseProtocol.HTTP); try (ClickHouseClient client = ClickHouseClient.builder() @@ -221,7 +222,7 @@ public void testPost() throws Exception { // why no detailed error message for this: "select 1,2" try (ClickHouseResponse resp = client.connect(server).compressServerResponse(false) .format(ClickHouseFormat.RowBinaryWithNamesAndTypes) - .query("select 1,2").execute().get()) { + .query("select 1,2").executeAndWait()) { int count = 0; for (ClickHouseRecord r : resp.records()) { Assert.assertEquals(r.getValue(0).asInteger(), 1); @@ -234,7 +235,7 @@ public void testPost() throws Exception { // reuse connection try (ClickHouseResponse resp = client.connect(server).format(ClickHouseFormat.RowBinaryWithNamesAndTypes) - .query("select 3,4").execute().get()) { + .query("select 3,4").executeAndWait()) { int count = 0; for (ClickHouseRecord r : resp.records()) { Assert.assertEquals(r.getValue(0).asInteger(), 3); diff --git a/clickhouse-http-client/src/test/java/com/clickhouse/client/http/DefaultHttpConnectionTest.java b/clickhouse-http-client/src/test/java/com/clickhouse/client/http/DefaultHttpConnectionTest.java index f79bfc001..59e40dee0 100644 --- a/clickhouse-http-client/src/test/java/com/clickhouse/client/http/DefaultHttpConnectionTest.java +++ b/clickhouse-http-client/src/test/java/com/clickhouse/client/http/DefaultHttpConnectionTest.java @@ -6,18 +6,21 @@ import com.clickhouse.client.ClickHouseProtocol; import com.clickhouse.client.ClickHouseRequest; +import java.io.IOException; + import org.testng.Assert; import org.testng.annotations.Test; public class DefaultHttpConnectionTest extends BaseIntegrationTest { @Test(groups = { "integration" }) - public void testConnectionReuse() throws Exception { + public void testConnectionReuse() throws IOException { ClickHouseNode server = getServer(ClickHouseProtocol.HTTP); try (ClickHouseClient client = ClickHouseClient.newInstance()) { ClickHouseRequest req = client.connect(server); ClickHouseHttpConnection conn = ClickHouseHttpConnectionFactory.createConnection(server, req, null); + Assert.assertNotNull(conn); } } } diff --git a/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/internal/ClickHouseConnectionImpl.java b/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/internal/ClickHouseConnectionImpl.java index a89a024c9..76d7baf13 100644 --- a/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/internal/ClickHouseConnectionImpl.java +++ b/clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/internal/ClickHouseConnectionImpl.java @@ -774,7 +774,7 @@ public PreparedStatement prepareStatement(String sql, int resultSetType, int res if (parsedStmt.hasTempTable()) { // queries using external/temporary table ps = new TableBasedPreparedStatement(this, - clientRequest.write().query(parsedStmt.getSQL(), newQueryId()), parsedStmt, + clientRequest.copy().query(parsedStmt.getSQL(), newQueryId()), parsedStmt, resultSetType, resultSetConcurrency, resultSetHoldability); } else if (parsedStmt.getStatementType() == StatementType.INSERT) { if (!ClickHouseChecker.isNullOrBlank(parsedStmt.getInput())) { diff --git a/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseConnectionTest.java b/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseConnectionTest.java index ec8eb0ead..7dc51da12 100644 --- a/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseConnectionTest.java +++ b/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseConnectionTest.java @@ -30,7 +30,7 @@ public void testCreateArray() throws SQLException { } @Test // (groups = "integration") - public void testAutoCommitMode() throws Exception { + public void testAutoCommitMode() throws SQLException { Properties props = new Properties(); props.setProperty("transactionSupport", "true"); @@ -50,7 +50,7 @@ public void testAutoCommitMode() throws Exception { } @Test(groups = "integration") - public void testNonExistDatabase() throws Exception { + public void testNonExistDatabase() throws SQLException { String database = UUID.randomUUID().toString(); Properties props = new Properties(); props.setProperty(ClickHouseClientOption.DATABASE.getKey(), database); @@ -199,7 +199,7 @@ public void testReadOnly() throws SQLException { } @Test // (groups = "integration") - public void testTransaction() throws Exception { + public void testTransaction() throws SQLException { testAutoCommit(); testManualCommit(); testNestedTransactions(); @@ -207,7 +207,7 @@ public void testTransaction() throws Exception { } @Test // (groups = "integration") - public void testAutoCommit() throws Exception { + public void testAutoCommit() throws SQLException { Properties props = new Properties(); props.setProperty("transactionSupport", "true"); String tableName = "test_jdbc_tx_auto_commit"; @@ -294,7 +294,7 @@ public void testAutoCommit() throws Exception { } @Test // (groups = "integration") - public void testManualCommit() throws Exception { + public void testManualCommit() throws SQLException { Properties props = new Properties(); props.setProperty("autoCommit", "false"); Properties txProps = new Properties(); @@ -397,7 +397,7 @@ public void testManualCommit() throws Exception { } @Test // (groups = "integration") - public void testNestedTransactions() throws Exception { + public void testNestedTransactions() throws SQLException { Properties props = new Properties(); props.setProperty("autoCommit", "false"); props.setProperty("transactionSupport", "true"); @@ -436,7 +436,7 @@ public void testNestedTransactions() throws Exception { } @Test // (groups = "integration") - public void testParallelTransactions() throws Exception { + public void testParallelTransactions() throws SQLException { Properties props = new Properties(); props.setProperty("autoCommit", "false"); props.setProperty("transactionSupport", "true"); diff --git a/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHousePreparedStatementTest.java b/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHousePreparedStatementTest.java index b00f47b70..9fd4b6054 100644 --- a/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHousePreparedStatementTest.java +++ b/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHousePreparedStatementTest.java @@ -1,10 +1,13 @@ package com.clickhouse.jdbc; import java.io.ByteArrayInputStream; +import java.io.IOException; import java.math.BigDecimal; import java.net.Inet4Address; import java.net.Inet6Address; +import java.net.MalformedURLException; import java.net.URL; +import java.net.UnknownHostException; import java.nio.charset.StandardCharsets; import java.sql.BatchUpdateException; import java.sql.Connection; @@ -27,6 +30,7 @@ import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; +import java.util.concurrent.ExecutionException; import com.clickhouse.client.ClickHouseConfig; import com.clickhouse.client.ClickHouseDataStreamFactory; @@ -714,7 +718,7 @@ public void testBatchInsert() throws SQLException { } @Test(groups = "integration") - public void testBatchInsertWithoutUnboundedQueue() throws Exception { + public void testBatchInsertWithoutUnboundedQueue() throws SQLException { Properties props = new Properties(); props.setProperty(ClickHouseClientOption.WRITE_BUFFER_SIZE.getKey(), "1"); props.setProperty(ClickHouseClientOption.MAX_QUEUED_BUFFERS.getKey(), "1"); @@ -1000,7 +1004,7 @@ public void testExecuteWithOrWithoutParameters(String tableSuffix, String query, } @Test(groups = "integration") - public void testLoadRawData() throws Exception { + public void testLoadRawData() throws IOException, SQLException { try (ClickHouseConnection conn = newConnection(new Properties()); ClickHouseStatement stmt = conn.createStatement(); PreparedStatement ps = conn.prepareStatement( @@ -1029,7 +1033,11 @@ public void testLoadRawData() throws Exception { } } - Assert.assertTrue(future.get() >= 0); + try { + Assert.assertTrue(future.get() >= 0); + } catch (InterruptedException | ExecutionException ex) { + Assert.fail("Failed to get result", ex); + } } } @@ -1145,7 +1153,7 @@ public void testNonBatchUpdate(String mode, String query) throws SQLException { } @Test(dataProvider = "columnsWithDefaultValue", groups = "integration") - public void testInsertDefaultValue(String columnType, String defaultExpr, String defaultValue) throws Exception { + public void testInsertDefaultValue(String columnType, String defaultExpr, String defaultValue) throws SQLException { Properties props = new Properties(); props.setProperty(JdbcConfig.PROP_NULL_AS_DEFAULT, "1"); props.setProperty(ClickHouseClientOption.COMPRESS.getKey(), "false"); @@ -1202,7 +1210,7 @@ public void testInsertDefaultValue(String columnType, String defaultExpr, String } @Test(dataProvider = "columnsWithoutDefaultValue", groups = "integration") - public void testInsertNullValue(String columnType, String defaultValue) throws Exception { + public void testInsertNullValue(String columnType, String defaultValue) throws SQLException { Properties props = new Properties(); props.setProperty(ClickHouseClientOption.FORMAT.getKey(), ClickHouseFormat.TabSeparatedWithNamesAndTypes.name()); @@ -1272,7 +1280,7 @@ public void testInsertNullValue(String columnType, String defaultValue) throws E } @Test(groups = "integration") - public void testInsertStringAsArray() throws Exception { + public void testInsertStringAsArray() throws SQLException { try (ClickHouseConnection conn = newConnection(new Properties()); Statement s = conn.createStatement(); PreparedStatement stmt = conn.prepareStatement( @@ -1316,7 +1324,7 @@ public void testInsertStringAsArray() throws Exception { } @Test(groups = "integration") - public void testInsertWithFunction() throws Exception { + public void testInsertWithFunction() throws SQLException, UnknownHostException { try (ClickHouseConnection conn = newConnection(new Properties()); Statement s = conn.createStatement(); PreparedStatement stmt = conn.prepareStatement( @@ -1354,7 +1362,7 @@ public void testInsertWithFunction() throws Exception { } @Test(groups = "integration") - public void testInsertWithSelect() throws Exception { + public void testInsertWithSelect() throws SQLException { try (ClickHouseConnection conn = newConnection(new Properties()); Statement s = conn.createStatement(); PreparedStatement ps1 = conn @@ -1416,7 +1424,7 @@ public void testQueryWithNamedParameter() throws SQLException { } @Test(groups = "integration") - public void testInsertWithAndSelect() throws Exception { + public void testInsertWithAndSelect() throws SQLException { try (ClickHouseConnection conn = newConnection(new Properties()); Statement s = conn.createStatement()) { s.execute("drop table if exists test_insert_with_and_select; " @@ -1442,7 +1450,7 @@ public void testInsertWithAndSelect() throws Exception { } @Test(groups = "integration") - public void testInsertWithMultipleValues() throws Exception { + public void testInsertWithMultipleValues() throws MalformedURLException, SQLException { try (ClickHouseConnection conn = newConnection(new Properties()); Statement s = conn.createStatement()) { s.execute("drop table if exists test_insert_with_multiple_values; " @@ -1484,7 +1492,7 @@ public void testInsertWithMultipleValues() throws Exception { } @Test(groups = "integration") - public void testInsertWithNullDateTime() throws Exception { + public void testInsertWithNullDateTime() throws SQLException { Properties props = new Properties(); props.setProperty(JdbcConfig.PROP_NULL_AS_DEFAULT, "2"); try (ClickHouseConnection conn = newConnection(props); @@ -1517,7 +1525,7 @@ public void testInsertWithNullDateTime() throws Exception { } @Test(groups = "integration") - public void testGetParameterMetaData() throws Exception { + public void testGetParameterMetaData() throws SQLException { try (Connection conn = newConnection(new Properties()); PreparedStatement emptyPs = conn.prepareStatement("select 1"); PreparedStatement inputPs = conn.prepareStatement( diff --git a/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseResultSetTest.java b/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseResultSetTest.java index ef975e78a..f654cd93d 100644 --- a/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseResultSetTest.java +++ b/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseResultSetTest.java @@ -297,7 +297,7 @@ public void testNullableValues(ClickHouseDataType type, Object value, BiFunction } @Test(dataProvider = "nullableColumns", groups = "integration") - public void testNullValue(String columnType, String defaultValue, Class clazz) throws Exception { + public void testNullValue(String columnType, String defaultValue, Class clazz) throws SQLException { Properties props = new Properties(); props.setProperty(JdbcConfig.PROP_NULL_AS_DEFAULT, "2"); String tableName = "test_query_null_value_" + columnType.split("\\(")[0].trim().toLowerCase(); diff --git a/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseStatementTest.java b/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseStatementTest.java index 9349cf9dc..71ebefd20 100644 --- a/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseStatementTest.java +++ b/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseStatementTest.java @@ -247,7 +247,7 @@ public void testAsyncInsert() throws SQLException { } @Test(dataProvider = "connectionProperties", groups = "integration") - public void testCancelQuery(Properties props) throws Exception { + public void testCancelQuery(Properties props) throws SQLException { try (ClickHouseConnection conn = newConnection(props); ClickHouseStatement stmt = conn.createStatement();) { CountDownLatch c = new CountDownLatch(1); @@ -270,6 +270,8 @@ public void testCancelQuery(Properties props) throws Exception { }); try { c.await(5, TimeUnit.SECONDS); + } catch (Exception e) { + Assert.fail("Failed to wait", e); } finally { stmt.cancel(); } diff --git a/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/internal/ClickHouseJdbcUrlParserTest.java b/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/internal/ClickHouseJdbcUrlParserTest.java index f3af0cd63..406963f4e 100644 --- a/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/internal/ClickHouseJdbcUrlParserTest.java +++ b/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/internal/ClickHouseJdbcUrlParserTest.java @@ -137,7 +137,7 @@ public void testParseWithProperties() throws SQLException, URISyntaxException { } @Test(groups = "unit") - public void testParseCredentials() throws Exception { + public void testParseCredentials() throws SQLException { Properties props = new Properties(); props.setProperty("user", "default1"); props.setProperty("password", "password1"); diff --git a/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/parser/ClickHouseSqlParserTest.java b/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/parser/ClickHouseSqlParserTest.java index 33abd1ff9..02675e67b 100644 --- a/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/parser/ClickHouseSqlParserTest.java +++ b/clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/parser/ClickHouseSqlParserTest.java @@ -768,7 +768,7 @@ static void parseAllSqlFiles(File f) throws IOException { } // TODO: add a sub-module points to ClickHouse/tests/queries? - public static void main(String[] args) throws Exception { + public static void main(String[] args) throws IOException { String chTestQueryDir = "D:/Sources/Github/ch/queries"; if (args != null && args.length > 0) { chTestQueryDir = args[0];