mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 19:51:00 +00:00
(improvement)(test) Fixed the intermittent failure of QueryByStructTest on Windows. (#1159)
This commit is contained in:
@@ -19,6 +19,7 @@ public class SemanticQueryResp extends QueryResult<Map<String, Object>> {
|
||||
List<QueryColumn> columns = Lists.newArrayList();
|
||||
String sql;
|
||||
QueryAuthorization queryAuthorization;
|
||||
boolean useCache;
|
||||
|
||||
public List<QueryColumn> getMetricColumns() {
|
||||
return columns.stream()
|
||||
|
||||
@@ -97,7 +97,9 @@ public class QueryServiceImpl implements QueryService {
|
||||
String cacheKey = queryCache.getCacheKey(queryReq);
|
||||
Object query = queryCache.query(queryReq, cacheKey);
|
||||
if (Objects.nonNull(query)) {
|
||||
return (SemanticQueryResp) query;
|
||||
SemanticQueryResp queryResp = (SemanticQueryResp) query;
|
||||
queryResp.setUseCache(true);
|
||||
return queryResp;
|
||||
}
|
||||
StatUtils.get().setUseResultCache(false);
|
||||
//3 query
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package com.tencent.supersonic.headless;
|
||||
|
||||
import static java.time.LocalDate.now;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.common.pojo.QueryColumn;
|
||||
import com.tencent.supersonic.common.pojo.exception.InvalidPermissionException;
|
||||
@@ -8,10 +13,6 @@ import com.tencent.supersonic.util.DataUtils;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static java.time.LocalDate.now;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
public class QueryBySqlTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
@@ -74,9 +75,9 @@ public class QueryBySqlTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
public void testCacheQuery() throws Exception {
|
||||
SemanticQueryResp result1 = queryBySql("SELECT 部门, SUM(访问次数) AS 访问次数 FROM 超音数PVUV统计 GROUP BY 部门 ");
|
||||
queryBySql("SELECT 部门, SUM(访问次数) AS 访问次数 FROM 超音数PVUV统计 GROUP BY 部门 ");
|
||||
SemanticQueryResp result2 = queryBySql("SELECT 部门, SUM(访问次数) AS 访问次数 FROM 超音数PVUV统计 GROUP BY 部门 ");
|
||||
assertTrue(result1 == result2);
|
||||
assertTrue(result2.isUseCache());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package com.tencent.supersonic.headless;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||
import com.tencent.supersonic.common.pojo.Aggregator;
|
||||
import com.tencent.supersonic.common.pojo.Filter;
|
||||
@@ -11,19 +16,27 @@ import com.tencent.supersonic.common.pojo.exception.InvalidPermissionException;
|
||||
import com.tencent.supersonic.headless.api.pojo.request.QueryStructReq;
|
||||
import com.tencent.supersonic.headless.api.pojo.response.SemanticQueryResp;
|
||||
import com.tencent.supersonic.util.DataUtils;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@Slf4j
|
||||
public class QueryByStructTest extends BaseTest {
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
public void testCacheQuery() throws Exception {
|
||||
QueryStructReq queryStructReq1 = buildQueryStructReq(Arrays.asList("department"));
|
||||
QueryStructReq queryStructReq2 = buildQueryStructReq(Arrays.asList("department"));
|
||||
queryService.queryByReq(queryStructReq1, User.getFakeUser());
|
||||
SemanticQueryResp result2 = queryService.queryByReq(queryStructReq2, User.getFakeUser());
|
||||
assertTrue(result2.isUseCache());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetailQuery() throws Exception {
|
||||
QueryStructReq queryStructReq = buildQueryStructReq(Arrays.asList("user_name", "department"),
|
||||
@@ -83,15 +96,6 @@ public class QueryByStructTest extends BaseTest {
|
||||
assertEquals("HR", result.getResultList().get(0).get("department").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheQuery() throws Exception {
|
||||
QueryStructReq queryStructReq1 = buildQueryStructReq(Arrays.asList("department"));
|
||||
QueryStructReq queryStructReq2 = buildQueryStructReq(Arrays.asList("department"));
|
||||
SemanticQueryResp result1 = queryService.queryByReq(queryStructReq1, User.getFakeUser());
|
||||
SemanticQueryResp result2 = queryService.queryByReq(queryStructReq2, User.getFakeUser());
|
||||
assertTrue(result1 == result2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthorization_model() {
|
||||
User alice = new User(2L, "alice", "alice", "alice@email", 0);
|
||||
|
||||
Reference in New Issue
Block a user