This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 f20f425adab Use DistSQLDatabaseRuleQueryExecutorAssert in
ShowSingleTablesExecutorTest (#35075)
f20f425adab is described below
commit f20f425adab77b6cefc9828fa7827160d4705a16
Author: ilyas ahsan <[email protected]>
AuthorDate: Wed Mar 26 19:45:59 2025 +0700
Use DistSQLDatabaseRuleQueryExecutorAssert in ShowSingleTablesExecutorTest
(#35075)
* Use DistSQLDatabaseRuleQueryExecutorAssert in
ShowShardingTableRulesUsedAuditorExecutorTest
* Use DistSQLDatabaseRuleQueryExecutorAssert in ShowSingleTablesExecutorTest
---
.../query/ShowSingleTablesExecutorTest.java | 39 ++++++----------------
.../cases/show-single-tables-current-config.yaml | 21 ++++++++++++
.../test/resources/cases/show-single-tables.xml | 30 +++++++++++++++++
3 files changed, 61 insertions(+), 29 deletions(-)
diff --git
a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTablesExecutorTest.java
b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTablesExecutorTest.java
index b1d04d5260f..a26f45f3074 100644
---
a/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTablesExecutorTest.java
+++
b/kernel/single/distsql/handler/src/test/java/org/apache/shardingsphere/single/distsql/handler/query/ShowSingleTablesExecutorTest.java
@@ -18,37 +18,29 @@
package org.apache.shardingsphere.single.distsql.handler.query;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
-import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
import org.apache.shardingsphere.infra.datanode.DataNode;
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.datanode.DataNodeRuleAttribute;
import org.apache.shardingsphere.single.config.SingleRuleConfiguration;
-import
org.apache.shardingsphere.single.distsql.statement.rql.ShowSingleTablesStatement;
import org.apache.shardingsphere.single.rule.SingleRule;
-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;
-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 ShowSingleTablesExecutorTest extends
DistSQLDatabaseRuleQueryExecutorTest {
-
- ShowSingleTablesExecutorTest() {
- super(mockRule());
- }
+@DistSQLRuleQueryExecutorSettings("cases/show-single-tables.xml")
+class ShowSingleTablesExecutorTest {
private static SingleRule mockRule() {
Map<String, Collection<DataNode>> singleTableDataNodeMap = new
HashMap<>(2, 1F);
@@ -61,21 +53,10 @@ class ShowSingleTablesExecutorTest extends
DistSQLDatabaseRuleQueryExecutorTest
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("normal", new
SingleRuleConfiguration(Collections.emptyList(), "foo_ds"), new
ShowSingleTablesStatement(null, null),
- Arrays.asList(new LocalDataQueryResultRow("t_order",
"ds_1"), new LocalDataQueryResultRow("t_order_item", "ds_2"))),
- Arguments.arguments("withLikeLiteral", new
SingleRuleConfiguration(Collections.emptyList(), "foo_ds"), new
ShowSingleTablesStatement(null, "%item"),
- Collections.singleton(new
LocalDataQueryResultRow("t_order_item", "ds_2"))));
- }
+ @ParameterizedTest(name = "DistSQL -> {0}")
+ @ArgumentsSource(DistSQLRuleQueryExecutorTestCaseArgumentsProvider.class)
+ void assertExecuteQuery(@SuppressWarnings("unused") final String distSQL,
final DistSQLStatement sqlStatement,
+ final SingleRuleConfiguration currentRuleConfig,
final Collection<LocalDataQueryResultRow> expected) throws SQLException {
+ new
DistSQLDatabaseRuleQueryExecutorAssert(mockRule()).assertQueryResultRows(currentRuleConfig,
sqlStatement, expected);
}
}
diff --git
a/kernel/single/distsql/handler/src/test/resources/cases/show-single-tables-current-config.yaml
b/kernel/single/distsql/handler/src/test/resources/cases/show-single-tables-current-config.yaml
new file mode 100644
index 00000000000..ba57f46beb3
--- /dev/null
+++
b/kernel/single/distsql/handler/src/test/resources/cases/show-single-tables-current-config.yaml
@@ -0,0 +1,21 @@
+#
+# 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:
+ - !SINGLE
+ tables:
+ - "*.*"
diff --git
a/kernel/single/distsql/handler/src/test/resources/cases/show-single-tables.xml
b/kernel/single/distsql/handler/src/test/resources/cases/show-single-tables.xml
new file mode 100644
index 00000000000..601ca991f67
--- /dev/null
+++
b/kernel/single/distsql/handler/src/test/resources/cases/show-single-tables.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 SINGLE TABLES"
current-rule-config-yaml-file="cases/show-single-tables-current-config.yaml">
+ <expected-query-result-rows>
+ <expected-query-result-row>
+ t_order|ds_1
+ </expected-query-result-row>
+ <expected-query-result-row>
+ t_order_item|ds_2
+ </expected-query-result-row>
+ </expected-query-result-rows>
+ </test-case>
+</distsql-rule-query-executor-test-cases>