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 40b6b79871c Use DistSQLDatabaseRuleQueryExecutorAssert in
ShowStatusFromReadwriteSplittingRulesExecutorTest (#34997)
40b6b79871c is described below
commit 40b6b79871c959ebbe2fa67863ab8e77d1c9732b
Author: ilyas ahsan <[email protected]>
AuthorDate: Mon Mar 17 08:04:09 2025 +0700
Use DistSQLDatabaseRuleQueryExecutorAssert in
ShowStatusFromReadwriteSplittingRulesExecutorTest (#34997)
* Use DistSQLDatabaseRuleQueryExecutorAssert in
ShowShardingTableRulesUsedAuditorExecutorTest
* Use DistSQLDatabaseRuleQueryExecutorAssert in
ShowStatusFromReadwriteSplittingRulesExecutorTest
---
...tusFromReadwriteSplittingRulesExecutorTest.java | 40 ++++++----------------
...m-readwrite-splitting-rules-current-config.yaml | 25 ++++++++++++++
.../show-status-from-readwrite-splitting-rules.xml | 30 ++++++++++++++++
3 files changed, 66 insertions(+), 29 deletions(-)
diff --git
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowStatusFromReadwriteSplittingRulesExecutorTest.java
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowStatusFromReadwriteSplittingRulesExecutorTest.java
index d00e6c2e7a6..b99c5a02fec 100644
---
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowStatusFromReadwriteSplittingRulesExecutorTest.java
+++
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowStatusFromReadwriteSplittingRulesExecutorTest.java
@@ -20,15 +20,12 @@ package
org.apache.shardingsphere.readwritesplitting.distsql.handler.query;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import
org.apache.shardingsphere.readwritesplitting.config.ReadwriteSplittingRuleConfiguration;
-import
org.apache.shardingsphere.readwritesplitting.distsql.statement.ShowStatusFromReadwriteSplittingRulesStatement;
import
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceGroupRule;
import
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
-import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLDatabaseRuleQueryExecutorTest;
-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;
@@ -36,21 +33,24 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
-import java.util.stream.Stream;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-class ShowStatusFromReadwriteSplittingRulesExecutorTest extends
DistSQLDatabaseRuleQueryExecutorTest {
+@DistSQLRuleQueryExecutorSettings("cases/show-status-from-readwrite-splitting-rules.xml")
+class ShowStatusFromReadwriteSplittingRulesExecutorTest {
- ShowStatusFromReadwriteSplittingRulesExecutorTest() {
- 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() {
ReadwriteSplittingRule result = mock(ReadwriteSplittingRule.class);
- Map<String, ReadwriteSplittingDataSourceGroupRule>
dataSourceGroupRules = Collections.singletonMap("group_0",
mockDataSourceGroupRule());
+ Map<String, ReadwriteSplittingDataSourceGroupRule>
dataSourceGroupRules = Collections.singletonMap("readwrite_ds",
mockDataSourceGroupRule());
when(result.getDataSourceRuleGroups()).thenReturn(dataSourceGroupRules);
return result;
}
@@ -62,22 +62,4 @@ class ShowStatusFromReadwriteSplittingRulesExecutorTest
extends DistSQLDatabaseR
when(result.getDisabledDataSourceNames()).thenReturn(Collections.singleton("read_ds_1"));
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("withoutRuleName",
mock(ReadwriteSplittingRuleConfiguration.class), new
ShowStatusFromReadwriteSplittingRulesStatement(null, null),
- Arrays.asList(new LocalDataQueryResultRow("read_ds_0",
"ENABLED"), new LocalDataQueryResultRow("read_ds_1", "DISABLED"))),
- Arguments.arguments("withRuleName",
mock(ReadwriteSplittingRuleConfiguration.class), new
ShowStatusFromReadwriteSplittingRulesStatement(null, "bar_rule"),
- Collections.emptyList()));
- }
- }
}
diff --git
a/features/readwrite-splitting/distsql/handler/src/test/resources/cases/show-status-from-readwrite-splitting-rules-current-config.yaml
b/features/readwrite-splitting/distsql/handler/src/test/resources/cases/show-status-from-readwrite-splitting-rules-current-config.yaml
new file mode 100644
index 00000000000..ea0c6837e6e
--- /dev/null
+++
b/features/readwrite-splitting/distsql/handler/src/test/resources/cases/show-status-from-readwrite-splitting-rules-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-status-from-readwrite-splitting-rules.xml
b/features/readwrite-splitting/distsql/handler/src/test/resources/cases/show-status-from-readwrite-splitting-rules.xml
new file mode 100644
index 00000000000..fdddbc5fae8
--- /dev/null
+++
b/features/readwrite-splitting/distsql/handler/src/test/resources/cases/show-status-from-readwrite-splitting-rules.xml
@@ -0,0 +1,30 @@
+<?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 STATUS FROM READWRITE_SPLITTING RULES"
current-rule-config-yaml-file="cases/show-status-from-readwrite-splitting-rules-current-config.yaml">
+ <expected-query-result-rows>
+ <expected-query-result-row>
+ read_ds_0|ENABLED
+ </expected-query-result-row>
+ <expected-query-result-row>
+ read_ds_1|DISABLED
+ </expected-query-result-row>
+ </expected-query-result-rows>
+ </test-case>
+</distsql-rule-query-executor-test-cases>