You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2024/10/04 09:53:40 UTC

(shardingsphere) branch master updated: Refactor DistSQLQueryExecutor's test cases (#33120)

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 ccd6eba31db Refactor DistSQLQueryExecutor's test cases (#33120)
ccd6eba31db is described below

commit ccd6eba31dbe78a4520a9400982878ea4840de68
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Oct 4 17:53:34 2024 +0800

    Refactor DistSQLQueryExecutor's test cases (#33120)
    
    * Refactor ShowShardingTableRulesUsedKeyGeneratorExecutorTest
    
    * Refactor ShowShardingTableRuleExecutorTest
    
    * Refactor ShowEncryptRuleExecutorTest
    
    * Refactor ShowShardingTableRulesUsedAuditorExecutorTest
    
    * Refactor ShowShardingTableNodesExecutorTest
    
    * Refactor ShowUnusedShardingAuditorsExecutorTest
    
    * Refactor ShowShardingTableNodesExecutorTest
    
    * Refactor ShowShardingTableRulesUsedAlgorithmExecutorTest
    
    * Refactor ShowShardingTableRulesUsedAlgorithmExecutorTest
---
 .../handler/query/ShowEncryptRuleExecutorTest.java |  2 +-
 .../query/ShowShardingTableNodesExecutorTest.java  | 53 ++++++++---------
 .../query/ShowShardingTableRuleExecutorTest.java   | 37 +++++-------
 ...hardingTableRulesUsedAlgorithmExecutorTest.java | 33 +++++------
 ...wShardingTableRulesUsedAuditorExecutorTest.java | 67 ++++++++-------------
 ...dingTableRulesUsedKeyGeneratorExecutorTest.java | 68 ++++++++--------------
 .../ShowUnusedShardingAuditorsExecutorTest.java    | 33 +++++------
 7 files changed, 116 insertions(+), 177 deletions(-)

diff --git a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java
index be74c6287be..7c1d1afca6e 100644
--- a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java
+++ b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptRuleExecutorTest.java
@@ -46,7 +46,7 @@ import static org.mockito.Mockito.when;
 class ShowEncryptRuleExecutorTest {
     
     @Test
-    void assertGetRowData() throws SQLException {
+    void assertExecuteQuery() throws SQLException {
         DistSQLQueryExecuteEngine engine = new DistSQLQueryExecuteEngine(new ShowEncryptRulesStatement("T_ENCRYPT", null), "foo_db", mockContextManager(), mock(DistSQLConnectionContext.class));
         engine.executeQuery();
         Collection<LocalDataQueryResultRow> actual = engine.getRows();
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableNodesExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableNodesExecutorTest.java
index a33dddab3df..89a49d296cd 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableNodesExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableNodesExecutorTest.java
@@ -24,6 +24,7 @@ import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecut
 import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext;
 import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
 import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
 import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
 import org.apache.shardingsphere.infra.yaml.config.pojo.YamlRootConfiguration;
 import org.apache.shardingsphere.mode.manager.ContextManager;
@@ -38,8 +39,11 @@ import java.io.File;
 import java.io.IOException;
 import java.net.URL;
 import java.sql.SQLException;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Optional;
 
 import static org.hamcrest.CoreMatchers.is;
@@ -52,22 +56,8 @@ import static org.mockito.Mockito.when;
 
 class ShowShardingTableNodesExecutorTest {
     
-    private DistSQLQueryExecuteEngine engine;
-    
-    DistSQLQueryExecuteEngine setUp(final ShardingRule rule, final ShowShardingTableNodesStatement statement) {
-        return new DistSQLQueryExecuteEngine(statement, "foo_db", mockContextManager(rule), mock(DistSQLConnectionContext.class));
-    }
-    
-    private ContextManager mockContextManager(final ShardingRule rule) {
-        ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
-        ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
-        when(result.getDatabase("foo_db")).thenReturn(database);
-        when(database.getRuleMetaData().findSingleRule(ShardingRule.class)).thenReturn(Optional.of(rule));
-        return result;
-    }
-    
     @Test
-    void assertGetRowData() throws SQLException {
+    void assertExecuteQuery() throws SQLException {
         ShardingRule rule = createShardingRule();
         assertOrder(rule);
         assertOrderItem(rule);
@@ -86,7 +76,8 @@ class ShowShardingTableNodesExecutorTest {
     }
     
     private void assertOrder(final ShardingRule rule) throws SQLException {
-        engine = setUp(rule, new ShowShardingTableNodesStatement("t_order", null));
+        DistSQLQueryExecuteEngine engine = new DistSQLQueryExecuteEngine(new ShowShardingTableNodesStatement("t_order", null),
+                "foo_db", mockContextManager(rule), mock(DistSQLConnectionContext.class));
         engine.executeQuery();
         Collection<LocalDataQueryResultRow> actual = engine.getRows();
         assertThat(actual.size(), is(1));
@@ -96,28 +87,34 @@ class ShowShardingTableNodesExecutorTest {
         assertThat(row.getCell(2), is("ds_1.t_order_0, ds_2.t_order_1, ds_1.t_order_2, ds_2.t_order_3, ds_1.t_order_4, ds_2.t_order_5"));
     }
     
+    private ContextManager mockContextManager(final ShardingRule rule) {
+        ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
+        ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
+        when(result.getDatabase("foo_db")).thenReturn(database);
+        when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
+        return result;
+    }
+    
     private void assertOrderItem(final ShardingRule rule) throws SQLException {
-        engine = setUp(rule, new ShowShardingTableNodesStatement("t_order_item", null));
+        DistSQLQueryExecuteEngine engine = new DistSQLQueryExecuteEngine(new ShowShardingTableNodesStatement("t_order_item", null),
+                "foo_db", mockContextManager(rule), mock(DistSQLConnectionContext.class));
         engine.executeQuery();
         Collection<LocalDataQueryResultRow> actual = engine.getRows();
         assertThat(actual.size(), is(1));
-        Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
-        LocalDataQueryResultRow row = iterator.next();
+        LocalDataQueryResultRow row = actual.iterator().next();
         assertThat(row.getCell(1), is("t_order_item"));
         assertThat(row.getCell(2), is("ds_2.t_order_item_0, ds_3.t_order_item_1, ds_2.t_order_item_2, ds_3.t_order_item_3, ds_2.t_order_item_4, ds_3.t_order_item_5"));
     }
     
     private void assertAll(final ShardingRule rule) throws SQLException {
-        engine = setUp(rule, new ShowShardingTableNodesStatement(null, null));
+        DistSQLQueryExecuteEngine engine = new DistSQLQueryExecuteEngine(new ShowShardingTableNodesStatement(null, null),
+                "foo_db", mockContextManager(rule), mock(DistSQLConnectionContext.class));
         engine.executeQuery();
-        Collection<LocalDataQueryResultRow> actual = engine.getRows();
+        List<LocalDataQueryResultRow> actual = new ArrayList<>(engine.getRows());
         assertThat(actual.size(), is(2));
-        Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
-        LocalDataQueryResultRow row = iterator.next();
-        assertThat(row.getCell(1), is("t_order"));
-        assertThat(row.getCell(2), is("ds_1.t_order_0, ds_2.t_order_1, ds_1.t_order_2, ds_2.t_order_3, ds_1.t_order_4, ds_2.t_order_5"));
-        row = iterator.next();
-        assertThat(row.getCell(1), is("t_order_item"));
-        assertThat(row.getCell(2), is("ds_2.t_order_item_0, ds_3.t_order_item_1, ds_2.t_order_item_2, ds_3.t_order_item_3, ds_2.t_order_item_4, ds_3.t_order_item_5"));
+        assertThat(actual.get(0).getCell(1), is("t_order"));
+        assertThat(actual.get(0).getCell(2), is("ds_1.t_order_0, ds_2.t_order_1, ds_1.t_order_2, ds_2.t_order_3, ds_1.t_order_4, ds_2.t_order_5"));
+        assertThat(actual.get(1).getCell(1), is("t_order_item"));
+        assertThat(actual.get(1).getCell(2), is("ds_2.t_order_item_0, ds_3.t_order_item_1, ds_2.t_order_item_2, ds_3.t_order_item_3, ds_2.t_order_item_4, ds_3.t_order_item_5"));
     }
 }
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRuleExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRuleExecutorTest.java
index a1955f5f178..53a215ced32 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRuleExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRuleExecutorTest.java
@@ -17,9 +17,9 @@
 
 package org.apache.shardingsphere.sharding.distsql.query;
 
-import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
 import org.apache.shardingsphere.distsql.handler.engine.DistSQLConnectionContext;
 import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecuteEngine;
+import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
 import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
 import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.mode.manager.ContextManager;
@@ -33,13 +33,11 @@ import org.apache.shardingsphere.sharding.distsql.statement.ShowShardingTableRul
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
 import org.apache.shardingsphere.test.util.PropertiesBuilder;
 import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import java.sql.SQLException;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.Optional;
 import java.util.Properties;
 
@@ -51,30 +49,13 @@ import static org.mockito.Mockito.when;
 
 class ShowShardingTableRuleExecutorTest {
     
-    private DistSQLQueryExecuteEngine engine;
-    
-    @BeforeEach
-    void setUp() {
-        engine = new DistSQLQueryExecuteEngine(mock(ShowShardingTableRulesStatement.class), "foo_db", mockContextManager(), mock(DistSQLConnectionContext.class));
-    }
-    
-    private ContextManager mockContextManager() {
-        ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
-        ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
-        when(result.getDatabase("foo_db")).thenReturn(database);
-        ShardingRule rule = mock(ShardingRule.class);
-        when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
-        when(database.getRuleMetaData().findSingleRule(ShardingRule.class)).thenReturn(Optional.of(rule));
-        return result;
-    }
-    
     @Test
-    void assertGetRowData() throws SQLException {
+    void assertExecuteQuery() throws SQLException {
+        DistSQLQueryExecuteEngine engine = new DistSQLQueryExecuteEngine(mock(ShowShardingTableRulesStatement.class), "foo_db", mockContextManager(), mock(DistSQLConnectionContext.class));
         engine.executeQuery();
         Collection<LocalDataQueryResultRow> actual = engine.getRows();
         assertThat(actual.size(), is(1));
-        Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
-        LocalDataQueryResultRow row = iterator.next();
+        LocalDataQueryResultRow row = actual.iterator().next();
         assertThat(row.getCell(1), is("t_order"));
         assertThat(row.getCell(2), is("ds_${0..1}.t_order_${0..1}"));
         assertThat(row.getCell(3), is(""));
@@ -93,6 +74,16 @@ class ShowShardingTableRuleExecutorTest {
         assertThat(row.getCell(16), is("true"));
     }
     
+    private ContextManager mockContextManager() {
+        ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
+        ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
+        when(result.getDatabase("foo_db")).thenReturn(database);
+        ShardingRule rule = mock(ShardingRule.class);
+        when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
+        when(database.getRuleMetaData().findSingleRule(ShardingRule.class)).thenReturn(Optional.of(rule));
+        return result;
+    }
+    
     private ShardingRuleConfiguration createRuleConfiguration() {
         ShardingRuleConfiguration result = new ShardingRuleConfiguration();
         result.getTables().add(createShardingTableRuleConfiguration());
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAlgorithmExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAlgorithmExecutorTest.java
index 794ca11006d..d51872f715a 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAlgorithmExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAlgorithmExecutorTest.java
@@ -49,26 +49,10 @@ import static org.mockito.Mockito.when;
 
 class ShowShardingTableRulesUsedAlgorithmExecutorTest {
     
-    private DistSQLQueryExecuteEngine engine;
-    
-    DistSQLQueryExecuteEngine setUp(final ShowShardingTableRulesUsedAlgorithmStatement statement, final String algorithmName) {
-        when(statement.getShardingAlgorithmName()).thenReturn(Optional.of(algorithmName));
-        return new DistSQLQueryExecuteEngine(statement, "foo_db", mockContextManager(), mock(DistSQLConnectionContext.class));
-    }
-    
-    private ContextManager mockContextManager() {
-        ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
-        ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
-        when(result.getDatabase("foo_db")).thenReturn(database);
-        ShardingRule rule = mock(ShardingRule.class);
-        when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
-        when(database.getRuleMetaData().findSingleRule(ShardingRule.class)).thenReturn(Optional.of(rule));
-        return result;
-    }
-    
     @Test
     void assertGetRowData1() throws SQLException {
-        engine = setUp(mock(ShowShardingTableRulesUsedAlgorithmStatement.class), "t_order_inline");
+        DistSQLQueryExecuteEngine engine = new DistSQLQueryExecuteEngine(
+                new ShowShardingTableRulesUsedAlgorithmStatement("t_order_inline", null), "foo_db", mockContextManager(), mock(DistSQLConnectionContext.class));
         engine.executeQuery();
         Collection<LocalDataQueryResultRow> actual = engine.getRows();
         assertThat(actual.size(), is(1));
@@ -80,7 +64,8 @@ class ShowShardingTableRulesUsedAlgorithmExecutorTest {
     
     @Test
     void assertGetRowData2() throws SQLException {
-        engine = setUp(mock(ShowShardingTableRulesUsedAlgorithmStatement.class), "auto_mod");
+        DistSQLQueryExecuteEngine engine = new DistSQLQueryExecuteEngine(
+                new ShowShardingTableRulesUsedAlgorithmStatement("auto_mod", null), "foo_db", mockContextManager(), mock(DistSQLConnectionContext.class));
         engine.executeQuery();
         Collection<LocalDataQueryResultRow> actual = engine.getRows();
         assertThat(actual.size(), is(1));
@@ -90,6 +75,16 @@ class ShowShardingTableRulesUsedAlgorithmExecutorTest {
         assertThat(row.getCell(2), is("t_order_auto"));
     }
     
+    private ContextManager mockContextManager() {
+        ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
+        ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
+        when(result.getDatabase("foo_db")).thenReturn(database);
+        ShardingRule rule = mock(ShardingRule.class);
+        when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
+        when(database.getRuleMetaData().findSingleRule(ShardingRule.class)).thenReturn(Optional.of(rule));
+        return result;
+    }
+    
     private ShardingRuleConfiguration createRuleConfiguration() {
         ShardingRuleConfiguration result = new ShardingRuleConfiguration();
         result.getTables().add(createShardingTableRuleConfiguration());
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAuditorExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAuditorExecutorTest.java
index 843a10e5c00..472d526dca1 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAuditorExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAuditorExecutorTest.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecut
 import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
 import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
 import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
 import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
@@ -36,10 +37,9 @@ import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
 import org.junit.jupiter.api.Test;
 
 import java.sql.SQLException;
-import java.util.Collection;
+import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Iterator;
-import java.util.Optional;
+import java.util.List;
 import java.util.Properties;
 
 import static org.hamcrest.CoreMatchers.is;
@@ -50,9 +50,17 @@ import static org.mockito.Mockito.when;
 
 class ShowShardingTableRulesUsedAuditorExecutorTest {
     
-    DistSQLQueryExecuteEngine setUp(final ShowShardingTableRulesUsedAuditorStatement statement, final String auditorName) {
-        when(statement.getAuditorName()).thenReturn(Optional.of(auditorName));
-        return new DistSQLQueryExecuteEngine(statement, "foo_db", mockContextManager(), mock(DistSQLConnectionContext.class));
+    @Test
+    void assertExecuteQuery() throws SQLException {
+        DistSQLQueryExecuteEngine engine = new DistSQLQueryExecuteEngine(
+                new ShowShardingTableRulesUsedAuditorStatement("shardingKeyAudit", null), "foo_db", mockContextManager(), mock(DistSQLConnectionContext.class));
+        engine.executeQuery();
+        List<LocalDataQueryResultRow> actual = new ArrayList<>(engine.getRows());
+        assertThat(actual.size(), is(2));
+        assertThat(actual.get(0).getCell(1), is("table"));
+        assertThat(actual.get(0).getCell(2), is("t_order"));
+        assertThat(actual.get(1).getCell(1), is("auto_table"));
+        assertThat(actual.get(1).getCell(2), is("t_order_auto"));
     }
     
     private ContextManager mockContextManager() {
@@ -61,42 +69,20 @@ class ShowShardingTableRulesUsedAuditorExecutorTest {
         when(result.getDatabase("foo_db")).thenReturn(database);
         ShardingRule rule = mock(ShardingRule.class);
         when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
-        when(database.getRuleMetaData().findSingleRule(ShardingRule.class)).thenReturn(Optional.of(rule));
+        when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
         return result;
     }
     
-    @Test
-    void assertGetRowData() throws SQLException {
-        DistSQLQueryExecuteEngine engine = setUp(mock(ShowShardingTableRulesUsedAuditorStatement.class), "shardingKeyAudit");
-        engine.executeQuery();
-        Collection<LocalDataQueryResultRow> actual = engine.getRows();
-        assertThat(actual.size(), is(2));
-        Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
-        LocalDataQueryResultRow row = iterator.next();
-        assertThat(row.getCell(1), is("table"));
-        assertThat(row.getCell(2), is("t_order"));
-        row = iterator.next();
-        assertThat(row.getCell(1), is("auto_table"));
-        assertThat(row.getCell(2), is("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", createShardingInlineAlgorithmConfiguration("ds_${user_id % 2}"));
-        result.getShardingAlgorithms().put("t_order_inline", createShardingInlineAlgorithmConfiguration("t_order_${order_id % 2}"));
-        result.getShardingAlgorithms().put("auto_mod", createShardingAutoModAlgorithmConfiguration());
-        result.getAuditors().put("sharding_key_required_auditor", createAuditorConfiguration());
-        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.setAuditStrategy(new ShardingAuditStrategyConfiguration(Collections.singleton("shardingKeyAudit"), true));
+        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.getAuditors().put("sharding_key_required_auditor", new AlgorithmConfiguration("DML_SHARDING_CONDITIONS", new Properties()));
         return result;
     }
     
@@ -107,15 +93,10 @@ class ShowShardingTableRulesUsedAuditorExecutorTest {
         return result;
     }
     
-    private AlgorithmConfiguration createShardingInlineAlgorithmConfiguration(final String algorithmExpression) {
-        return new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", algorithmExpression)));
-    }
-    
-    private AlgorithmConfiguration createShardingAutoModAlgorithmConfiguration() {
-        return new AlgorithmConfiguration("MOD", PropertiesBuilder.build(new Property("sharding-count", "4")));
-    }
-    
-    private AlgorithmConfiguration createAuditorConfiguration() {
-        return new AlgorithmConfiguration("DML_SHARDING_CONDITIONS", new Properties());
+    private ShardingAutoTableRuleConfiguration createShardingAutoTableRuleConfiguration() {
+        ShardingAutoTableRuleConfiguration result = new ShardingAutoTableRuleConfiguration("t_order_auto", "ds_0, ds_1");
+        result.setShardingStrategy(new StandardShardingStrategyConfiguration("order_id", "auto_mod"));
+        result.setAuditStrategy(new ShardingAuditStrategyConfiguration(Collections.singleton("shardingKeyAudit"), true));
+        return result;
     }
 }
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedKeyGeneratorExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedKeyGeneratorExecutorTest.java
index fa5f602228e..eab7aa109eb 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedKeyGeneratorExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedKeyGeneratorExecutorTest.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecut
 import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
 import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
 import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
 import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
@@ -36,9 +37,9 @@ import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
 import org.junit.jupiter.api.Test;
 
 import java.sql.SQLException;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Optional;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 import java.util.Properties;
 
 import static org.hamcrest.CoreMatchers.is;
@@ -49,9 +50,17 @@ import static org.mockito.Mockito.when;
 
 class ShowShardingTableRulesUsedKeyGeneratorExecutorTest {
     
-    DistSQLQueryExecuteEngine setUp(final ShowShardingTableRulesUsedKeyGeneratorStatement statement, final String keyGeneratorName) {
-        when(statement.getKeyGeneratorName()).thenReturn(Optional.of(keyGeneratorName));
-        return new DistSQLQueryExecuteEngine(statement, "foo_db", mockContextManager(), mock(DistSQLConnectionContext.class));
+    @Test
+    void assertExecuteQuery() throws SQLException {
+        DistSQLQueryExecuteEngine engine = new DistSQLQueryExecuteEngine(
+                new ShowShardingTableRulesUsedKeyGeneratorStatement("snowflake", null), "foo_db", mockContextManager(), mock(DistSQLConnectionContext.class));
+        engine.executeQuery();
+        List<LocalDataQueryResultRow> actual = new ArrayList<>(engine.getRows());
+        assertThat(actual.size(), is(2));
+        assertThat(actual.get(0).getCell(1), is("table"));
+        assertThat(actual.get(0).getCell(2), is("t_order"));
+        assertThat(actual.get(1).getCell(1), is("auto_table"));
+        assertThat(actual.get(1).getCell(2), is("t_order_auto"));
     }
     
     private ContextManager mockContextManager() {
@@ -60,42 +69,20 @@ class ShowShardingTableRulesUsedKeyGeneratorExecutorTest {
         when(result.getDatabase("foo_db")).thenReturn(database);
         ShardingRule rule = mock(ShardingRule.class);
         when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
-        when(database.getRuleMetaData().findSingleRule(ShardingRule.class)).thenReturn(Optional.of(rule));
+        when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
         return result;
     }
     
-    @Test
-    void assertGetRowData() throws SQLException {
-        DistSQLQueryExecuteEngine engine = setUp(mock(ShowShardingTableRulesUsedKeyGeneratorStatement.class), "snowflake");
-        engine.executeQuery();
-        Collection<LocalDataQueryResultRow> actual = engine.getRows();
-        assertThat(actual.size(), is(2));
-        Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
-        LocalDataQueryResultRow row = iterator.next();
-        assertThat(row.getCell(1), is("table"));
-        assertThat(row.getCell(2), is("t_order"));
-        row = iterator.next();
-        assertThat(row.getCell(1), is("auto_table"));
-        assertThat(row.getCell(2), is("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", createShardingInlineAlgorithmConfiguration("ds_${user_id % 2}"));
-        result.getShardingAlgorithms().put("t_order_inline", createShardingInlineAlgorithmConfiguration("t_order_${order_id % 2}"));
-        result.getShardingAlgorithms().put("auto_mod", createShardingAutoModAlgorithmConfiguration());
-        result.getKeyGenerators().put("snowflake", createKeyGeneratorConfiguration());
-        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"));
+        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;
     }
     
@@ -106,15 +93,10 @@ class ShowShardingTableRulesUsedKeyGeneratorExecutorTest {
         return result;
     }
     
-    private AlgorithmConfiguration createShardingInlineAlgorithmConfiguration(final String algorithmExpression) {
-        return new AlgorithmConfiguration("INLINE", PropertiesBuilder.build(new Property("algorithm-expression", algorithmExpression)));
-    }
-    
-    private AlgorithmConfiguration createShardingAutoModAlgorithmConfiguration() {
-        return new AlgorithmConfiguration("MOD", PropertiesBuilder.build(new Property("sharding-count", "4")));
-    }
-    
-    private AlgorithmConfiguration createKeyGeneratorConfiguration() {
-        return new AlgorithmConfiguration("SNOWFLAKE", new Properties());
+    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;
     }
 }
diff --git a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingAuditorsExecutorTest.java b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingAuditorsExecutorTest.java
index 11869b9c3f0..d2b5801f422 100644
--- a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingAuditorsExecutorTest.java
+++ b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowUnusedShardingAuditorsExecutorTest.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecut
 import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
 import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
 import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
 import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
@@ -30,14 +31,12 @@ import org.apache.shardingsphere.sharding.distsql.statement.ShowUnusedShardingAu
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
 import org.apache.shardingsphere.test.util.PropertiesBuilder;
 import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import java.sql.SQLException;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
-import java.util.Optional;
 import java.util.Properties;
 
 import static org.hamcrest.CoreMatchers.is;
@@ -48,25 +47,9 @@ import static org.mockito.Mockito.when;
 
 class ShowUnusedShardingAuditorsExecutorTest {
     
-    private DistSQLQueryExecuteEngine engine;
-    
-    @BeforeEach
-    void setUp() {
-        engine = new DistSQLQueryExecuteEngine(mock(ShowUnusedShardingAuditorsStatement.class), "foo_db", mockContextManager(), mock(DistSQLConnectionContext.class));
-    }
-    
-    private ContextManager mockContextManager() {
-        ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
-        ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
-        when(result.getDatabase("foo_db")).thenReturn(database);
-        ShardingRule rule = mock(ShardingRule.class);
-        when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
-        when(database.getRuleMetaData().findSingleRule(ShardingRule.class)).thenReturn(Optional.of(rule));
-        return result;
-    }
-    
     @Test
-    void assertGetRowData() throws SQLException {
+    void assertExecuteQuery() throws SQLException {
+        DistSQLQueryExecuteEngine engine = new DistSQLQueryExecuteEngine(mock(ShowUnusedShardingAuditorsStatement.class), "foo_db", mockContextManager(), mock(DistSQLConnectionContext.class));
         engine.executeQuery();
         Collection<LocalDataQueryResultRow> actual = engine.getRows();
         assertThat(actual.size(), is(1));
@@ -77,6 +60,16 @@ class ShowUnusedShardingAuditorsExecutorTest {
         assertThat(row.getCell(3), is("{\"key\":\"value\"}"));
     }
     
+    private ContextManager mockContextManager() {
+        ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
+        ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
+        when(result.getDatabase("foo_db")).thenReturn(database);
+        ShardingRule rule = mock(ShardingRule.class);
+        when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
+        when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
+        return result;
+    }
+    
     private ShardingRuleConfiguration createRuleConfiguration() {
         ShardingRuleConfiguration result = new ShardingRuleConfiguration();
         result.getAuditors().put("sharding_key_required_auditor", new AlgorithmConfiguration("DML_SHARDING_CONDITIONS", new Properties()));