This is an automated email from the ASF dual-hosted git repository.
yx9o pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 27309e1f4ea Use DistSQLDatabaseRuleQueryExecutorAssert in
ShowReadwriteSplittingRuleExecutorTest (#34984)
27309e1f4ea is described below
commit 27309e1f4eadac7a40c266048a23471b58533675
Author: ilyas ahsan <[email protected]>
AuthorDate: Fri Mar 14 11:04:49 2025 +0700
Use DistSQLDatabaseRuleQueryExecutorAssert in
ShowReadwriteSplittingRuleExecutorTest (#34984)
* Use DistSQLDatabaseRuleQueryExecutorAssert in
ShowShardingTableRulesUsedAuditorExecutorTest
* Use DistSQLDatabaseRuleQueryExecutorAssert in
ShowReadwriteSplittingRuleExecutorTest
* fix spotless
---
.../ShowReadwriteSplittingRuleExecutorTest.java | 58 ++++------------------
...ow-readwrite-splitting-rule-current-config.yaml | 25 ++++++++++
.../cases/show-readwrite-splitting-rule.xml | 27 ++++++++++
3 files changed, 62 insertions(+), 48 deletions(-)
diff --git
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java
index a88d44e4170..b5f48ed61a0 100644
---
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java
+++
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadwriteSplittingRuleExecutorTest.java
@@ -18,40 +18,35 @@
package org.apache.shardingsphere.readwritesplitting.distsql.handler.query;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
-import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes;
import
org.apache.shardingsphere.infra.rule.attribute.exportable.constant.ExportableConstants;
-import
org.apache.shardingsphere.readwritesplitting.config.ReadwriteSplittingRuleConfiguration;
-import
org.apache.shardingsphere.readwritesplitting.config.rule.ReadwriteSplittingDataSourceGroupRuleConfiguration;
-import
org.apache.shardingsphere.readwritesplitting.distsql.statement.ShowReadwriteSplittingRulesStatement;
import
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
import
org.apache.shardingsphere.readwritesplitting.rule.attribute.ReadwriteSplittingExportableRuleAttribute;
-import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLDatabaseRuleQueryExecutorTest;
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.junit.jupiter.api.extension.ExtensionContext;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLDatabaseRuleQueryExecutorAssert;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorSettings;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorTestCaseArgumentsProvider;
import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import java.sql.SQLException;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import java.util.stream.Stream;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-class ShowReadwriteSplittingRuleExecutorTest extends
DistSQLDatabaseRuleQueryExecutorTest {
+@DistSQLRuleQueryExecutorSettings("cases/show-readwrite-splitting-rule.xml")
+class ShowReadwriteSplittingRuleExecutorTest {
- ShowReadwriteSplittingRuleExecutorTest() {
- super(mockRule());
+ @ParameterizedTest(name = "DistSQL -> {0}")
+ @ArgumentsSource(DistSQLRuleQueryExecutorTestCaseArgumentsProvider.class)
+ void assertExecuteQuery(@SuppressWarnings("unused") final String distSQL,
final DistSQLStatement sqlStatement,
+ final DatabaseRuleConfiguration currentRuleConfig,
final Collection<LocalDataQueryResultRow> expected) throws SQLException {
+ new
DistSQLDatabaseRuleQueryExecutorAssert(mockRule()).assertQueryResultRows(currentRuleConfig,
sqlStatement, expected);
}
private static ReadwriteSplittingRule mockRule() {
@@ -67,37 +62,4 @@ class ShowReadwriteSplittingRuleExecutorTest extends
DistSQLDatabaseRuleQueryExe
result.put(ExportableConstants.EXPORT_STATIC_READWRITE_SPLITTING_RULE,
Collections.emptyMap());
return result;
}
-
- @ParameterizedTest(name = "{0}")
- @ArgumentsSource(TestCaseArgumentsProvider.class)
- void assertExecuteQuery(final String name, final DatabaseRuleConfiguration
ruleConfig, final DistSQLStatement sqlStatement,
- final Collection<LocalDataQueryResultRow>
expected) throws SQLException {
- assertQueryResultRows(ruleConfig, sqlStatement, expected);
- }
-
- private static class TestCaseArgumentsProvider implements
ArgumentsProvider {
-
- @Override
- public Stream<? extends Arguments> provideArguments(final
ExtensionContext extensionContext) {
- return Stream.of(Arguments.arguments("withNull",
createRuleConfiguration(), new ShowReadwriteSplittingRulesStatement(null, null),
- Collections.singleton(new
LocalDataQueryResultRow("readwrite_ds", "ds_primary", "ds_slave_0,ds_slave_1",
"DYNAMIC", "random", "{\"read_weight\":\"2:1\"}"))),
- Arguments.arguments("withSpecifiedRuleName",
createRuleConfiguration(), new
ShowReadwriteSplittingRulesStatement("readwrite_ds", null),
- Collections.singleton(new
LocalDataQueryResultRow("readwrite_ds", "ds_primary", "ds_slave_0,ds_slave_1",
"DYNAMIC", "random", "{\"read_weight\":\"2:1\"}"))),
- Arguments.arguments("withoutLoadBalancer",
createRuleConfigurationWithoutLoadBalancer(), new
ShowReadwriteSplittingRulesStatement("readwrite_ds", null),
- Collections.singleton(new
LocalDataQueryResultRow("readwrite_ds", "write_ds", "read_ds_0,read_ds_1",
"DYNAMIC", "", ""))));
- }
-
- private ReadwriteSplittingRuleConfiguration createRuleConfiguration() {
- ReadwriteSplittingDataSourceGroupRuleConfiguration
dataSourceGroupConfig =
- new
ReadwriteSplittingDataSourceGroupRuleConfiguration("readwrite_ds",
"ds_primary", Arrays.asList("ds_slave_0", "ds_slave_1"), "test");
- return new ReadwriteSplittingRuleConfiguration(
- Collections.singleton(dataSourceGroupConfig),
Collections.singletonMap("test", new AlgorithmConfiguration("random",
PropertiesBuilder.build(new Property("read_weight", "2:1")))));
- }
-
- private ReadwriteSplittingRuleConfiguration
createRuleConfigurationWithoutLoadBalancer() {
- ReadwriteSplittingDataSourceGroupRuleConfiguration
dataSourceGroupConfig =
- new
ReadwriteSplittingDataSourceGroupRuleConfiguration("readwrite_ds", "write_ds",
Arrays.asList("read_ds_0", "read_ds_1"), null);
- return new
ReadwriteSplittingRuleConfiguration(Collections.singleton(dataSourceGroupConfig),
null);
- }
- }
}
diff --git
a/features/readwrite-splitting/distsql/handler/src/test/resources/cases/show-readwrite-splitting-rule-current-config.yaml
b/features/readwrite-splitting/distsql/handler/src/test/resources/cases/show-readwrite-splitting-rule-current-config.yaml
new file mode 100644
index 00000000000..ea0c6837e6e
--- /dev/null
+++
b/features/readwrite-splitting/distsql/handler/src/test/resources/cases/show-readwrite-splitting-rule-current-config.yaml
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+
+rules:
+ - !READWRITE_SPLITTING
+ dataSourceGroups:
+ readwrite_ds:
+ writeDataSourceName: write_ds
+ readDataSourceNames:
+ - read_ds_0
+ - read_ds_1
diff --git
a/features/readwrite-splitting/distsql/handler/src/test/resources/cases/show-readwrite-splitting-rule.xml
b/features/readwrite-splitting/distsql/handler/src/test/resources/cases/show-readwrite-splitting-rule.xml
new file mode 100644
index 00000000000..256e7b716fd
--- /dev/null
+++
b/features/readwrite-splitting/distsql/handler/src/test/resources/cases/show-readwrite-splitting-rule.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<distsql-rule-query-executor-test-cases>
+ <test-case dist-sql="SHOW READWRITE_SPLITTING RULES"
current-rule-config-yaml-file="cases/show-readwrite-splitting-rule-current-config.yaml">
+ <expected-query-result-rows>
+ <expected-query-result-row>
+ readwrite_ds|write_ds|read_ds_0,read_ds_1|DYNAMIC||
+ </expected-query-result-row>
+ </expected-query-result-rows>
+ </test-case>
+</distsql-rule-query-executor-test-cases>