Skip to content

Commit 3218361

Browse files
author
Paultagoras
committed
Adjusting performance tests
1 parent 03c85b0 commit 3218361

File tree

3 files changed

+57
-17
lines changed

3 files changed

+57
-17
lines changed

client-v2/src/test/java/com/clickhouse/client/insert/InsertTests.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import com.clickhouse.client.ClickHouseNode;
88
import com.clickhouse.client.ClickHouseNodeSelector;
99
import com.clickhouse.client.ClickHouseProtocol;
10-
import com.clickhouse.client.ClickHouseRequest;
11-
import com.clickhouse.client.ClickHouseResponse;
1210
import com.clickhouse.client.api.Client;
1311
import com.clickhouse.client.api.enums.Protocol;
1412
import com.clickhouse.client.api.insert.InsertResponse;
@@ -18,17 +16,12 @@
1816
import com.clickhouse.client.api.metrics.ServerMetrics;
1917
import com.clickhouse.client.api.query.GenericRecord;
2018
import com.clickhouse.client.config.ClickHouseClientOption;
21-
import com.clickhouse.client.http.ClickHouseHttpClient;
22-
import com.clickhouse.client.http.config.ClickHouseHttpOption;
23-
import com.clickhouse.config.ClickHouseOption;
2419
import com.clickhouse.data.ClickHouseFormat;
2520
import com.github.tomakehurst.wiremock.WireMockServer;
26-
import com.github.tomakehurst.wiremock.admin.model.ScenarioState;
2721
import com.github.tomakehurst.wiremock.client.WireMock;
2822
import com.github.tomakehurst.wiremock.common.ConsoleNotifier;
2923
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
3024
import com.github.tomakehurst.wiremock.http.Fault;
31-
import org.apache.hc.client5.http.impl.Wire;
3225
import org.testcontainers.shaded.org.apache.commons.lang3.RandomStringUtils;
3326
import org.testng.Assert;
3427
import org.testng.annotations.AfterMethod;
@@ -39,12 +32,8 @@
3932
import java.io.ByteArrayOutputStream;
4033
import java.io.IOException;
4134
import java.io.PrintWriter;
42-
import java.io.Serializable;
43-
import java.net.ConnectException;
4435
import java.util.ArrayList;
45-
import java.util.HashMap;
4636
import java.util.List;
47-
import java.util.Map;
4837
import java.util.UUID;
4938
import java.util.concurrent.TimeUnit;
5039

@@ -156,6 +145,28 @@ public void insertRawData() throws Exception {
156145
assertEquals(records.size(), 1000);
157146
}
158147

148+
149+
@Test(groups = { "integration" }, enabled = true)
150+
public void insertRawDataSimple() throws Exception {
151+
insertRawDataSimple(1000);
152+
}
153+
public void insertRawDataSimple(int numberOfRecords) throws Exception {
154+
final String tableName = "raw_data_table";
155+
createTable(String.format("CREATE TABLE IF NOT EXISTS %s (Id UInt32, event_ts Timestamp, name String, p1 Int64, p2 String) ENGINE = MergeTree() ORDER BY ()", tableName));
156+
157+
settings.setInputStreamCopyBufferSize(8198 * 2);
158+
ByteArrayOutputStream data = new ByteArrayOutputStream();
159+
PrintWriter writer = new PrintWriter(data);
160+
for (int i = 0; i < numberOfRecords; i++) {
161+
writer.printf("%d\t%s\t%s\t%d\t%s\n", i, "2021-01-01 00:00:00", "name" + i, i, "p2");
162+
}
163+
writer.flush();
164+
InsertResponse response = client.insert(tableName, new ByteArrayInputStream(data.toByteArray()),
165+
ClickHouseFormat.TSV, settings).get(30, TimeUnit.SECONDS);
166+
OperationMetrics metrics = response.getMetrics();
167+
assertEquals((int)response.getWrittenRows(), numberOfRecords );
168+
}
169+
159170
@Test(groups = { "integration" }, enabled = true)
160171
public void testNoHttpResponseFailure() {
161172
WireMockServer faultyServer = new WireMockServer( WireMockConfiguration

client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@ public void testQueryAll(int numberOfRecords) throws Exception {
188188
Assert.assertNotNull(hostnameRecord);
189189
}
190190

191+
@Test(groups = {"integration"})
192+
public void testQueryAllSimple() throws Exception {
193+
testQueryAllSimple(10);
194+
}
195+
public void testQueryAllSimple(int numberOfRecords) throws Exception {
196+
GenericRecord record = client.queryAll("SELECT number FROM system.numbers LIMIT " + numberOfRecords).stream().findFirst().get();
197+
Assert.assertNotNull(record);
198+
}
199+
191200
@Test(groups = {"integration"})
192201
public void testQueryAllNoResult() throws Exception {
193202
List<GenericRecord> records = client.queryAll("CREATE DATABASE IF NOT EXISTS test_db");

client-v2/src/test/perf/com/clickhouse/client/ClientBenchmark.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
@Threads(1)
1616
public class ClientBenchmark {
1717
private static final Logger LOGGER = LoggerFactory.getLogger(ClientBenchmark.class);
18+
private static final int SMALL_SIZE = 1000;
19+
private static final int MEDIUM_SIZE = 1000000;
20+
private static final int LARGE_SIZE = 10000000;
1821

1922
@Setup
2023
public void setup() {
@@ -43,7 +46,7 @@ public void queryBenchmarkSmall() throws Exception {
4346
LOGGER.info("(V2) Query benchmark");
4447
QueryTests queryTests = new QueryTests(false, false);
4548
queryTests.setUp();
46-
queryTests.testQueryAll(1000);
49+
queryTests.testQueryAllSimple(SMALL_SIZE);
4750
queryTests.tearDown();
4851
}
4952

@@ -52,7 +55,7 @@ public void queryBenchmarkMedium() throws Exception {
5255
LOGGER.info("(V2) Query benchmark");
5356
QueryTests queryTests = new QueryTests(false, false);
5457
queryTests.setUp();
55-
queryTests.testQueryAll(1000000);
58+
queryTests.testQueryAllSimple(MEDIUM_SIZE);
5659
queryTests.tearDown();
5760
}
5861

@@ -61,17 +64,34 @@ public void queryBenchmarkLarge() throws Exception {
6164
LOGGER.info("(V2) Query benchmark");
6265
QueryTests queryTests = new QueryTests(false, false);
6366
queryTests.setUp();
64-
queryTests.testQueryAll(1000000000);
67+
queryTests.testQueryAllSimple(LARGE_SIZE);
6568
queryTests.tearDown();
6669
}
6770

6871
@Benchmark
69-
public void insertRawDataBenchmark() throws Exception {
72+
public void insertRawDataBenchmarkSmall() throws Exception {
7073
LOGGER.info("(V2) Insert raw data benchmark");
7174
InsertTests insertTests = new InsertTests(false, false);
7275
insertTests.setUp();
73-
insertTests.insertRawData();
74-
insertTests.insertSimplePOJOs();
76+
insertTests.insertRawDataSimple(SMALL_SIZE);
77+
insertTests.tearDown();
78+
}
79+
80+
@Benchmark
81+
public void insertRawDataBenchmarkMedium() throws Exception {
82+
LOGGER.info("(V2) Insert raw data benchmark");
83+
InsertTests insertTests = new InsertTests(false, false);
84+
insertTests.setUp();
85+
insertTests.insertRawDataSimple(MEDIUM_SIZE);
86+
insertTests.tearDown();
87+
}
88+
89+
@Benchmark
90+
public void insertRawDataBenchmarkLarge() throws Exception {
91+
LOGGER.info("(V2) Insert raw data benchmark");
92+
InsertTests insertTests = new InsertTests(false, false);
93+
insertTests.setUp();
94+
insertTests.insertRawDataSimple(LARGE_SIZE);
7595
insertTests.tearDown();
7696
}
7797

0 commit comments

Comments
 (0)