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/05 05:04:36 UTC

(shardingsphere) branch master updated: Refactor ShowSQLFederationRuleExecutorTest (#33125)

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 9bb707233d2 Refactor ShowSQLFederationRuleExecutorTest (#33125)
9bb707233d2 is described below

commit 9bb707233d2b49713123e759e6b3e8ba9ff887ad
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Oct 5 13:04:29 2024 +0800

    Refactor ShowSQLFederationRuleExecutorTest (#33125)
    
    * Refactor ShowSQLFederationRuleExecutorTest
    
    * Refactor ShowSQLFederationRuleExecutorTest
---
 kernel/sql-federation/distsql/handler/pom.xml      |  2 +-
 .../query/ShowSQLFederationRuleExecutorTest.java   | 56 +++++++++++-----------
 .../query/ShowSQLParserRuleExecutorTest.java       |  5 +-
 .../query/ShowSQLTranslatorRuleExecutorTest.java   |  5 +-
 .../query/DistSQLGlobalRuleQueryExecutorTest.java  |  6 +--
 5 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/kernel/sql-federation/distsql/handler/pom.xml b/kernel/sql-federation/distsql/handler/pom.xml
index f4ff1302edf..0621e36ac6b 100644
--- a/kernel/sql-federation/distsql/handler/pom.xml
+++ b/kernel/sql-federation/distsql/handler/pom.xml
@@ -50,7 +50,7 @@
         
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-test-util</artifactId>
+            <artifactId>shardingsphere-test-it-distsql</artifactId>
             <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
diff --git a/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutorTest.java b/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutorTest.java
index fe5cc2787fc..a3e7ce3702b 100644
--- a/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutorTest.java
+++ b/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/query/ShowSQLFederationRuleExecutorTest.java
@@ -17,46 +17,48 @@
 
 package org.apache.shardingsphere.sqlfederation.distsql.handler.query;
 
-import org.apache.shardingsphere.distsql.handler.engine.DistSQLConnectionContext;
-import org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecuteEngine;
+import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
+import org.apache.shardingsphere.infra.config.rule.scope.GlobalRuleConfiguration;
 import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
-import org.apache.shardingsphere.mode.manager.ContextManager;
 import org.apache.shardingsphere.sql.parser.api.CacheOption;
 import org.apache.shardingsphere.sqlfederation.config.SQLFederationRuleConfiguration;
 import org.apache.shardingsphere.sqlfederation.distsql.statement.queryable.ShowSQLFederationRuleStatement;
 import org.apache.shardingsphere.sqlfederation.rule.SQLFederationRule;
-import org.junit.jupiter.api.Test;
+import org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLGlobalRuleQueryExecutorTest;
+import org.junit.jupiter.api.extension.ExtensionContext;
+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.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
-import java.util.List;
+import java.util.stream.Stream;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
-class ShowSQLFederationRuleExecutorTest {
+class ShowSQLFederationRuleExecutorTest extends DistSQLGlobalRuleQueryExecutorTest {
     
-    @Test
-    void assertGetRows() throws SQLException {
-        DistSQLQueryExecuteEngine engine = new DistSQLQueryExecuteEngine(new ShowSQLFederationRuleStatement(), null, mockContextManager(), mock(DistSQLConnectionContext.class));
-        engine.executeQuery();
-        List<LocalDataQueryResultRow> actual = new ArrayList<>(engine.getRows());
-        assertThat(actual.size(), is(1));
-        assertThat(actual.get(0).getCell(1), is("true"));
-        assertThat(actual.get(0).getCell(2), is("true"));
-        assertThat(actual.get(0).getCell(3), is("initialCapacity: 2000, maximumSize: 65535"));
+    ShowSQLFederationRuleExecutorTest() {
+        super(mock(SQLFederationRule.class));
     }
     
-    private ContextManager mockContextManager() {
-        ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
-        SQLFederationRule rule = mock(SQLFederationRule.class);
-        when(rule.getConfiguration()).thenReturn(new SQLFederationRuleConfiguration(true, true, new CacheOption(2000, 65535L)));
-        when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(rule)));
-        return result;
+    @ParameterizedTest(name = "{0}")
+    @ArgumentsSource(TestCaseArgumentsProvider.class)
+    void assertExecuteQuery(final String name, final GlobalRuleConfiguration 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("withCacheOption", new SQLFederationRuleConfiguration(false, false, new CacheOption(2000, 65535L)), new ShowSQLFederationRuleStatement(),
+                            Collections.singleton(new LocalDataQueryResultRow(false, false, "initialCapacity: 2000, maximumSize: 65535"))),
+                    Arguments.arguments("withoutCacheOption", new SQLFederationRuleConfiguration(true, true, null), new ShowSQLFederationRuleStatement(),
+                            Collections.singleton(new LocalDataQueryResultRow(true, true, ""))));
+        }
     }
 }
diff --git a/kernel/sql-parser/distsql/handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/query/ShowSQLParserRuleExecutorTest.java b/kernel/sql-parser/distsql/handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/query/ShowSQLParserRuleExecutorTest.java
index fa1904fc65e..5ea78f6ed5c 100644
--- a/kernel/sql-parser/distsql/handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/query/ShowSQLParserRuleExecutorTest.java
+++ b/kernel/sql-parser/distsql/handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/query/ShowSQLParserRuleExecutorTest.java
@@ -46,9 +46,8 @@ class ShowSQLParserRuleExecutorTest extends DistSQLGlobalRuleQueryExecutorTest {
     
     @ParameterizedTest(name = "{0}")
     @ArgumentsSource(TestCaseArgumentsProvider.class)
-    void assertExecuteQuery(final String name,
-                            final GlobalRuleConfiguration ruleConfig, final DistSQLStatement sqlStatement, final Collection<LocalDataQueryResultRow> expectedRows) throws SQLException {
-        assertQueryResultRows(ruleConfig, sqlStatement, expectedRows);
+    void assertExecuteQuery(final String name, final GlobalRuleConfiguration ruleConfig, final DistSQLStatement sqlStatement, final Collection<LocalDataQueryResultRow> expected) throws SQLException {
+        assertQueryResultRows(ruleConfig, sqlStatement, expected);
     }
     
     private static class TestCaseArgumentsProvider implements ArgumentsProvider {
diff --git a/kernel/sql-translator/distsql/handler/src/test/java/org/apache/shardingsphere/sqltranslator/distsql/handler/query/ShowSQLTranslatorRuleExecutorTest.java b/kernel/sql-translator/distsql/handler/src/test/java/org/apache/shardingsphere/sqltranslator/distsql/handler/query/ShowSQLTranslatorRuleExecutorTest.java
index 9582c5700d1..1c17ef7cd74 100644
--- a/kernel/sql-translator/distsql/handler/src/test/java/org/apache/shardingsphere/sqltranslator/distsql/handler/query/ShowSQLTranslatorRuleExecutorTest.java
+++ b/kernel/sql-translator/distsql/handler/src/test/java/org/apache/shardingsphere/sqltranslator/distsql/handler/query/ShowSQLTranslatorRuleExecutorTest.java
@@ -46,9 +46,8 @@ class ShowSQLTranslatorRuleExecutorTest extends DistSQLGlobalRuleQueryExecutorTe
     
     @ParameterizedTest(name = "{0}")
     @ArgumentsSource(TestCaseArgumentsProvider.class)
-    void assertExecuteQuery(final String name,
-                            final GlobalRuleConfiguration ruleConfig, final DistSQLStatement sqlStatement, final Collection<LocalDataQueryResultRow> expectedRows) throws SQLException {
-        assertQueryResultRows(ruleConfig, sqlStatement, expectedRows);
+    void assertExecuteQuery(final String name, final GlobalRuleConfiguration ruleConfig, final DistSQLStatement sqlStatement, final Collection<LocalDataQueryResultRow> expected) throws SQLException {
+        assertQueryResultRows(ruleConfig, sqlStatement, expected);
     }
     
     private static class TestCaseArgumentsProvider implements ArgumentsProvider {
diff --git a/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/query/DistSQLGlobalRuleQueryExecutorTest.java b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/query/DistSQLGlobalRuleQueryExecutorTest.java
index 5ecf5923979..4fc087dbf7a 100644
--- a/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/query/DistSQLGlobalRuleQueryExecutorTest.java
+++ b/test/it/distsql/src/main/java/org/apache/shardingsphere/test/it/distsql/handler/engine/query/DistSQLGlobalRuleQueryExecutorTest.java
@@ -43,11 +43,11 @@ public abstract class DistSQLGlobalRuleQueryExecutorTest {
     
     private final GlobalRule mockedRule;
     
-    protected void assertQueryResultRows(final GlobalRuleConfiguration ruleConfig, final DistSQLStatement sqlStatement, final Collection<LocalDataQueryResultRow> expectedRows) throws SQLException {
+    protected void assertQueryResultRows(final GlobalRuleConfiguration ruleConfig, final DistSQLStatement sqlStatement, final Collection<LocalDataQueryResultRow> expected) throws SQLException {
         DistSQLQueryExecuteEngine engine = new DistSQLQueryExecuteEngine(sqlStatement, null, mockContextManager(ruleConfig), mock(DistSQLConnectionContext.class));
         engine.executeQuery();
-        Collection<LocalDataQueryResultRow> actualRows = new ArrayList<>(engine.getRows());
-        assertThat(actualRows, deepEqual(new ArrayList<>(expectedRows)));
+        Collection<LocalDataQueryResultRow> actual = new ArrayList<>(engine.getRows());
+        assertThat(actual, deepEqual(new ArrayList<>(expected)));
     }
     
     private ContextManager mockContextManager(final GlobalRuleConfiguration ruleConfig) {