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 d6196a118ad Use DistSQLDatabaseRuleQueryExecutorAssert in 
ShowShardingTableRulesUsedKeyGeneratorExecutorTest (#34843)
d6196a118ad is described below

commit d6196a118ad669c922d0e02453a83919a7f7b8e6
Author: ilyas ahsan <meilyasah...@gmail.com>
AuthorDate: Tue Mar 4 18:33:49 2025 +0700

    Use DistSQLDatabaseRuleQueryExecutorAssert in 
ShowShardingTableRulesUsedKeyGeneratorExecutorTest (#34843)
    
    * Use DistSQLDatabaseRuleQueryExecutorAssert in 
ShowShardingTableRulesUsedAuditorExecutorTest
    
    * Use DistSQLDatabaseRuleQueryExecutorAssert in 
ShowShardingTableRulesUsedKeyGeneratorExecutorTest
---
 ...dingTableRulesUsedKeyGeneratorExecutorTest.java | 73 +++-------------------
 ...le-rules-used-key-generator-current-config.yaml | 33 ++++++++++
 ...how-sharding-table-rules-used-key-generator.xml | 27 ++++++++
 3 files changed, 70 insertions(+), 63 deletions(-)

diff --git 
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRulesUsedKeyGeneratorExecutorTest.java
 
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRulesUsedKeyGeneratorExecutorTest.java
index 6301191b2ed..90ea2cc2c98 100644
--- 
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRulesUsedKeyGeneratorExecutorTest.java
+++ 
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRulesUsedKeyGeneratorExecutorTest.java
@@ -18,80 +18,27 @@
 package org.apache.shardingsphere.sharding.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.sharding.api.config.ShardingRuleConfiguration;
-import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
-import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
-import 
org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration;
-import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.NoneShardingStrategyConfiguration;
-import 
org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
-import 
org.apache.shardingsphere.sharding.distsql.statement.ShowShardingTableRulesUsedKeyGeneratorStatement;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
-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.Properties;
-import java.util.stream.Stream;
 
 import static org.mockito.Mockito.mock;
 
-class ShowShardingTableRulesUsedKeyGeneratorExecutorTest extends 
DistSQLDatabaseRuleQueryExecutorTest {
+@DistSQLRuleQueryExecutorSettings("cases/show-sharding-table-rules-used-key-generator.xml")
+class ShowShardingTableRulesUsedKeyGeneratorExecutorTest {
     
-    ShowShardingTableRulesUsedKeyGeneratorExecutorTest() {
-        super(mock(ShardingRule.class));
-    }
-    
-    @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", 
createRuleConfiguration(), new 
ShowShardingTableRulesUsedKeyGeneratorStatement("snowflake", null),
-                    Arrays.asList(new LocalDataQueryResultRow("table", 
"t_order"), new LocalDataQueryResultRow("auto_table", "t_order_auto"))));
-        }
-        
-        private ShardingRuleConfiguration createRuleConfiguration() {
-            ShardingRuleConfiguration result = new ShardingRuleConfiguration();
-            result.getTables().add(createShardingTableRuleConfiguration());
-            
result.getAutoTables().add(createShardingAutoTableRuleConfiguration());
-            result.setDefaultDatabaseShardingStrategy(new 
StandardShardingStrategyConfiguration("user_id", "database_inline"));
-            result.setDefaultTableShardingStrategy(new 
NoneShardingStrategyConfiguration());
-            result.getShardingAlgorithms().put("database_inline", new 
AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new 
Property("algorithm-expression", "ds_${user_id % 2}"))));
-            result.getShardingAlgorithms().put("t_order_inline", new 
AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new 
Property("algorithm-expression", "t_order_${order_id % 2}"))));
-            result.getShardingAlgorithms().put("auto_mod", new 
AlgorithmConfiguration("MOD", PropertiesBuilder.build(new 
Property("sharding-count", "4"))));
-            result.getKeyGenerators().put("snowflake", new 
AlgorithmConfiguration("SNOWFLAKE", new Properties()));
-            return result;
-        }
-        
-        private ShardingTableRuleConfiguration 
createShardingTableRuleConfiguration() {
-            ShardingTableRuleConfiguration result = new 
ShardingTableRuleConfiguration("t_order", "ds_${0..1}.t_order_${0..1}");
-            result.setTableShardingStrategy(new 
StandardShardingStrategyConfiguration("order_id", "t_order_inline"));
-            result.setKeyGenerateStrategy(new 
KeyGenerateStrategyConfiguration("order_id", "snowflake"));
-            return result;
-        }
-        
-        private ShardingAutoTableRuleConfiguration 
createShardingAutoTableRuleConfiguration() {
-            ShardingAutoTableRuleConfiguration result = new 
ShardingAutoTableRuleConfiguration("t_order_auto", "ds_0, ds_1");
-            result.setShardingStrategy(new 
StandardShardingStrategyConfiguration("order_id", "auto_mod"));
-            result.setKeyGenerateStrategy(new 
KeyGenerateStrategyConfiguration("order_id", "snowflake"));
-            return result;
-        }
+    @ParameterizedTest(name = "DistSQL -> {0}")
+    @ArgumentsSource(DistSQLRuleQueryExecutorTestCaseArgumentsProvider.class)
+    void assertExecuteQuery(@SuppressWarnings("unused") final String distSQL, 
final DistSQLStatement sqlStatement,
+                            final ShardingRuleConfiguration currentRuleConfig, 
final Collection<LocalDataQueryResultRow> expected) throws SQLException {
+        new 
DistSQLDatabaseRuleQueryExecutorAssert(mock(ShardingRule.class)).assertQueryResultRows(currentRuleConfig,
 sqlStatement, expected);
     }
 }
diff --git 
a/features/sharding/distsql/handler/src/test/resources/cases/show-sharding-table-rules-used-key-generator-current-config.yaml
 
b/features/sharding/distsql/handler/src/test/resources/cases/show-sharding-table-rules-used-key-generator-current-config.yaml
new file mode 100644
index 00000000000..d035dd8a06b
--- /dev/null
+++ 
b/features/sharding/distsql/handler/src/test/resources/cases/show-sharding-table-rules-used-key-generator-current-config.yaml
@@ -0,0 +1,33 @@
+#
+# 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:
+  - !SHARDING
+    tables:
+      t_order:
+        actualDataNodes: ds_${0..1}.t_order_${0..1}
+        tableStrategy:
+          standard:
+            shardingColumn: order_id
+            shardingAlgorithmName: table_inline
+        keyGenerateStrategy:
+          column: order_id
+          keyGeneratorName: snowflake_key_generator
+
+    keyGenerators:
+      snowflake_key_generator:
+        type: SNOWFLAKE
diff --git 
a/features/sharding/distsql/handler/src/test/resources/cases/show-sharding-table-rules-used-key-generator.xml
 
b/features/sharding/distsql/handler/src/test/resources/cases/show-sharding-table-rules-used-key-generator.xml
new file mode 100644
index 00000000000..97155d6df2b
--- /dev/null
+++ 
b/features/sharding/distsql/handler/src/test/resources/cases/show-sharding-table-rules-used-key-generator.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 SHARDING TABLE RULES USED KEY GENERATOR 
snowflake_key_generator" 
current-rule-config-yaml-file="cases/show-sharding-table-rules-used-key-generator-current-config.yaml">
+        <expected-query-result-rows>
+            <expected-query-result-row>
+                table|t_order
+            </expected-query-result-row>
+        </expected-query-result-rows>
+    </test-case>
+</distsql-rule-query-executor-test-cases>

Reply via email to