This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new 073238cd2a Add unit tests for 6 more JDBC query DAOs (#13808)
073238cd2a is described below
commit 073238cd2ad2eaa1ecf948bbc2b04df3fe81e927
Author: Hyunjin-Jeong <[email protected]>
AuthorDate: Thu Apr 9 21:40:35 2026 +0900
Add unit tests for 6 more JDBC query DAOs (#13808)
---
.../common/dao/JDBCAggregationQueryDAOTest.java | 134 +++++++++++++++++++++
.../common/dao/JDBCEBPFProfilingDataDAOTest.java | 83 +++++++++++++
.../dao/JDBCEBPFProfilingScheduleDAOTest.java | 76 ++++++++++++
.../jdbc/common/dao/JDBCHierarchyQueryDAOTest.java | 93 ++++++++++++++
.../jdbc/common/dao/JDBCRecordsQueryDAOTest.java | 101 ++++++++++++++++
.../dao/JDBCTagAutoCompleteQueryDAOTest.java | 105 ++++++++++++++++
6 files changed, 592 insertions(+)
diff --git
a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCAggregationQueryDAOTest.java
b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCAggregationQueryDAOTest.java
new file mode 100644
index 0000000000..381d301238
--- /dev/null
+++
b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCAggregationQueryDAOTest.java
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.oap.server.storage.plugin.jdbc.common.dao;
+
+import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics;
+import org.apache.skywalking.oap.server.core.query.enumeration.Order;
+import org.apache.skywalking.oap.server.core.query.enumeration.Step;
+import org.apache.skywalking.oap.server.core.query.input.Duration;
+import org.apache.skywalking.oap.server.core.query.input.TopNCondition;
+import org.apache.skywalking.oap.server.core.query.type.KeyValue;
+import
org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCClient;
+import
org.apache.skywalking.oap.server.storage.plugin.jdbc.common.JDBCTableInstaller;
+import
org.apache.skywalking.oap.server.storage.plugin.jdbc.common.SQLAndParameters;
+import org.apache.skywalking.oap.server.storage.plugin.jdbc.common.TableHelper;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import java.util.Collections;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class JDBCAggregationQueryDAOTest {
+
+ private static final String TABLE = "metrics_table";
+
+ @Mock
+ private JDBCClient jdbcClient;
+ @Mock
+ private TableHelper tableHelper;
+
+ private JDBCAggregationQueryDAO dao;
+
+ @BeforeEach
+ void setUp() {
+ dao = new JDBCAggregationQueryDAO(jdbcClient, tableHelper);
+ }
+
+ private TopNCondition buildCondition(String name, int topN, Order order) {
+ final TopNCondition condition = new TopNCondition();
+ condition.setName(name);
+ condition.setTopN(topN);
+ condition.setOrder(order);
+ return condition;
+ }
+
+ private Duration buildDuration() {
+ final Duration duration = new Duration();
+ duration.setStart("2023-01-01 0000");
+ duration.setEnd("2023-01-02 0000");
+ duration.setStep(Step.MINUTE);
+ return duration;
+ }
+
+ @Test
+ void buildSQL_shouldContainTableColumnAndTimeBucketRange() {
+ final TopNCondition condition = buildCondition("service_resp_time",
10, Order.DES);
+ final Duration duration = buildDuration();
+
+ final SQLAndParameters result = dao.buildSQL(condition, "value",
duration, null, TABLE);
+
+ assertThat(result.sql()).contains(JDBCTableInstaller.TABLE_COLUMN + "
= ?");
+ assertThat(result.sql()).contains(Metrics.TIME_BUCKET + " >= ?");
+ assertThat(result.sql()).contains(Metrics.TIME_BUCKET + " <= ?");
+ }
+
+ @Test
+ void buildSQL_shouldContainSubqueryWithGroupBy() {
+ final TopNCondition condition = buildCondition("service_resp_time",
10, Order.DES);
+ final Duration duration = buildDuration();
+
+ final SQLAndParameters result = dao.buildSQL(condition, "value",
duration, null, TABLE);
+
+ assertThat(result.sql()).contains("avg(value) as result");
+ assertThat(result.sql()).contains("group by " + Metrics.ENTITY_ID);
+ assertThat(result.sql()).contains("as T order by result");
+ }
+
+ @Test
+ void buildSQL_withOrderDES_shouldContainDesc() {
+ final TopNCondition condition = buildCondition("service_resp_time", 5,
Order.DES);
+ final Duration duration = buildDuration();
+
+ final SQLAndParameters result = dao.buildSQL(condition, "value",
duration, null, TABLE);
+
+ assertThat(result.sql()).contains("order by result desc");
+ assertThat(result.sql()).contains("limit 5");
+ }
+
+ @Test
+ void buildSQL_withOrderASC_shouldContainAsc() {
+ final TopNCondition condition = buildCondition("service_resp_time", 5,
Order.ASC);
+ final Duration duration = buildDuration();
+
+ final SQLAndParameters result = dao.buildSQL(condition, "value",
duration, null, TABLE);
+
+ assertThat(result.sql()).contains("order by result asc");
+ }
+
+ @Test
+ void buildSQL_withAdditionalConditions_shouldAppendConditions() {
+ final TopNCondition condition = buildCondition("service_resp_time",
10, Order.DES);
+ final Duration duration = buildDuration();
+ final KeyValue kv = new KeyValue("service_id", "svc-1");
+
+ final SQLAndParameters result = dao.buildSQL(
+ condition, "value", duration, Collections.singletonList(kv),
TABLE);
+
+ assertThat(result.sql()).contains("service_id = ?");
+ assertThat(result.parameters()).contains("svc-1");
+ }
+}
diff --git
a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCEBPFProfilingDataDAOTest.java
b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCEBPFProfilingDataDAOTest.java
new file mode 100644
index 0000000000..9488ab4172
--- /dev/null
+++
b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCEBPFProfilingDataDAOTest.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.oap.server.storage.plugin.jdbc.common.dao;
+
+import
org.apache.skywalking.oap.server.core.profiling.ebpf.storage.EBPFProfilingDataRecord;
+import
org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCClient;
+import
org.apache.skywalking.oap.server.storage.plugin.jdbc.common.JDBCTableInstaller;
+import
org.apache.skywalking.oap.server.storage.plugin.jdbc.common.SQLAndParameters;
+import org.apache.skywalking.oap.server.storage.plugin.jdbc.common.TableHelper;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import java.util.Arrays;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class JDBCEBPFProfilingDataDAOTest {
+
+ private static final String TABLE = "ebpf_profiling_data";
+
+ @Mock
+ private JDBCClient jdbcClient;
+ @Mock
+ private TableHelper tableHelper;
+
+ private JDBCEBPFProfilingDataDAO dao;
+
+ @BeforeEach
+ void setUp() {
+ dao = new JDBCEBPFProfilingDataDAO(jdbcClient, tableHelper);
+ }
+
+ @Test
+ void buildSQL_shouldContainTableColumnCondition() {
+ final SQLAndParameters result = dao.buildSQL(
+ Arrays.asList("schedule-1"), 1000L, 2000L, TABLE);
+
+ assertThat(result.sql()).contains(JDBCTableInstaller.TABLE_COLUMN + "
= ?");
+
assertThat(result.parameters()).contains(EBPFProfilingDataRecord.INDEX_NAME);
+ }
+
+ @Test
+ void buildSQL_shouldContainScheduleIdInClause() {
+ final SQLAndParameters result = dao.buildSQL(
+ Arrays.asList("s1", "s2", "s3"), 1000L, 2000L, TABLE);
+
+ assertThat(result.sql()).contains(EBPFProfilingDataRecord.SCHEDULE_ID
+ " in (?, ?, ?)");
+ }
+
+ @Test
+ void buildSQL_shouldContainUploadTimeRange() {
+ final SQLAndParameters result = dao.buildSQL(
+ Arrays.asList("schedule-1"), 1000L, 2000L, TABLE);
+
+ assertThat(result.sql()).contains(EBPFProfilingDataRecord.UPLOAD_TIME
+ ">=?");
+ assertThat(result.sql()).contains(EBPFProfilingDataRecord.UPLOAD_TIME
+ "<?");
+ assertThat(result.parameters()).contains(1000L);
+ assertThat(result.parameters()).contains(2000L);
+ }
+}
diff --git
a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCEBPFProfilingScheduleDAOTest.java
b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCEBPFProfilingScheduleDAOTest.java
new file mode 100644
index 0000000000..ad07919a28
--- /dev/null
+++
b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCEBPFProfilingScheduleDAOTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.oap.server.storage.plugin.jdbc.common.dao;
+
+import
org.apache.skywalking.oap.server.core.profiling.ebpf.storage.EBPFProfilingScheduleRecord;
+import
org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCClient;
+import
org.apache.skywalking.oap.server.storage.plugin.jdbc.common.JDBCTableInstaller;
+import
org.apache.skywalking.oap.server.storage.plugin.jdbc.common.SQLAndParameters;
+import org.apache.skywalking.oap.server.storage.plugin.jdbc.common.TableHelper;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class JDBCEBPFProfilingScheduleDAOTest {
+
+ private static final String TABLE = "ebpf_profiling_schedule";
+
+ @Mock
+ private JDBCClient jdbcClient;
+ @Mock
+ private TableHelper tableHelper;
+
+ private JDBCEBPFProfilingScheduleDAO dao;
+
+ @BeforeEach
+ void setUp() {
+ dao = new JDBCEBPFProfilingScheduleDAO(jdbcClient, tableHelper);
+ }
+
+ @Test
+ void buildSQL_shouldContainTableColumnCondition() {
+ final SQLAndParameters result = dao.buildSQL("task-1", TABLE);
+
+ assertThat(result.sql()).contains(JDBCTableInstaller.TABLE_COLUMN + "
= ?");
+
assertThat(result.parameters()).contains(EBPFProfilingScheduleRecord.INDEX_NAME);
+ }
+
+ @Test
+ void buildSQL_shouldContainTaskIdCondition() {
+ final SQLAndParameters result = dao.buildSQL("task-abc", TABLE);
+
+ assertThat(result.sql()).contains(EBPFProfilingScheduleRecord.TASK_ID
+ "=?");
+ assertThat(result.parameters()).contains("task-abc");
+ }
+
+ @Test
+ void buildSQL_shouldContainWhereClause() {
+ final SQLAndParameters result = dao.buildSQL("task-1", TABLE);
+
+ assertThat(result.sql()).contains(" where ");
+ }
+}
diff --git
a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCHierarchyQueryDAOTest.java
b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCHierarchyQueryDAOTest.java
new file mode 100644
index 0000000000..269875fd27
--- /dev/null
+++
b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCHierarchyQueryDAOTest.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.oap.server.storage.plugin.jdbc.common.dao;
+
+import
org.apache.skywalking.oap.server.core.hierarchy.instance.InstanceHierarchyRelationTraffic;
+import
org.apache.skywalking.oap.server.core.hierarchy.service.ServiceHierarchyRelationTraffic;
+import
org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCClient;
+import
org.apache.skywalking.oap.server.storage.plugin.jdbc.common.JDBCTableInstaller;
+import
org.apache.skywalking.oap.server.storage.plugin.jdbc.common.SQLAndParameters;
+import org.apache.skywalking.oap.server.storage.plugin.jdbc.common.TableHelper;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class JDBCHierarchyQueryDAOTest {
+
+ private static final String TABLE = "hierarchy_table";
+
+ @Mock
+ private JDBCClient jdbcClient;
+ @Mock
+ private TableHelper tableHelper;
+
+ private JDBCHierarchyQueryDAO dao;
+
+ @BeforeEach
+ void setUp() {
+ dao = new JDBCHierarchyQueryDAO(jdbcClient, 100, tableHelper);
+ }
+
+ @Test
+ void buildSQLForReadAllServiceRelations_shouldContainTableColumnAndLimit()
{
+ final SQLAndParameters result =
dao.buildSQLForReadAllServiceRelations(TABLE);
+
+ assertThat(result.sql()).contains(JDBCTableInstaller.TABLE_COLUMN + "
= ?");
+
assertThat(result.parameters()).contains(ServiceHierarchyRelationTraffic.INDEX_NAME);
+ assertThat(result.sql()).contains("limit 200");
+ }
+
+ @Test
+ void
buildSQLForReadInstanceRelations_shouldContainBidirectionalCondition() {
+ final SQLAndParameters result =
dao.buildSQLForReadInstanceRelations(TABLE, "instance-1", 1);
+
+ assertThat(result.sql()).contains(JDBCTableInstaller.TABLE_COLUMN + "
= ?");
+
assertThat(result.sql()).contains(InstanceHierarchyRelationTraffic.INSTANCE_ID
+ "=?");
+
assertThat(result.sql()).contains(InstanceHierarchyRelationTraffic.SERVICE_LAYER
+ "=?");
+
assertThat(result.sql()).contains(InstanceHierarchyRelationTraffic.RELATED_INSTANCE_ID
+ "=?");
+
assertThat(result.sql()).contains(InstanceHierarchyRelationTraffic.RELATED_SERVICE_LAYER
+ "=?");
+ }
+
+ @Test
+ void buildSQLForReadInstanceRelations_shouldHaveOrBetweenDirections() {
+ final SQLAndParameters result =
dao.buildSQLForReadInstanceRelations(TABLE, "instance-1", 1);
+
+ assertThat(result.sql()).contains(") or (");
+ }
+
+ @Test
+ void buildSQLForReadInstanceRelations_shouldBindParametersCorrectly() {
+ final SQLAndParameters result =
dao.buildSQLForReadInstanceRelations(TABLE, "inst-abc", 3);
+
+ assertThat(result.parameters())
+ .containsExactly(
+ InstanceHierarchyRelationTraffic.INDEX_NAME,
+ "inst-abc", 3,
+ "inst-abc", 3
+ );
+ }
+}
diff --git
a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCRecordsQueryDAOTest.java
b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCRecordsQueryDAOTest.java
new file mode 100644
index 0000000000..1a64889175
--- /dev/null
+++
b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCRecordsQueryDAOTest.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.oap.server.storage.plugin.jdbc.common.dao;
+
+import org.apache.skywalking.oap.server.core.analysis.topn.TopN;
+import org.apache.skywalking.oap.server.core.query.enumeration.Order;
+import org.apache.skywalking.oap.server.core.query.enumeration.Scope;
+import org.apache.skywalking.oap.server.core.query.enumeration.Step;
+import org.apache.skywalking.oap.server.core.query.input.Duration;
+import org.apache.skywalking.oap.server.core.query.input.Entity;
+import org.apache.skywalking.oap.server.core.query.input.RecordCondition;
+import
org.apache.skywalking.oap.server.storage.plugin.jdbc.common.JDBCTableInstaller;
+import
org.apache.skywalking.oap.server.storage.plugin.jdbc.common.SQLAndParameters;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class JDBCRecordsQueryDAOTest {
+
+ private static final String TABLE = "records_table";
+
+ private Duration buildDuration() {
+ final Duration duration = new Duration();
+ duration.setStart("2023-01-01 0000");
+ duration.setEnd("2023-01-02 0000");
+ duration.setStep(Step.MINUTE);
+ return duration;
+ }
+
+ private RecordCondition buildCondition(String name, int topN, Order order)
{
+ final RecordCondition condition = new RecordCondition();
+ condition.setName(name);
+ condition.setTopN(topN);
+ condition.setOrder(order);
+ final Entity entity = new Entity();
+ entity.setScope(Scope.Service);
+ entity.setServiceName("test-service");
+ entity.setNormal(true);
+ condition.setParentEntity(entity);
+ return condition;
+ }
+
+ @Test
+ void buildSQL_shouldContainTableColumnCondition() {
+ final RecordCondition condition = buildCondition("top_n_db", 10,
Order.DES);
+ final Duration duration = buildDuration();
+
+ final SQLAndParameters result =
JDBCRecordsQueryDAO.buildSQL(condition, "value", duration, TABLE);
+
+ assertThat(result.sql()).contains(JDBCTableInstaller.TABLE_COLUMN + "
= ?");
+ }
+
+ @Test
+ void buildSQL_shouldContainEntityIdAndTimeBucket() {
+ final RecordCondition condition = buildCondition("top_n_db", 10,
Order.DES);
+ final Duration duration = buildDuration();
+
+ final SQLAndParameters result =
JDBCRecordsQueryDAO.buildSQL(condition, "value", duration, TABLE);
+
+ assertThat(result.sql()).contains(TopN.ENTITY_ID + " = ?");
+ assertThat(result.sql()).contains(TopN.TIME_BUCKET + " >= ?");
+ assertThat(result.sql()).contains(TopN.TIME_BUCKET + " <= ?");
+ }
+
+ @Test
+ void buildSQL_withOrderDES_shouldContainDesc() {
+ final RecordCondition condition = buildCondition("top_n_db", 5,
Order.DES);
+ final Duration duration = buildDuration();
+
+ final SQLAndParameters result =
JDBCRecordsQueryDAO.buildSQL(condition, "latency", duration, TABLE);
+
+ assertThat(result.sql()).contains("order by latency desc");
+ assertThat(result.sql()).contains("limit 5");
+ }
+
+ @Test
+ void buildSQL_withOrderASC_shouldContainAsc() {
+ final RecordCondition condition = buildCondition("top_n_db", 5,
Order.ASC);
+ final Duration duration = buildDuration();
+
+ final SQLAndParameters result =
JDBCRecordsQueryDAO.buildSQL(condition, "latency", duration, TABLE);
+
+ assertThat(result.sql()).contains("order by latency asc");
+ }
+}
diff --git
a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCTagAutoCompleteQueryDAOTest.java
b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCTagAutoCompleteQueryDAOTest.java
new file mode 100644
index 0000000000..d7b724d086
--- /dev/null
+++
b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCTagAutoCompleteQueryDAOTest.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.oap.server.storage.plugin.jdbc.common.dao;
+
+import
org.apache.skywalking.oap.server.core.analysis.manual.searchtag.TagAutocompleteData;
+import org.apache.skywalking.oap.server.core.analysis.manual.searchtag.TagType;
+import org.apache.skywalking.oap.server.core.query.enumeration.Step;
+import org.apache.skywalking.oap.server.core.query.input.Duration;
+import
org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCClient;
+import
org.apache.skywalking.oap.server.storage.plugin.jdbc.common.SQLAndParameters;
+import org.apache.skywalking.oap.server.storage.plugin.jdbc.common.TableHelper;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
+class JDBCTagAutoCompleteQueryDAOTest {
+
+ private static final String TABLE = "tag_autocomplete_table";
+
+ @Mock
+ private JDBCClient jdbcClient;
+ @Mock
+ private TableHelper tableHelper;
+
+ private JDBCTagAutoCompleteQueryDAO dao;
+
+ @BeforeEach
+ void setUp() {
+ dao = new JDBCTagAutoCompleteQueryDAO(jdbcClient, tableHelper);
+ }
+
+ private Duration buildDuration() {
+ final Duration duration = new Duration();
+ duration.setStart("2023-01-01 0000");
+ duration.setEnd("2023-01-02 0000");
+ duration.setStep(Step.MINUTE);
+ return duration;
+ }
+
+ @Test
+ void buildSQLForQueryKeys_shouldContainDistinctAndTagType() {
+ final Duration duration = buildDuration();
+
+ final SQLAndParameters result =
dao.buildSQLForQueryKeys(TagType.TRACE, 100, duration, TABLE);
+
+ assertThat(result.sql()).contains("select distinct " +
TagAutocompleteData.TAG_KEY);
+ assertThat(result.sql()).contains(TagAutocompleteData.TAG_TYPE + " =
?");
+ assertThat(result.parameters()).contains(TagType.TRACE.name());
+ }
+
+ @Test
+ void buildSQLForQueryKeys_shouldContainLimit() {
+ final Duration duration = buildDuration();
+
+ final SQLAndParameters result =
dao.buildSQLForQueryKeys(TagType.TRACE, 50, duration, TABLE);
+
+ assertThat(result.sql()).contains("limit 50");
+ }
+
+ @Test
+ void buildSQLForQueryValues_shouldContainTagKeyCondition() {
+ final Duration duration = buildDuration();
+
+ final SQLAndParameters result = dao.buildSQLForQueryValues(
+ TagType.TRACE, "http.method", 100, duration, TABLE);
+
+ assertThat(result.sql()).contains(TagAutocompleteData.TAG_KEY + " =
?");
+ assertThat(result.parameters()).contains("http.method");
+ }
+
+ @Test
+ void buildSQLForQueryValues_shouldContainTagTypeCondition() {
+ final Duration duration = buildDuration();
+
+ final SQLAndParameters result = dao.buildSQLForQueryValues(
+ TagType.LOG, "level", 100, duration, TABLE);
+
+ assertThat(result.sql()).contains(TagAutocompleteData.TAG_TYPE + " =
?");
+ assertThat(result.parameters()).contains(TagType.LOG.name());
+ }
+}