Skip to content

Commit 9225473

Browse files
committed
Update product name test to deel with cloud environment
1 parent 338e722 commit 9225473

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

flink-connector-clickhouse-1.17/src/test/java/org/apache/flink/connector/clickhouse/sink/ClickHouseSinkTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ void ProductNameTest() throws Exception {
314314
if (ClickHouseServerForTests.isCloud())
315315
Thread.sleep(5000);
316316
// let's wait until data will be available in query log
317-
String productName = ClickHouseServerForTests.extractProductName(ClickHouseServerForTests.getDatabase(), tableName);
317+
String startWith = String.format("Flink-ClickHouse-Sink/%s", ClickHouseSinkVersion.getVersion());
318+
String productName = ClickHouseServerForTests.extractProductName(ClickHouseServerForTests.getDatabase(), tableName, startWith);
318319
String compareString = String.format("Flink-ClickHouse-Sink/%s (fv:flink/%s, lv:scala/2.12)", ClickHouseSinkVersion.getVersion(), flinkVersion);
319320

320321
boolean isContains = productName.contains(compareString);

flink-connector-clickhouse-1.17/src/test/java/org/apache/flink/connector/test/embedded/clickhouse/ClickHouseServerForTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ public static int countRows(String table) throws ExecutionException, Interrupted
123123
return countResult.get(0).getInteger(1);
124124
}
125125
// http_user_agent
126-
public static String extractProductName(String databaseName, String tableName) {
127-
String extractProductName = String.format("SELECT http_user_agent, tables FROM clusterAllReplicas('default', system.query_log) WHERE type = 'QueryStart' AND query_kind = 'Insert' AND has(databases,'%s') AND has(tables,'%s.%s') LIMIT 100", databaseName, databaseName, tableName);
126+
public static String extractProductName(String databaseName, String tableName, String startWith) {
127+
String extractProductName = String.format("SELECT http_user_agent, tables FROM clusterAllReplicas('default', system.query_log) WHERE type = 'QueryStart' AND query_kind = 'Insert' AND has(databases,'%s') AND has(tables,'%s.%s') and startsWith(http_user_agent, '%s') LIMIT 100", databaseName, databaseName, tableName, startWith);
128128
Client client = ClickHouseTestHelpers.getClient(host, port, isSSL, username, password);
129129
List<GenericRecord> userAgentResult = client.queryAll(extractProductName);
130130
if (!userAgentResult.isEmpty()) {

flink-connector-clickhouse-2.0.0/src/test/java/org/apache/flink/connector/clickhouse/sink/ClickHouseSinkTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ void ProductNameTest() throws Exception {
308308
if (ClickHouseServerForTests.isCloud())
309309
Thread.sleep(5000);
310310
// let's wait until data will be available in query log
311-
String productName = ClickHouseServerForTests.extractProductName(ClickHouseServerForTests.getDatabase(), tableName, "Flink-ClickHouse-Sink");
311+
String startWith = String.format("Flink-ClickHouse-Sink/%s", ClickHouseSinkVersion.getVersion());
312+
String productName = ClickHouseServerForTests.extractProductName(ClickHouseServerForTests.getDatabase(), tableName, startWith);
312313
String compareString = String.format("Flink-ClickHouse-Sink/%s (fv:flink/2.0.0, lv:scala/2.12)", ClickHouseSinkVersion.getVersion());
313314
boolean isContains = productName.contains(compareString);
314315
Assertions.assertTrue(isContains, "Expected user agent to contain: " + compareString + " but got: " + productName);

flink-connector-clickhouse-2.0.0/src/test/java/org/apache/flink/connector/test/embedded/clickhouse/ClickHouseServerForTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ public static int countRows(String table) throws ExecutionException, Interrupted
124124
}
125125

126126
// http_user_agent
127-
public static String extractProductName(String databaseName, String tableName, String productNameStartWith) {
128-
String extractProductName = String.format("SELECT http_user_agent, tables FROM clusterAllReplicas('default', system.query_log) WHERE type = 'QueryStart' AND query_kind = 'Insert' AND has(databases,'%s') AND has(tables,'%s.%s') LIMIT 100", databaseName, databaseName, tableName);
127+
public static String extractProductName(String databaseName, String tableName, String startWith) {
128+
String extractProductName = String.format("SELECT http_user_agent, tables FROM clusterAllReplicas('default', system.query_log) WHERE type = 'QueryStart' AND query_kind = 'Insert' AND has(databases,'%s') AND has(tables,'%s.%s') and startsWith(http_user_agent, '%s') LIMIT 100", databaseName, databaseName, tableName, startWith);
129129
Client client = ClickHouseTestHelpers.getClient(host, port, isSSL, username, password);
130130
List<GenericRecord> userAgentResult = client.queryAll(extractProductName);
131131
String userAgentValue = null;
132132
if (!userAgentResult.isEmpty()) {
133133
for (GenericRecord userAgent : userAgentResult) {
134134
userAgentValue = userAgent.getString(1);
135-
if (userAgentValue.contains(productNameStartWith))
135+
if (userAgentValue.contains(startWith))
136136
return userAgent.getString(1);
137137
}
138138
throw new RuntimeException("Can not extract product name from " + userAgentValue);

0 commit comments

Comments
 (0)