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 f9f66677cf9 Add more test cases on 
ShowStatusFromReadwriteSplittingRulesExecutorTest (#38261)
f9f66677cf9 is described below

commit f9f66677cf9cb27d7234a9332d63676d852d5cc0
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Feb 28 10:36:08 2026 +0800

    Add more test cases on ShowStatusFromReadwriteSplittingRulesExecutorTest 
(#38261)
---
 ...tusFromReadwriteSplittingRulesExecutorTest.java | 80 ++++++++++++++++------
 1 file changed, 60 insertions(+), 20 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 b99c5a02fec..9d49d864589 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
@@ -17,49 +17,89 @@
 
 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.distsql.handler.engine.query.DistSQLQueryExecutor;
 import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.infra.state.datasource.DataSourceState;
+import org.apache.shardingsphere.mode.manager.ContextManager;
+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.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.ArgumentsSource;
+import org.junit.jupiter.api.Test;
 
-import java.sql.SQLException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
 
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-@DistSQLRuleQueryExecutorSettings("cases/show-status-from-readwrite-splitting-rules.xml")
 class ShowStatusFromReadwriteSplittingRulesExecutorTest {
     
-    @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 final ShowStatusFromReadwriteSplittingRulesExecutor executor =
+            (ShowStatusFromReadwriteSplittingRulesExecutor) 
TypedSPILoader.getService(DistSQLQueryExecutor.class, 
ShowStatusFromReadwriteSplittingRulesStatement.class);
+    
+    @Test
+    void assertGetColumnNames() {
+        assertThat(executor.getColumnNames(new 
ShowStatusFromReadwriteSplittingRulesStatement(null, null)), 
is(Arrays.asList("name", "storage_unit", "status")));
+    }
+    
+    @Test
+    void assertGetRowsWithoutRuleName() {
+        executor.setRule(mockRule(createDataSourceGroupRules()));
+        LinkedList<LocalDataQueryResultRow> actual = new 
LinkedList<>(executor.getRows(new 
ShowStatusFromReadwriteSplittingRulesStatement(null, null), 
mock(ContextManager.class)));
+        assertThat(actual.size(), is(3));
+        assertRow(actual.get(0), "foo_rule", "read_ds_0", 
DataSourceState.ENABLED.name());
+        assertRow(actual.get(1), "foo_rule", "read_ds_1", 
DataSourceState.DISABLED.name());
+        assertRow(actual.get(2), "bar_rule", "read_ds_2", 
DataSourceState.ENABLED.name());
+    }
+    
+    @Test
+    void assertGetRowsWithRuleName() {
+        executor.setRule(mockRule(createDataSourceGroupRules()));
+        List<LocalDataQueryResultRow> actual = new 
ArrayList<>(executor.getRows(new 
ShowStatusFromReadwriteSplittingRulesStatement(null, "FOO_RULE"), 
mock(ContextManager.class)));
+        assertThat(actual.size(), is(2));
+        assertRow(actual.get(0), "foo_rule", "read_ds_0", 
DataSourceState.ENABLED.name());
+        assertRow(actual.get(1), "foo_rule", "read_ds_1", 
DataSourceState.DISABLED.name());
+    }
+    
+    @Test
+    void assertGetRuleClass() {
+        assertThat(executor.getRuleClass(), is(ReadwriteSplittingRule.class));
     }
     
-    private static ReadwriteSplittingRule mockRule() {
+    private ReadwriteSplittingRule mockRule(final Map<String, 
ReadwriteSplittingDataSourceGroupRule> dataSourceGroupRules) {
         ReadwriteSplittingRule result = mock(ReadwriteSplittingRule.class);
-        Map<String, ReadwriteSplittingDataSourceGroupRule> 
dataSourceGroupRules = Collections.singletonMap("readwrite_ds", 
mockDataSourceGroupRule());
         
when(result.getDataSourceRuleGroups()).thenReturn(dataSourceGroupRules);
         return result;
     }
     
-    private static ReadwriteSplittingDataSourceGroupRule 
mockDataSourceGroupRule() {
+    private Map<String, ReadwriteSplittingDataSourceGroupRule> 
createDataSourceGroupRules() {
+        Map<String, ReadwriteSplittingDataSourceGroupRule> result = new 
LinkedHashMap<>(2, 1F);
+        result.put("foo_rule", mockDataSourceGroupRule("foo_rule", 
Arrays.asList("read_ds_0", "read_ds_1"), Collections.singleton("read_ds_1")));
+        result.put("bar_rule", mockDataSourceGroupRule("bar_rule", 
Collections.singletonList("read_ds_2"), Collections.emptySet()));
+        return result;
+    }
+    
+    private ReadwriteSplittingDataSourceGroupRule 
mockDataSourceGroupRule(final String name, final List<String> readDataSources, 
final Collection<String> disabledDataSourceNames) {
         ReadwriteSplittingDataSourceGroupRule result = 
mock(ReadwriteSplittingDataSourceGroupRule.class, RETURNS_DEEP_STUBS);
-        when(result.getName()).thenReturn("foo_rule");
-        
when(result.getReadwriteSplittingGroup().getReadDataSources()).thenReturn(Arrays.asList("read_ds_0",
 "read_ds_1"));
-        
when(result.getDisabledDataSourceNames()).thenReturn(Collections.singleton("read_ds_1"));
+        when(result.getName()).thenReturn(name);
+        
when(result.getReadwriteSplittingGroup().getReadDataSources()).thenReturn(readDataSources);
+        
when(result.getDisabledDataSourceNames()).thenReturn(disabledDataSourceNames);
         return result;
     }
+    
+    private void assertRow(final LocalDataQueryResultRow row, final String 
expectedRuleName, final String expectedStorageUnit, final String 
expectedStatus) {
+        assertThat(row.getCell(1), is(expectedRuleName));
+        assertThat(row.getCell(2), is(expectedStorageUnit));
+        assertThat(row.getCell(3), is(expectedStatus));
+    }
 }

Reply via email to