Skip to content

Commit 27309e1

Browse files
Use DistSQLDatabaseRuleQueryExecutorAssert in ShowReadwriteSplittingRuleExecutorTest (#34984)
* Use DistSQLDatabaseRuleQueryExecutorAssert in ShowShardingTableRulesUsedAuditorExecutorTest * Use DistSQLDatabaseRuleQueryExecutorAssert in ShowReadwriteSplittingRuleExecutorTest * fix spotless
1 parent 0055818 commit 27309e1

File tree

3 files changed

+62
-48
lines changed

3 files changed

+62
-48
lines changed

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

+10-48
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,35 @@
1818
package org.apache.shardingsphere.readwritesplitting.distsql.handler.query;
1919

2020
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
21-
import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
2221
import org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
2322
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
2423
import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes;
2524
import org.apache.shardingsphere.infra.rule.attribute.exportable.constant.ExportableConstants;
26-
import org.apache.shardingsphere.readwritesplitting.config.ReadwriteSplittingRuleConfiguration;
27-
import org.apache.shardingsphere.readwritesplitting.config.rule.ReadwriteSplittingDataSourceGroupRuleConfiguration;
28-
import org.apache.shardingsphere.readwritesplitting.distsql.statement.ShowReadwriteSplittingRulesStatement;
2925
import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
3026
import org.apache.shardingsphere.readwritesplitting.rule.attribute.ReadwriteSplittingExportableRuleAttribute;
31-
import org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLDatabaseRuleQueryExecutorTest;
32-
import org.apache.shardingsphere.test.util.PropertiesBuilder;
33-
import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
34-
import org.junit.jupiter.api.extension.ExtensionContext;
27+
import org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLDatabaseRuleQueryExecutorAssert;
28+
import org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorSettings;
29+
import org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorTestCaseArgumentsProvider;
3530
import org.junit.jupiter.params.ParameterizedTest;
36-
import org.junit.jupiter.params.provider.Arguments;
37-
import org.junit.jupiter.params.provider.ArgumentsProvider;
3831
import org.junit.jupiter.params.provider.ArgumentsSource;
3932

4033
import java.sql.SQLException;
41-
import java.util.Arrays;
4234
import java.util.Collection;
4335
import java.util.Collections;
4436
import java.util.HashMap;
4537
import java.util.Map;
46-
import java.util.stream.Stream;
4738

4839
import static org.mockito.Mockito.mock;
4940
import static org.mockito.Mockito.when;
5041

51-
class ShowReadwriteSplittingRuleExecutorTest extends DistSQLDatabaseRuleQueryExecutorTest {
42+
@DistSQLRuleQueryExecutorSettings("cases/show-readwrite-splitting-rule.xml")
43+
class ShowReadwriteSplittingRuleExecutorTest {
5244

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

5752
private static ReadwriteSplittingRule mockRule() {
@@ -67,37 +62,4 @@ private static Map<String, Object> createExportedData() {
6762
result.put(ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE, Collections.emptyMap());
6863
return result;
6964
}
70-
71-
@ParameterizedTest(name = "{0}")
72-
@ArgumentsSource(TestCaseArgumentsProvider.class)
73-
void assertExecuteQuery(final String name, final DatabaseRuleConfiguration ruleConfig, final DistSQLStatement sqlStatement,
74-
final Collection<LocalDataQueryResultRow> expected) throws SQLException {
75-
assertQueryResultRows(ruleConfig, sqlStatement, expected);
76-
}
77-
78-
private static class TestCaseArgumentsProvider implements ArgumentsProvider {
79-
80-
@Override
81-
public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
82-
return Stream.of(Arguments.arguments("withNull", createRuleConfiguration(), new ShowReadwriteSplittingRulesStatement(null, null),
83-
Collections.singleton(new LocalDataQueryResultRow("readwrite_ds", "ds_primary", "ds_slave_0,ds_slave_1", "DYNAMIC", "random", "{\"read_weight\":\"2:1\"}"))),
84-
Arguments.arguments("withSpecifiedRuleName", createRuleConfiguration(), new ShowReadwriteSplittingRulesStatement("readwrite_ds", null),
85-
Collections.singleton(new LocalDataQueryResultRow("readwrite_ds", "ds_primary", "ds_slave_0,ds_slave_1", "DYNAMIC", "random", "{\"read_weight\":\"2:1\"}"))),
86-
Arguments.arguments("withoutLoadBalancer", createRuleConfigurationWithoutLoadBalancer(), new ShowReadwriteSplittingRulesStatement("readwrite_ds", null),
87-
Collections.singleton(new LocalDataQueryResultRow("readwrite_ds", "write_ds", "read_ds_0,read_ds_1", "DYNAMIC", "", ""))));
88-
}
89-
90-
private ReadwriteSplittingRuleConfiguration createRuleConfiguration() {
91-
ReadwriteSplittingDataSourceGroupRuleConfiguration dataSourceGroupConfig =
92-
new ReadwriteSplittingDataSourceGroupRuleConfiguration("readwrite_ds", "ds_primary", Arrays.asList("ds_slave_0", "ds_slave_1"), "test");
93-
return new ReadwriteSplittingRuleConfiguration(
94-
Collections.singleton(dataSourceGroupConfig), Collections.singletonMap("test", new AlgorithmConfiguration("random", PropertiesBuilder.build(new Property("read_weight", "2:1")))));
95-
}
96-
97-
private ReadwriteSplittingRuleConfiguration createRuleConfigurationWithoutLoadBalancer() {
98-
ReadwriteSplittingDataSourceGroupRuleConfiguration dataSourceGroupConfig =
99-
new ReadwriteSplittingDataSourceGroupRuleConfiguration("readwrite_ds", "write_ds", Arrays.asList("read_ds_0", "read_ds_1"), null);
100-
return new ReadwriteSplittingRuleConfiguration(Collections.singleton(dataSourceGroupConfig), null);
101-
}
102-
}
10365
}
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,27 @@
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 READWRITE_SPLITTING RULES" current-rule-config-yaml-file="cases/show-readwrite-splitting-rule-current-config.yaml">
21+
<expected-query-result-rows>
22+
<expected-query-result-row>
23+
readwrite_ds|write_ds|read_ds_0,read_ds_1|DYNAMIC||
24+
</expected-query-result-row>
25+
</expected-query-result-rows>
26+
</test-case>
27+
</distsql-rule-query-executor-test-cases>

0 commit comments

Comments
 (0)