Skip to content

Commit f6c8f6c

Browse files
authored
Merge branch 'master' into fix/update-infra-e2e-distinct-contains
2 parents 3bc9e5c + 5e9b9e2 commit f6c8f6c

8 files changed

Lines changed: 799 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.apache.skywalking.oap.server.storage.plugin.jdbc.common.dao;
20+
21+
import org.apache.skywalking.oap.server.core.profiling.asyncprofiler.storage.AsyncProfilerTaskLogRecord;
22+
import org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCClient;
23+
import org.apache.skywalking.oap.server.storage.plugin.jdbc.common.JDBCTableInstaller;
24+
import org.apache.skywalking.oap.server.storage.plugin.jdbc.common.TableHelper;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.extension.ExtendWith;
28+
import org.mockito.Mock;
29+
import org.mockito.junit.jupiter.MockitoExtension;
30+
import org.mockito.junit.jupiter.MockitoSettings;
31+
import org.mockito.quality.Strictness;
32+
33+
import java.util.ArrayList;
34+
import java.util.Collections;
35+
import java.util.concurrent.atomic.AtomicReference;
36+
37+
import static org.assertj.core.api.Assertions.assertThat;
38+
import static org.mockito.ArgumentMatchers.any;
39+
import static org.mockito.ArgumentMatchers.anyString;
40+
import static org.mockito.Mockito.doAnswer;
41+
import static org.mockito.Mockito.when;
42+
43+
@ExtendWith(MockitoExtension.class)
44+
@MockitoSettings(strictness = Strictness.LENIENT)
45+
class JDBCAsyncProfilerTaskLogQueryDAOTest {
46+
47+
@Mock
48+
private JDBCClient jdbcClient;
49+
@Mock
50+
private TableHelper tableHelper;
51+
52+
private JDBCAsyncProfilerTaskLogQueryDAO dao;
53+
54+
@BeforeEach
55+
void setUp() {
56+
dao = new JDBCAsyncProfilerTaskLogQueryDAO(jdbcClient, tableHelper);
57+
}
58+
59+
@Test
60+
void getTaskLogList_shouldContainTableColumnAndTaskIdFilter() throws Exception {
61+
when(tableHelper.getTablesWithinTTL(AsyncProfilerTaskLogRecord.INDEX_NAME))
62+
.thenReturn(Collections.singletonList("async_profiler_task_log"));
63+
64+
final AtomicReference<String> capturedSql = new AtomicReference<>();
65+
doAnswer(invocation -> {
66+
capturedSql.set(invocation.getArgument(0));
67+
return new ArrayList<>();
68+
}).when(jdbcClient).executeQuery(anyString(), any(), any(Object[].class));
69+
70+
dao.getTaskLogList("task-123");
71+
72+
assertThat(capturedSql.get()).contains(JDBCTableInstaller.TABLE_COLUMN + " = ?");
73+
assertThat(capturedSql.get()).contains(AsyncProfilerTaskLogRecord.TASK_ID + " = ?");
74+
}
75+
76+
@Test
77+
void getTaskLogList_shouldContainOrderByOperationTimeDesc() throws Exception {
78+
when(tableHelper.getTablesWithinTTL(AsyncProfilerTaskLogRecord.INDEX_NAME))
79+
.thenReturn(Collections.singletonList("async_profiler_task_log"));
80+
81+
final AtomicReference<String> capturedSql = new AtomicReference<>();
82+
doAnswer(invocation -> {
83+
capturedSql.set(invocation.getArgument(0));
84+
return new ArrayList<>();
85+
}).when(jdbcClient).executeQuery(anyString(), any(), any(Object[].class));
86+
87+
dao.getTaskLogList("task-1");
88+
89+
assertThat(capturedSql.get()).contains("order by " + AsyncProfilerTaskLogRecord.OPERATION_TIME + " desc");
90+
}
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.apache.skywalking.oap.server.storage.plugin.jdbc.common.dao;
20+
21+
import org.apache.skywalking.oap.server.core.profiling.asyncprofiler.storage.AsyncProfilerTaskRecord;
22+
import org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCClient;
23+
import org.apache.skywalking.oap.server.storage.plugin.jdbc.common.JDBCTableInstaller;
24+
import org.apache.skywalking.oap.server.storage.plugin.jdbc.common.TableHelper;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.extension.ExtendWith;
28+
import org.mockito.Mock;
29+
import org.mockito.junit.jupiter.MockitoExtension;
30+
import org.mockito.junit.jupiter.MockitoSettings;
31+
import org.mockito.quality.Strictness;
32+
33+
import java.util.ArrayList;
34+
import java.util.Collections;
35+
import java.util.concurrent.atomic.AtomicReference;
36+
37+
import static org.assertj.core.api.Assertions.assertThat;
38+
import static org.mockito.ArgumentMatchers.any;
39+
import static org.mockito.ArgumentMatchers.anyString;
40+
import static org.mockito.Mockito.doAnswer;
41+
import static org.mockito.Mockito.when;
42+
43+
@ExtendWith(MockitoExtension.class)
44+
@MockitoSettings(strictness = Strictness.LENIENT)
45+
class JDBCAsyncProfilerTaskQueryDAOTest {
46+
47+
@Mock
48+
private JDBCClient jdbcClient;
49+
@Mock
50+
private TableHelper tableHelper;
51+
52+
private JDBCAsyncProfilerTaskQueryDAO dao;
53+
54+
@BeforeEach
55+
void setUp() {
56+
dao = new JDBCAsyncProfilerTaskQueryDAO(jdbcClient, tableHelper);
57+
}
58+
59+
@Test
60+
void getTaskList_withServiceId_shouldIncludeServiceIdFilter() throws Exception {
61+
when(tableHelper.getTablesWithinTTL(AsyncProfilerTaskRecord.INDEX_NAME))
62+
.thenReturn(Collections.singletonList("async_profiler_task"));
63+
64+
final AtomicReference<String> capturedSql = new AtomicReference<>();
65+
doAnswer(invocation -> {
66+
capturedSql.set(invocation.getArgument(0));
67+
return new ArrayList<>();
68+
}).when(jdbcClient).executeQuery(anyString(), any(), any(Object[].class));
69+
70+
dao.getTaskList("service-1", null, null, null);
71+
72+
assertThat(capturedSql.get()).contains(JDBCTableInstaller.TABLE_COLUMN + " = ?");
73+
assertThat(capturedSql.get()).contains(AsyncProfilerTaskRecord.SERVICE_ID + "=?");
74+
}
75+
76+
@Test
77+
void getTaskList_withoutServiceId_shouldNotIncludeServiceIdFilter() throws Exception {
78+
when(tableHelper.getTablesWithinTTL(AsyncProfilerTaskRecord.INDEX_NAME))
79+
.thenReturn(Collections.singletonList("async_profiler_task"));
80+
81+
final AtomicReference<String> capturedSql = new AtomicReference<>();
82+
doAnswer(invocation -> {
83+
capturedSql.set(invocation.getArgument(0));
84+
return new ArrayList<>();
85+
}).when(jdbcClient).executeQuery(anyString(), any(), any(Object[].class));
86+
87+
dao.getTaskList(null, null, null, null);
88+
89+
assertThat(capturedSql.get()).doesNotContain(AsyncProfilerTaskRecord.SERVICE_ID);
90+
}
91+
92+
@Test
93+
void getTaskList_shouldAlwaysOrderByCreateTimeDesc() throws Exception {
94+
when(tableHelper.getTablesWithinTTL(AsyncProfilerTaskRecord.INDEX_NAME))
95+
.thenReturn(Collections.singletonList("async_profiler_task"));
96+
97+
final AtomicReference<String> capturedSql = new AtomicReference<>();
98+
doAnswer(invocation -> {
99+
capturedSql.set(invocation.getArgument(0));
100+
return new ArrayList<>();
101+
}).when(jdbcClient).executeQuery(anyString(), any(), any(Object[].class));
102+
103+
dao.getTaskList(null, null, null, null);
104+
105+
assertThat(capturedSql.get()).contains("ORDER BY " + AsyncProfilerTaskRecord.CREATE_TIME + " DESC");
106+
}
107+
108+
@Test
109+
void getTaskList_withLimit_shouldIncludeLimitClause() throws Exception {
110+
when(tableHelper.getTablesWithinTTL(AsyncProfilerTaskRecord.INDEX_NAME))
111+
.thenReturn(Collections.singletonList("async_profiler_task"));
112+
113+
final AtomicReference<String> capturedSql = new AtomicReference<>();
114+
doAnswer(invocation -> {
115+
capturedSql.set(invocation.getArgument(0));
116+
return new ArrayList<>();
117+
}).when(jdbcClient).executeQuery(anyString(), any(), any(Object[].class));
118+
119+
dao.getTaskList(null, null, null, 10);
120+
121+
assertThat(capturedSql.get()).contains("LIMIT 10");
122+
}
123+
124+
@Test
125+
void getById_shouldContainTableColumnAndTaskIdWithLimit() throws Exception {
126+
when(tableHelper.getTablesWithinTTL(AsyncProfilerTaskRecord.INDEX_NAME))
127+
.thenReturn(Collections.singletonList("async_profiler_task"));
128+
129+
final AtomicReference<String> capturedSql = new AtomicReference<>();
130+
doAnswer(invocation -> {
131+
capturedSql.set(invocation.getArgument(0));
132+
return null;
133+
}).when(jdbcClient).executeQuery(anyString(), any(), any(Object[].class));
134+
135+
dao.getById("task-id-1");
136+
137+
assertThat(capturedSql.get()).contains(JDBCTableInstaller.TABLE_COLUMN + " = ?");
138+
assertThat(capturedSql.get()).contains(AsyncProfilerTaskRecord.TASK_ID + "=?");
139+
assertThat(capturedSql.get()).contains("LIMIT 1");
140+
}
141+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.apache.skywalking.oap.server.storage.plugin.jdbc.common.dao;
20+
21+
import org.apache.skywalking.oap.server.core.profiling.continuous.storage.ContinuousProfilingPolicy;
22+
import org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCClient;
23+
import org.apache.skywalking.oap.server.storage.plugin.jdbc.common.JDBCTableInstaller;
24+
import org.apache.skywalking.oap.server.storage.plugin.jdbc.common.TableHelper;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.extension.ExtendWith;
28+
import org.mockito.Mock;
29+
import org.mockito.junit.jupiter.MockitoExtension;
30+
import org.mockito.junit.jupiter.MockitoSettings;
31+
import org.mockito.quality.Strictness;
32+
33+
import java.util.ArrayList;
34+
import java.util.Arrays;
35+
import java.util.Collections;
36+
import java.util.concurrent.atomic.AtomicReference;
37+
38+
import static org.assertj.core.api.Assertions.assertThat;
39+
import static org.mockito.ArgumentMatchers.any;
40+
import static org.mockito.ArgumentMatchers.anyString;
41+
import static org.mockito.Mockito.doAnswer;
42+
import static org.mockito.Mockito.when;
43+
44+
@ExtendWith(MockitoExtension.class)
45+
@MockitoSettings(strictness = Strictness.LENIENT)
46+
class JDBCContinuousProfilingPolicyDAOTest {
47+
48+
@Mock
49+
private JDBCClient jdbcClient;
50+
@Mock
51+
private TableHelper tableHelper;
52+
53+
private JDBCContinuousProfilingPolicyDAO dao;
54+
55+
@BeforeEach
56+
void setUp() {
57+
dao = new JDBCContinuousProfilingPolicyDAO(jdbcClient, tableHelper);
58+
}
59+
60+
@Test
61+
void queryPolicies_shouldContainTableColumnAndServiceIdInClause() throws Exception {
62+
when(tableHelper.getTablesWithinTTL(ContinuousProfilingPolicy.INDEX_NAME))
63+
.thenReturn(Collections.singletonList("continuous_profiling_policy"));
64+
65+
final AtomicReference<String> capturedSql = new AtomicReference<>();
66+
doAnswer(invocation -> {
67+
capturedSql.set(invocation.getArgument(0));
68+
return new ArrayList<>();
69+
}).when(jdbcClient).executeQuery(anyString(), any(), any(Object[].class));
70+
71+
dao.queryPolicies(Arrays.asList("svc-1", "svc-2"));
72+
73+
assertThat(capturedSql.get()).contains(JDBCTableInstaller.TABLE_COLUMN + " = ?");
74+
assertThat(capturedSql.get()).contains(ContinuousProfilingPolicy.SERVICE_ID + " in (?,?)");
75+
}
76+
77+
@Test
78+
void queryPolicies_withSingleServiceId_shouldContainSinglePlaceholder() throws Exception {
79+
when(tableHelper.getTablesWithinTTL(ContinuousProfilingPolicy.INDEX_NAME))
80+
.thenReturn(Collections.singletonList("continuous_profiling_policy"));
81+
82+
final AtomicReference<String> capturedSql = new AtomicReference<>();
83+
doAnswer(invocation -> {
84+
capturedSql.set(invocation.getArgument(0));
85+
return new ArrayList<>();
86+
}).when(jdbcClient).executeQuery(anyString(), any(), any(Object[].class));
87+
88+
dao.queryPolicies(Collections.singletonList("svc-1"));
89+
90+
assertThat(capturedSql.get()).contains(ContinuousProfilingPolicy.SERVICE_ID + " in (?)");
91+
}
92+
}

0 commit comments

Comments
 (0)