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 3fed8d56ab9 Add test cases on InUsedStorageUnitRetriever's impl 
(#33471)
3fed8d56ab9 is described below

commit 3fed8d56ab99652bf73681e7c72c8f6ace47c257
Author: Liang Zhang <zhangli...@apache.org>
AuthorDate: Wed Oct 30 22:29:23 2024 +0800

    Add test cases on InUsedStorageUnitRetriever's impl (#33471)
---
 .../handler/query/InUsedEncryptStorageUnitRetrieverTest.java     | 7 ++++++-
 .../handler/query/InUsedMaskStorageUnitRetrieverTest.java        | 9 +++++++--
 .../query/InUsedReadwriteSplittingStorageUnitRetrieverTest.java  | 6 +++---
 .../handler/query/InUsedShadowStorageUnitRetrieverTest.java      | 6 +++---
 .../handler/query/InUsedShardingStorageUnitRetrieverTest.java    | 4 ++--
 5 files changed, 21 insertions(+), 11 deletions(-)

diff --git 
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/InUsedEncryptStorageUnitRetrieverTest.java
 
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/InUsedEncryptStorageUnitRetrieverTest.java
index 64c8b33de46..a269bde6282 100644
--- 
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/InUsedEncryptStorageUnitRetrieverTest.java
+++ 
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/query/InUsedEncryptStorageUnitRetrieverTest.java
@@ -38,8 +38,13 @@ class InUsedEncryptStorageUnitRetrieverTest {
     @Test
     void assertGetInUsedResources() {
         ShowRulesUsedStorageUnitStatement sqlStatement = new 
ShowRulesUsedStorageUnitStatement(null, null);
+        EncryptRule rule = mockRule();
+        assertThat(retriever.getInUsedResources(sqlStatement, rule), 
is(Collections.singleton("foo_tbl")));
+    }
+    
+    private EncryptRule mockRule() {
         EncryptRule rule = mock(EncryptRule.class);
         
when(rule.getAllTableNames()).thenReturn(Collections.singleton("foo_tbl"));
-        assertThat(retriever.getInUsedResources(sqlStatement, rule), 
is(Collections.singleton("foo_tbl")));
+        return rule;
     }
 }
diff --git 
a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/query/InUsedMaskStorageUnitRetrieverTest.java
 
b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/query/InUsedMaskStorageUnitRetrieverTest.java
index e1b0e65bc9f..4589a17ddcf 100644
--- 
a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/query/InUsedMaskStorageUnitRetrieverTest.java
+++ 
b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/query/InUsedMaskStorageUnitRetrieverTest.java
@@ -40,8 +40,13 @@ class InUsedMaskStorageUnitRetrieverTest {
     @Test
     void assertGetInUsedResources() {
         ShowRulesUsedStorageUnitStatement sqlStatement = new 
ShowRulesUsedStorageUnitStatement(null, null);
-        MaskRule rule = mock(MaskRule.class, RETURNS_DEEP_STUBS);
-        
when(rule.getConfiguration().getTables()).thenReturn(Collections.singleton(new 
MaskTableRuleConfiguration("foo_tbl", Collections.emptyList())));
+        MaskRule rule = mockRule();
         assertThat(retriever.getInUsedResources(sqlStatement, rule), 
is(Collections.singletonList("foo_tbl")));
     }
+    
+    private MaskRule mockRule() {
+        MaskRule result = mock(MaskRule.class, RETURNS_DEEP_STUBS);
+        
when(result.getConfiguration().getTables()).thenReturn(Collections.singleton(new
 MaskTableRuleConfiguration("foo_tbl", Collections.emptyList())));
+        return result;
+    }
 }
diff --git 
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/InUsedReadwriteSplittingStorageUnitRetrieverTest.java
 
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/InUsedReadwriteSplittingStorageUnitRetrieverTest.java
index 1302fdebcf5..d6fb83438da 100644
--- 
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/InUsedReadwriteSplittingStorageUnitRetrieverTest.java
+++ 
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/InUsedReadwriteSplittingStorageUnitRetrieverTest.java
@@ -47,16 +47,16 @@ class InUsedReadwriteSplittingStorageUnitRetrieverTest {
     @Test
     void assertGetInUsedResourcesWithWriteDataSource() {
         ShowRulesUsedStorageUnitStatement sqlStatement = new 
ShowRulesUsedStorageUnitStatement("foo_unit_write", null);
-        assertThat(retriever.getInUsedResources(sqlStatement, 
createReadwriteSplittingRule()), is(Collections.singletonList("foo_ds")));
+        assertThat(retriever.getInUsedResources(sqlStatement, mockRule()), 
is(Collections.singletonList("foo_ds")));
     }
     
     @Test
     void assertGetInUsedResourcesWithReadDataSource() {
         ShowRulesUsedStorageUnitStatement sqlStatement = new 
ShowRulesUsedStorageUnitStatement("foo_unit_read", null);
-        assertThat(retriever.getInUsedResources(sqlStatement, 
createReadwriteSplittingRule()), is(Collections.singletonList("foo_ds")));
+        assertThat(retriever.getInUsedResources(sqlStatement, mockRule()), 
is(Collections.singletonList("foo_ds")));
     }
     
-    private static ReadwriteSplittingRule createReadwriteSplittingRule() {
+    private ReadwriteSplittingRule mockRule() {
         ReadwriteSplittingRule result = mock(ReadwriteSplittingRule.class, 
RETURNS_DEEP_STUBS);
         ReadwriteSplittingDataSourceGroupRuleConfiguration 
dataSourceGroupRuleConfig = new 
ReadwriteSplittingDataSourceGroupRuleConfiguration(
                 "foo_ds", "foo_unit_write", 
Collections.singletonList("foo_unit_read"), "");
diff --git 
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/InUsedShadowStorageUnitRetrieverTest.java
 
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/InUsedShadowStorageUnitRetrieverTest.java
index aec1a3b24b2..a9808066345 100644
--- 
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/InUsedShadowStorageUnitRetrieverTest.java
+++ 
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/InUsedShadowStorageUnitRetrieverTest.java
@@ -47,16 +47,16 @@ class InUsedShadowStorageUnitRetrieverTest {
     @Test
     void assertGetInUsedResourcesWithShadowDataSource() {
         ShowRulesUsedStorageUnitStatement sqlStatement = new 
ShowRulesUsedStorageUnitStatement("prod_ds", null);
-        assertThat(retriever.getInUsedResources(sqlStatement, 
createShadowRule()), is(Collections.singletonList("foo_ds")));
+        assertThat(retriever.getInUsedResources(sqlStatement, mockRule()), 
is(Collections.singletonList("foo_ds")));
     }
     
     @Test
     void assertGetInUsedResourcesWithProductionDataSource() {
         ShowRulesUsedStorageUnitStatement sqlStatement = new 
ShowRulesUsedStorageUnitStatement("shadow_ds", null);
-        assertThat(retriever.getInUsedResources(sqlStatement, 
createShadowRule()), is(Collections.singletonList("foo_ds")));
+        assertThat(retriever.getInUsedResources(sqlStatement, mockRule()), 
is(Collections.singletonList("foo_ds")));
     }
     
-    private static ShadowRule createShadowRule() {
+    private ShadowRule mockRule() {
         ShadowRule result = mock(ShadowRule.class, RETURNS_DEEP_STUBS);
         ShadowDataSourceConfiguration dataSourceConfig = new 
ShadowDataSourceConfiguration("foo_ds", "prod_ds", "shadow_ds");
         
when(result.getConfiguration().getDataSources()).thenReturn(Collections.singleton(dataSourceConfig));
diff --git 
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/InUsedShardingStorageUnitRetrieverTest.java
 
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/InUsedShardingStorageUnitRetrieverTest.java
index 6fc96351710..a396940a855 100644
--- 
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/InUsedShardingStorageUnitRetrieverTest.java
+++ 
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/query/InUsedShardingStorageUnitRetrieverTest.java
@@ -42,10 +42,10 @@ class InUsedShardingStorageUnitRetrieverTest {
     @Test
     void assertGetInUsedResources() {
         ShowRulesUsedStorageUnitStatement sqlStatement = new 
ShowRulesUsedStorageUnitStatement("prod_ds", null);
-        assertThat(retriever.getInUsedResources(sqlStatement, 
createShardingRule()), is(Arrays.asList("foo_auto_tbl", "foo_tbl")));
+        assertThat(retriever.getInUsedResources(sqlStatement, mockRule()), 
is(Arrays.asList("foo_auto_tbl", "foo_tbl")));
     }
     
-    private static ShardingRule createShardingRule() {
+    private ShardingRule mockRule() {
         ShardingRule result = mock(ShardingRule.class, RETURNS_DEEP_STUBS);
         
when(result.getConfiguration().getAutoTables()).thenReturn(Collections.singleton(new
 ShardingAutoTableRuleConfiguration("foo_auto_tbl", "")));
         
when(result.getConfiguration().getTables()).thenReturn(Collections.singleton(new
 ShardingTableRuleConfiguration("foo_tbl", "")));

Reply via email to