Skip to content

Commit 0ae8197

Browse files
author
Paultagoras
committed
Update ClickHouseHttpClientTest.java
1 parent 967c6db commit 0ae8197

File tree

1 file changed

+15
-73
lines changed

1 file changed

+15
-73
lines changed

clickhouse-http-client/src/test/java/com/clickhouse/client/http/ClickHouseHttpClientTest.java

Lines changed: 15 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -140,109 +140,51 @@ public void testAuthentication() throws ClickHouseException {
140140

141141
@Test(groups = "integration")
142142
public void testUserAgent() throws Exception {
143+
testUserAgent(ClickHouseClientOption.PRODUCT_NAME, "MyCustomProduct");
144+
testUserAgent(ClickHouseClientOption.CLIENT_NAME, "MyCustomClient");
145+
}
146+
private void testUserAgent(ClickHouseOption option, String optionValue) throws Exception {
143147
final ClickHouseNode server = getServer();
144-
final String sql = "select :uuid(String)";
148+
final String sql = "SELECT :uuid(String)";
145149

146150
String uuid = UUID.randomUUID().toString();
147151
String queryId = UUID.randomUUID().toString();
148-
try (ClickHouseClient client = getClient();
149-
ClickHouseResponse response = newRequest(client, server)
150-
.query(ClickHouseParameterizedQuery.of(client.getConfig(), sql), queryId)
151-
.params(ClickHouseStringValue.of(uuid))
152-
.executeAndWait()) {
153-
Assert.assertEquals(response.firstRecord().getValue(0).asString(), uuid);
154-
}
155-
ClickHouseClient.send(server, "SYSTEM FLUSH LOGS").get();
156-
157-
String selectQuery = "select http_user_agent from system.query_log where query='select ''" + uuid + "'''";
158-
if (isCloud()) {
159-
selectQuery = "SELECT http_user_agent FROM clusterAllReplicas(default, 'system', query_log) WHERE query_id='" + queryId + "'";
160-
}
161-
162-
int loopCount = 0;
163-
do {
164-
try (ClickHouseClient client = getClient();
165-
ClickHouseResponse response = newRequest(client, server)
166-
.query(selectQuery)
167-
.format(ClickHouseFormat.TSVWithNamesAndTypes)
168-
.executeAndWait()) {
169-
if (response.records().iterator().hasNext()) {
170-
String result = response.firstRecord().getValue(0).asString();
171-
Assert.assertTrue(result.startsWith(client.getConfig().getProductName()));
172-
Assert.assertTrue(result.indexOf("Http") > 0);
173-
break;
174-
} else {
175-
Thread.sleep(2500);
176-
}
177-
}
178-
} while (loopCount++ < 5);
179-
180-
uuid = UUID.randomUUID().toString();
181-
queryId = UUID.randomUUID().toString();
182-
try (ClickHouseClient client = getClient();
183-
ClickHouseResponse response = newRequest(client, server)
184-
.option(ClickHouseClientOption.PRODUCT_NAME, "MyCustomClient")
185-
.query(ClickHouseParameterizedQuery.of(client.getConfig(), sql), queryId)
186-
.params(ClickHouseStringValue.of(uuid))
187-
.executeAndWait()) {
188-
Assert.assertEquals(response.firstRecord().getValue(0).asString(), uuid);
189-
}
190-
ClickHouseClient.send(server, "SYSTEM FLUSH LOGS").get();
191-
192-
selectQuery = "select http_user_agent from system.query_log where query='select ''" + uuid + "'''";
193-
if (isCloud()) {
194-
selectQuery = "SELECT http_user_agent FROM clusterAllReplicas(default, 'system', query_log) WHERE query_id='" + queryId + "'";
195-
}
196-
197-
loopCount = 0;
198-
do {
199-
try (ClickHouseClient client = getClient();
200-
ClickHouseResponse response = newRequest(client, server)
201-
.query(selectQuery)
202-
.executeAndWait()) {
203-
if (response.records().iterator().hasNext()) {
204-
String result = response.firstRecord().getValue(0).asString();
205-
Assert.assertTrue(result.startsWith("MyCustomClient ClickHouse-JavaClient/"));
206-
Assert.assertTrue(result.indexOf("Http") > 0);
207-
break;
208-
} else {
209-
Thread.sleep(2500);
210-
}
211-
}
212-
} while (loopCount++ < 5);
213-
214-
uuid = UUID.randomUUID().toString();
215152
try (ClickHouseClient client = getClient();
216153
ClickHouseResponse response = newRequest(client, server)
217-
.option(ClickHouseClientOption.CLIENT_NAME, "MyCustomClient")
154+
.option(option, optionValue)
218155
.query(ClickHouseParameterizedQuery.of(client.getConfig(), sql), queryId)
219156
.params(ClickHouseStringValue.of(uuid))
220157
.executeAndWait()) {
221158
Assert.assertEquals(response.firstRecord().getValue(0).asString(), uuid);
222159
}
223160
ClickHouseClient.send(server, "SYSTEM FLUSH LOGS").get();
224161

225-
selectQuery = "select http_user_agent from system.query_log where query='select ''" + uuid + "'''";
162+
String selectQuery = "SELECT http_user_agent FROM system.query_log WHERE query_id='" + queryId + "'";
226163
if (isCloud()) {
227164
selectQuery = "SELECT http_user_agent FROM clusterAllReplicas(default, 'system', query_log) WHERE query_id='" + queryId + "'";
228165
}
229166

230-
loopCount = 0;
167+
int loopCount = 0;
231168
do {
232169
try (ClickHouseClient client = getClient();
233170
ClickHouseResponse response = newRequest(client, server)
171+
.option(option, optionValue)
234172
.query(selectQuery)
235173
.executeAndWait()) {
236174
if (response.records().iterator().hasNext()) {
237-
Assert.assertTrue(response.firstRecord().getValue(0).asString().startsWith("MyCustomClient ClickHouse-JavaClient/"));
175+
String result = response.firstRecord().getValue(0).asString();
176+
Assert.assertTrue(result.startsWith(optionValue + " ClickHouse-JavaClient/"));
177+
Assert.assertTrue(result.indexOf("Http") > 0);
238178
break;
239179
} else {
240180
Thread.sleep(2500);
241181
}
242182
}
243-
} while (loopCount++ < 5);
183+
} while (loopCount++ < 10);
244184
}
245185

186+
187+
246188
@Override
247189
@Test(groups = "integration")
248190
public void testSession() throws ClickHouseException {

0 commit comments

Comments
 (0)