Skip to content

Commit 40b6b79

Browse files
Use DistSQLDatabaseRuleQueryExecutorAssert in ShowStatusFromReadwriteSplittingRulesExecutorTest (#34997)
* Use DistSQLDatabaseRuleQueryExecutorAssert in ShowShardingTableRulesUsedAuditorExecutorTest * Use DistSQLDatabaseRuleQueryExecutorAssert in ShowStatusFromReadwriteSplittingRulesExecutorTest
1 parent 5ccac8b commit 40b6b79

File tree

3 files changed

+66
-29
lines changed

3 files changed

+66
-29
lines changed

features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowStatusFromReadwriteSplittingRulesExecutorTest.java

+11-29
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,37 @@
2020
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
2121
import org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
2222
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
23-
import org.apache.shardingsphere.readwritesplitting.config.ReadwriteSplittingRuleConfiguration;
24-
import org.apache.shardingsphere.readwritesplitting.distsql.statement.ShowStatusFromReadwriteSplittingRulesStatement;
2523
import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceGroupRule;
2624
import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
27-
import org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLDatabaseRuleQueryExecutorTest;
28-
import org.junit.jupiter.api.extension.ExtensionContext;
25+
import org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLDatabaseRuleQueryExecutorAssert;
26+
import org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorSettings;
27+
import org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorTestCaseArgumentsProvider;
2928
import org.junit.jupiter.params.ParameterizedTest;
30-
import org.junit.jupiter.params.provider.Arguments;
31-
import org.junit.jupiter.params.provider.ArgumentsProvider;
3229
import org.junit.jupiter.params.provider.ArgumentsSource;
3330

3431
import java.sql.SQLException;
3532
import java.util.Arrays;
3633
import java.util.Collection;
3734
import java.util.Collections;
3835
import java.util.Map;
39-
import java.util.stream.Stream;
4036

4137
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
4238
import static org.mockito.Mockito.mock;
4339
import static org.mockito.Mockito.when;
4440

45-
class ShowStatusFromReadwriteSplittingRulesExecutorTest extends DistSQLDatabaseRuleQueryExecutorTest {
41+
@DistSQLRuleQueryExecutorSettings("cases/show-status-from-readwrite-splitting-rules.xml")
42+
class ShowStatusFromReadwriteSplittingRulesExecutorTest {
4643

47-
ShowStatusFromReadwriteSplittingRulesExecutorTest() {
48-
super(mockRule());
44+
@ParameterizedTest(name = "DistSQL -> {0}")
45+
@ArgumentsSource(DistSQLRuleQueryExecutorTestCaseArgumentsProvider.class)
46+
void assertExecuteQuery(@SuppressWarnings("unused") final String distSQL, final DistSQLStatement sqlStatement,
47+
final DatabaseRuleConfiguration currentRuleConfig, final Collection<LocalDataQueryResultRow> expected) throws SQLException {
48+
new DistSQLDatabaseRuleQueryExecutorAssert(mockRule()).assertQueryResultRows(currentRuleConfig, sqlStatement, expected);
4949
}
5050

5151
private static ReadwriteSplittingRule mockRule() {
5252
ReadwriteSplittingRule result = mock(ReadwriteSplittingRule.class);
53-
Map<String, ReadwriteSplittingDataSourceGroupRule> dataSourceGroupRules = Collections.singletonMap("group_0", mockDataSourceGroupRule());
53+
Map<String, ReadwriteSplittingDataSourceGroupRule> dataSourceGroupRules = Collections.singletonMap("readwrite_ds", mockDataSourceGroupRule());
5454
when(result.getDataSourceRuleGroups()).thenReturn(dataSourceGroupRules);
5555
return result;
5656
}
@@ -62,22 +62,4 @@ private static ReadwriteSplittingDataSourceGroupRule mockDataSourceGroupRule() {
6262
when(result.getDisabledDataSourceNames()).thenReturn(Collections.singleton("read_ds_1"));
6363
return result;
6464
}
65-
66-
@ParameterizedTest(name = "{0}")
67-
@ArgumentsSource(TestCaseArgumentsProvider.class)
68-
void assertExecuteQuery(final String name, final DatabaseRuleConfiguration ruleConfig, final DistSQLStatement sqlStatement,
69-
final Collection<LocalDataQueryResultRow> expected) throws SQLException {
70-
assertQueryResultRows(ruleConfig, sqlStatement, expected);
71-
}
72-
73-
private static class TestCaseArgumentsProvider implements ArgumentsProvider {
74-
75-
@Override
76-
public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
77-
return Stream.of(Arguments.arguments("withoutRuleName", mock(ReadwriteSplittingRuleConfiguration.class), new ShowStatusFromReadwriteSplittingRulesStatement(null, null),
78-
Arrays.asList(new LocalDataQueryResultRow("read_ds_0", "ENABLED"), new LocalDataQueryResultRow("read_ds_1", "DISABLED"))),
79-
Arguments.arguments("withRuleName", mock(ReadwriteSplittingRuleConfiguration.class), new ShowStatusFromReadwriteSplittingRulesStatement(null, "bar_rule"),
80-
Collections.emptyList()));
81-
}
82-
}
8365
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
rules:
19+
- !READWRITE_SPLITTING
20+
dataSourceGroups:
21+
readwrite_ds:
22+
writeDataSourceName: write_ds
23+
readDataSourceNames:
24+
- read_ds_0
25+
- read_ds_1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to You under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
19+
<distsql-rule-query-executor-test-cases>
20+
<test-case dist-sql="SHOW STATUS FROM READWRITE_SPLITTING RULES" current-rule-config-yaml-file="cases/show-status-from-readwrite-splitting-rules-current-config.yaml">
21+
<expected-query-result-rows>
22+
<expected-query-result-row>
23+
read_ds_0|ENABLED
24+
</expected-query-result-row>
25+
<expected-query-result-row>
26+
read_ds_1|DISABLED
27+
</expected-query-result-row>
28+
</expected-query-result-rows>
29+
</test-case>
30+
</distsql-rule-query-executor-test-cases>

0 commit comments

Comments
 (0)