summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlijinyang <[email protected]>2024-06-14 16:34:19 +0800
committerlijinyang <[email protected]>2024-06-14 16:34:19 +0800
commit47568f340cf5d084b6e3198e992718e10bdc41c1 (patch)
tree8eb69a711d42606cd5d8d919511197cd49168f17
parenta534888f97bd019e5aafde397e8c536b256abf7a (diff)
fix:GAL-596 QGW通过Nginx查询CH相关单元测试
-rw-r--r--src/test/java/com/mesa/reportservice/service/impl/QueryGatewayServiceImplTest.java44
-rw-r--r--src/test/resources/parameters/queryGatewayTest.json4
2 files changed, 47 insertions, 1 deletions
diff --git a/src/test/java/com/mesa/reportservice/service/impl/QueryGatewayServiceImplTest.java b/src/test/java/com/mesa/reportservice/service/impl/QueryGatewayServiceImplTest.java
index d805261..7eef27d 100644
--- a/src/test/java/com/mesa/reportservice/service/impl/QueryGatewayServiceImplTest.java
+++ b/src/test/java/com/mesa/reportservice/service/impl/QueryGatewayServiceImplTest.java
@@ -1,7 +1,10 @@
package com.mesa.reportservice.service.impl;
+import cn.hutool.log.Log;
+import cn.hutool.log.LogFactory;
import com.mesa.ReportServiceApplicationTests;
import com.mesa.reportservice.bean.HttpResult;
+import com.mesa.reportservice.exception.SQSException;
import com.mesa.reportservice.service.QueryGatewayService;
import org.junit.Assert;
import org.junit.Test;
@@ -13,6 +16,8 @@ import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import static com.mesa.reportservice.exception.SQSCode.ERROR;
+
/**
* @Auther: lijinyang
* @Date: 2024/01/04/17:05
@@ -22,6 +27,8 @@ public class QueryGatewayServiceImplTest extends ReportServiceApplicationTests {
private static final String QUERY_ID_PATTERN = "^[a-f0-9]{32}:[a-f0-9]{32}$";
+ private static final Log logger = LogFactory.get();
+
@Autowired
private QueryGatewayService queryGatewayService;
@@ -93,4 +100,41 @@ public class QueryGatewayServiceImplTest extends ReportServiceApplicationTests {
httpResult = queryGatewayService.deleteJob(queryId);
Assert.assertTrue(httpResult.getCode() == HttpStatus.NOT_FOUND.value());
}
+
+ @Test
+ public void highLatencyQuerySuccess() throws IOException {
+ String sql = this.jsonToInParameter("parameters/queryGatewayTest.json", "highLatencyQuerySuccess", String.class);
+ HttpResult httpResult = queryGatewayService.queryJob(sql);
+ Assert.assertTrue(httpResult.getCode() == HttpStatus.OK.value());
+ }
+
+ @Test
+ public void highLatencyQueryCancel() throws IOException {
+ try {
+ String sql = this.jsonToInParameter("parameters/queryGatewayTest.json", "highLatencyQueryCancel", String.class);
+ String queryId = queryGatewayService.getQueryId(sql);
+ Thread thread = new Thread(() -> {
+ try {
+ HttpResult result = queryGatewayService.queryJob(sql);
+ logger.info(result.getBody());
+ if(!result.getBody().contains("Error in SQL execution: Code: 394. DB::Exception: Query was cancelled. (QUERY_WAS_CANCELLED)")) {
+ throw new SQSException("Job not cancelled", ERROR.getCode());
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ });
+ thread.start();
+ thread.sleep(5000);
+ HttpResult process = queryGatewayService.queryJobProcess(queryId);
+ logger.info(process.getBody());
+ Assert.assertTrue(process.getBody().contains("elapsed"));
+ HttpResult httpResult = queryGatewayService.deleteJob(queryId);
+ Assert.assertTrue(httpResult.getCode() == HttpStatus.OK.value());
+ thread.checkAccess();
+ thread.join();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
}
diff --git a/src/test/resources/parameters/queryGatewayTest.json b/src/test/resources/parameters/queryGatewayTest.json
index fc36ed0..d4050b3 100644
--- a/src/test/resources/parameters/queryGatewayTest.json
+++ b/src/test/resources/parameters/queryGatewayTest.json
@@ -2,5 +2,7 @@
"querySqlSuccess": "select 1 from session_record limit 1",
"querySqlError": "select 1 from session_record_cn limit 1",
"queryForProcessIdError": "",
- "queryForCancelIdError": "1:1"
+ "queryForCancelIdError": "1:1",
+ "highLatencyQuerySuccess": "SELECT app,sleepEachRow(3) FROM traffic_sketch_metric LIMIT 100",
+ "highLatencyQueryCancel": "SELECT * FROM traffic_sketch_metric ORDER BY bytes DESC LIMIT 20"
}