This is an automated email from the ASF dual-hosted git repository.

jianglongtao 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 1cad6971d84 Refactor RuleConfigurationToDistSQLConverter's test cases 
(#33454)
1cad6971d84 is described below

commit 1cad6971d84b5886f42f15d40046c8573f52e8c6
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Oct 29 21:26:14 2024 +0800

    Refactor RuleConfigurationToDistSQLConverter's test cases (#33454)
    
    * Refactor RuleConfigurationToDistSQLConverter's test cases
    
    * Refactor RuleConfigurationToDistSQLConverter's test cases
---
 ...roadcastRuleConfigurationToDistSQLConverterTest.java |  8 ++++++--
 .../EncryptRuleConfigurationToDistSQLConverterTest.java | 17 +++++++----------
 .../MaskRuleConfigurationToDistSQLConverterTest.java    |  4 ++--
 ...plittingRuleConfigurationToDistSQLConverterTest.java | 12 ++++++++----
 .../ShadowRuleConfigurationToDistSQLConverterTest.java  | 17 +++++++----------
 ...ShardingRuleConfigurationToDistSQLConverterTest.java | 17 +++++++----------
 6 files changed, 37 insertions(+), 38 deletions(-)

diff --git 
a/features/broadcast/distsql/handler/src/test/java/org/apache/shardingsphere/broadcast/distsql/handler/converter/BroadcastRuleConfigurationToDistSQLConverterTest.java
 
b/features/broadcast/distsql/handler/src/test/java/org/apache/shardingsphere/broadcast/distsql/handler/converter/BroadcastRuleConfigurationToDistSQLConverterTest.java
index 7abc62e0cbe..0cf40f1f14c 100644
--- 
a/features/broadcast/distsql/handler/src/test/java/org/apache/shardingsphere/broadcast/distsql/handler/converter/BroadcastRuleConfigurationToDistSQLConverterTest.java
+++ 
b/features/broadcast/distsql/handler/src/test/java/org/apache/shardingsphere/broadcast/distsql/handler/converter/BroadcastRuleConfigurationToDistSQLConverterTest.java
@@ -18,6 +18,8 @@
 package org.apache.shardingsphere.broadcast.distsql.handler.converter;
 
 import org.apache.shardingsphere.broadcast.config.BroadcastRuleConfiguration;
+import 
org.apache.shardingsphere.distsql.handler.engine.query.ral.convert.RuleConfigurationToDistSQLConverter;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import org.junit.jupiter.api.Test;
 
 import java.util.Arrays;
@@ -29,11 +31,13 @@ import static org.mockito.Mockito.when;
 
 class BroadcastRuleConfigurationToDistSQLConverterTest {
     
+    @SuppressWarnings("unchecked")
+    private final 
RuleConfigurationToDistSQLConverter<BroadcastRuleConfiguration> converter = 
TypedSPILoader.getService(RuleConfigurationToDistSQLConverter.class, 
BroadcastRuleConfiguration.class);
+    
     @Test
     void assertConvert() {
         BroadcastRuleConfiguration ruleConfig = 
mock(BroadcastRuleConfiguration.class);
         when(ruleConfig.getTables()).thenReturn(Arrays.asList("t_province", 
"t_city"));
-        String actual = new 
BroadcastRuleConfigurationToDistSQLConverter().convert(ruleConfig);
-        assertThat(actual, is("CREATE BROADCAST TABLE RULE 
t_province,t_city;"));
+        assertThat(converter.convert(ruleConfig), is("CREATE BROADCAST TABLE 
RULE t_province,t_city;"));
     }
 }
diff --git 
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleConfigurationToDistSQLConverterTest.java
 
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleConfigurationToDistSQLConverterTest.java
index 30ae6bb8f7a..d75ab7db31c 100644
--- 
a/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleConfigurationToDistSQLConverterTest.java
+++ 
b/features/encrypt/distsql/handler/src/test/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleConfigurationToDistSQLConverterTest.java
@@ -17,11 +17,13 @@
 
 package org.apache.shardingsphere.encrypt.distsql.handler.converter;
 
+import 
org.apache.shardingsphere.distsql.handler.engine.query.ral.convert.RuleConfigurationToDistSQLConverter;
 import org.apache.shardingsphere.encrypt.config.EncryptRuleConfiguration;
 import 
org.apache.shardingsphere.encrypt.config.rule.EncryptColumnItemRuleConfiguration;
 import 
org.apache.shardingsphere.encrypt.config.rule.EncryptColumnRuleConfiguration;
 import 
org.apache.shardingsphere.encrypt.config.rule.EncryptTableRuleConfiguration;
 import 
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import org.junit.jupiter.api.Test;
 
 import java.util.Arrays;
@@ -36,19 +38,20 @@ import static org.mockito.Mockito.when;
 
 class EncryptRuleConfigurationToDistSQLConverterTest {
     
+    @SuppressWarnings("unchecked")
+    private final 
RuleConfigurationToDistSQLConverter<EncryptRuleConfiguration> converter = 
TypedSPILoader.getService(RuleConfigurationToDistSQLConverter.class, 
EncryptRuleConfiguration.class);
+    
     @Test
     void assertConvertWithEmptyTables() {
         EncryptRuleConfiguration encryptRuleConfig = 
mock(EncryptRuleConfiguration.class);
         
when(encryptRuleConfig.getTables()).thenReturn(Collections.emptyList());
-        EncryptRuleConfigurationToDistSQLConverter 
encryptRuleConfigurationToDistSQLConverter = new 
EncryptRuleConfigurationToDistSQLConverter();
-        
assertThat(encryptRuleConfigurationToDistSQLConverter.convert(encryptRuleConfig),
 is(""));
+        assertThat(converter.convert(encryptRuleConfig), is(""));
     }
     
     @Test
     void assertConvert() {
         EncryptRuleConfiguration encryptRuleConfig = 
getEncryptRuleConfiguration();
-        EncryptRuleConfigurationToDistSQLConverter 
encryptRuleConfigurationToDistSQLConverter = new 
EncryptRuleConfigurationToDistSQLConverter();
-        
assertThat(encryptRuleConfigurationToDistSQLConverter.convert(encryptRuleConfig),
+        assertThat(converter.convert(encryptRuleConfig),
                 is("CREATE ENCRYPT RULE t_encrypt (" + System.lineSeparator() 
+ "COLUMNS(" + System.lineSeparator()
                         + "(NAME=user_id, CIPHER=user_cipher, 
ASSISTED_QUERY_COLUMN=user_assisted, LIKE_QUERY_COLUMN=user_like, 
ENCRYPT_ALGORITHM(TYPE(NAME='md5')), "
                         + "ASSISTED_QUERY_ALGORITHM(), 
LIKE_QUERY_ALGORITHM())," + System.lineSeparator()
@@ -58,12 +61,6 @@ class EncryptRuleConfigurationToDistSQLConverterTest {
                         + "ASSISTED_QUERY_ALGORITHM(), 
LIKE_QUERY_ALGORITHM())" + System.lineSeparator() + "));"));
     }
     
-    @Test
-    void assertGetType() {
-        EncryptRuleConfigurationToDistSQLConverter 
encryptRuleConfigurationToDistSQLConverter = new 
EncryptRuleConfigurationToDistSQLConverter();
-        
assertThat(encryptRuleConfigurationToDistSQLConverter.getType().getName(), 
is("org.apache.shardingsphere.encrypt.config.EncryptRuleConfiguration"));
-    }
-    
     private EncryptRuleConfiguration getEncryptRuleConfiguration() {
         EncryptColumnRuleConfiguration encryptColumnRuleConfig = new 
EncryptColumnRuleConfiguration("user_id", new 
EncryptColumnItemRuleConfiguration("user_cipher", "test"));
         encryptColumnRuleConfig.setAssistedQuery(new 
EncryptColumnItemRuleConfiguration("user_assisted", 
"foo_assist_query_encryptor"));
diff --git 
a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/converter/MaskRuleConfigurationToDistSQLConverterTest.java
 
b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/converter/MaskRuleConfigurationToDistSQLConverterTest.java
index d70e97eb760..92ec312b127 100644
--- 
a/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/converter/MaskRuleConfigurationToDistSQLConverterTest.java
+++ 
b/features/mask/distsql/handler/src/test/java/org/apache/shardingsphere/mask/distsql/handler/converter/MaskRuleConfigurationToDistSQLConverterTest.java
@@ -33,10 +33,10 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-@SuppressWarnings({"rawtypes", "unchecked"})
 class MaskRuleConfigurationToDistSQLConverterTest {
     
-    private final RuleConfigurationToDistSQLConverter converter = 
TypedSPILoader.getService(RuleConfigurationToDistSQLConverter.class, 
MaskRuleConfiguration.class);
+    @SuppressWarnings("unchecked")
+    private final RuleConfigurationToDistSQLConverter<MaskRuleConfiguration> 
converter = 
TypedSPILoader.getService(RuleConfigurationToDistSQLConverter.class, 
MaskRuleConfiguration.class);
     
     @Test
     void assertConvertWithEmptyTables() {
diff --git 
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleConfigurationToDistSQLConverterTest.java
 
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleConfigurationToDistSQLConverterTest.java
index f0cdeee4599..6bbdd0cac94 100644
--- 
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleConfigurationToDistSQLConverterTest.java
+++ 
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/converter/ReadwriteSplittingRuleConfigurationToDistSQLConverterTest.java
@@ -17,7 +17,9 @@
 
 package org.apache.shardingsphere.readwritesplitting.distsql.handler.converter;
 
+import 
org.apache.shardingsphere.distsql.handler.engine.query.ral.convert.RuleConfigurationToDistSQLConverter;
 import 
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import 
org.apache.shardingsphere.readwritesplitting.config.ReadwriteSplittingRuleConfiguration;
 import 
org.apache.shardingsphere.readwritesplitting.config.rule.ReadwriteSplittingDataSourceGroupRuleConfiguration;
 import org.apache.shardingsphere.test.util.PropertiesBuilder;
@@ -33,12 +35,15 @@ import static org.mockito.Mockito.when;
 
 class ReadwriteSplittingRuleConfigurationToDistSQLConverterTest {
     
+    @SuppressWarnings("unchecked")
+    private final 
RuleConfigurationToDistSQLConverter<ReadwriteSplittingRuleConfiguration> 
converter = TypedSPILoader.getService(
+            RuleConfigurationToDistSQLConverter.class, 
ReadwriteSplittingRuleConfiguration.class);
+    
     @Test
     void assertConvertWithEmptyDataSources() {
         ReadwriteSplittingRuleConfiguration readwriteSplittingRuleConfig = 
mock(ReadwriteSplittingRuleConfiguration.class);
         
when(readwriteSplittingRuleConfig.getDataSourceGroups()).thenReturn(Collections.emptyList());
-        ReadwriteSplittingRuleConfigurationToDistSQLConverter 
readwriteSplittingRuleConfigurationToDistSQLConverter = new 
ReadwriteSplittingRuleConfigurationToDistSQLConverter();
-        
assertThat(readwriteSplittingRuleConfigurationToDistSQLConverter.convert(readwriteSplittingRuleConfig),
 is(""));
+        assertThat(converter.convert(readwriteSplittingRuleConfig), is(""));
     }
     
     @Test
@@ -47,8 +52,7 @@ class 
ReadwriteSplittingRuleConfigurationToDistSQLConverterTest {
                 new 
ReadwriteSplittingDataSourceGroupRuleConfiguration("readwrite_ds", 
"ds_primary", Arrays.asList("ds_slave_0", "ds_slave_1"), "test");
         ReadwriteSplittingRuleConfiguration readwriteSplittingRuleConfig = new 
ReadwriteSplittingRuleConfiguration(Collections.singleton(dataSourceGroupConfig),
                 Collections.singletonMap("test", new 
AlgorithmConfiguration("random", PropertiesBuilder.build(new 
PropertiesBuilder.Property("read_weight", "2:1")))));
-        ReadwriteSplittingRuleConfigurationToDistSQLConverter 
readwriteSplittingRuleConfigurationToDistSQLConverter = new 
ReadwriteSplittingRuleConfigurationToDistSQLConverter();
-        
assertThat(readwriteSplittingRuleConfigurationToDistSQLConverter.convert(readwriteSplittingRuleConfig),
+        assertThat(converter.convert(readwriteSplittingRuleConfig),
                 is("CREATE READWRITE_SPLITTING RULE readwrite_ds (" + 
System.lineSeparator() + "WRITE_STORAGE_UNIT=ds_primary," + 
System.lineSeparator() + "READ_STORAGE_UNITS(ds_slave_0,ds_slave_1),"
                         + System.lineSeparator() + 
"TRANSACTIONAL_READ_QUERY_STRATEGY='DYNAMIC'," + System.lineSeparator() + 
"TYPE(NAME='random', PROPERTIES('read_weight'='2:1'))"
                         + System.lineSeparator() + ");"));
diff --git 
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/converter/ShadowRuleConfigurationToDistSQLConverterTest.java
 
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/converter/ShadowRuleConfigurationToDistSQLConverterTest.java
index c8e1f8bec89..a5e129ab05a 100644
--- 
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/converter/ShadowRuleConfigurationToDistSQLConverterTest.java
+++ 
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/converter/ShadowRuleConfigurationToDistSQLConverterTest.java
@@ -17,7 +17,9 @@
 
 package org.apache.shardingsphere.shadow.distsql.handler.converter;
 
+import 
org.apache.shardingsphere.distsql.handler.engine.query.ral.convert.RuleConfigurationToDistSQLConverter;
 import 
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import org.apache.shardingsphere.shadow.config.ShadowRuleConfiguration;
 import 
org.apache.shardingsphere.shadow.config.datasource.ShadowDataSourceConfiguration;
 import org.apache.shardingsphere.shadow.config.table.ShadowTableConfiguration;
@@ -33,12 +35,14 @@ import static org.mockito.Mockito.when;
 
 class ShadowRuleConfigurationToDistSQLConverterTest {
     
+    @SuppressWarnings("unchecked")
+    private final RuleConfigurationToDistSQLConverter<ShadowRuleConfiguration> 
converter = 
TypedSPILoader.getService(RuleConfigurationToDistSQLConverter.class, 
ShadowRuleConfiguration.class);
+    
     @Test
     void assertConvertWithoutDataSources() {
         ShadowRuleConfiguration shadowRuleConfig = 
mock(ShadowRuleConfiguration.class);
         
when(shadowRuleConfig.getDataSources()).thenReturn(Collections.emptyList());
-        ShadowRuleConfigurationToDistSQLConverter 
shadowRuleConfigurationToDistSQLConverter = new 
ShadowRuleConfigurationToDistSQLConverter();
-        
assertThat(shadowRuleConfigurationToDistSQLConverter.convert(shadowRuleConfig), 
is(""));
+        assertThat(converter.convert(shadowRuleConfig), is(""));
     }
     
     @Test
@@ -48,15 +52,8 @@ class ShadowRuleConfigurationToDistSQLConverterTest {
         
shadowRuleConfig.getShadowAlgorithms().put("user_id_select_match_algorithm", 
new AlgorithmConfiguration("REGEX_MATCH", new Properties()));
         shadowRuleConfig.getTables().put("t_order", new 
ShadowTableConfiguration(Collections.singleton("shadow_rule"), 
Collections.singleton("user_id_select_match_algorithm")));
         shadowRuleConfig.getTables().put("t_order_item", new 
ShadowTableConfiguration(Collections.singleton("shadow_rule"), 
Collections.singleton("user_id_select_match_algorithm")));
-        ShadowRuleConfigurationToDistSQLConverter 
shadowRuleConfigurationToDistSQLConverter = new 
ShadowRuleConfigurationToDistSQLConverter();
-        
assertThat(shadowRuleConfigurationToDistSQLConverter.convert(shadowRuleConfig),
+        assertThat(converter.convert(shadowRuleConfig),
                 is("CREATE SHADOW RULE shadow_rule(" + System.lineSeparator() 
+ "SOURCE=source," + System.lineSeparator() + "SHADOW=shadow," + 
System.lineSeparator()
                         + "t_order(TYPE(NAME='regex_match'))," + 
System.lineSeparator() + "t_order_item(TYPE(NAME='regex_match'))" + 
System.lineSeparator() + ");"));
     }
-    
-    @Test
-    void assertGetType() {
-        ShadowRuleConfigurationToDistSQLConverter 
shadowRuleConfigurationToDistSQLConverter = new 
ShadowRuleConfigurationToDistSQLConverter();
-        
assertThat(shadowRuleConfigurationToDistSQLConverter.getType().getName(), 
is("org.apache.shardingsphere.shadow.config.ShadowRuleConfiguration"));
-    }
 }
diff --git 
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/converter/ShardingRuleConfigurationToDistSQLConverterTest.java
 
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/converter/ShardingRuleConfigurationToDistSQLConverterTest.java
index 070d633dd7c..ba3d9aa07a3 100644
--- 
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/converter/ShardingRuleConfigurationToDistSQLConverterTest.java
+++ 
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/handler/converter/ShardingRuleConfigurationToDistSQLConverterTest.java
@@ -17,7 +17,9 @@
 
 package org.apache.shardingsphere.sharding.distsql.handler.converter;
 
+import 
org.apache.shardingsphere.distsql.handler.engine.query.ral.convert.RuleConfigurationToDistSQLConverter;
 import 
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.strategy.audit.ShardingAuditStrategyConfiguration;
@@ -37,13 +39,15 @@ import static org.mockito.Mockito.when;
 
 class ShardingRuleConfigurationToDistSQLConverterTest {
     
+    @SuppressWarnings("unchecked")
+    private final 
RuleConfigurationToDistSQLConverter<ShardingRuleConfiguration> converter = 
TypedSPILoader.getService(RuleConfigurationToDistSQLConverter.class, 
ShardingRuleConfiguration.class);
+    
     @Test
     void assertConvertWithEmptyTables() {
         ShardingRuleConfiguration shardingRuleConfig = 
mock(ShardingRuleConfiguration.class);
         
when(shardingRuleConfig.getTables()).thenReturn(Collections.emptyList());
         
when(shardingRuleConfig.getAutoTables()).thenReturn(Collections.emptyList());
-        ShardingRuleConfigurationToDistSQLConverter 
shardingRuleConfigurationToDistSQLConverter = new 
ShardingRuleConfigurationToDistSQLConverter();
-        
assertThat(shardingRuleConfigurationToDistSQLConverter.convert(shardingRuleConfig),
 is(""));
+        assertThat(converter.convert(shardingRuleConfig), is(""));
     }
     
     @Test
@@ -56,8 +60,7 @@ class ShardingRuleConfigurationToDistSQLConverterTest {
         shardingRuleConfig.getShardingAlgorithms().put("t_order_inline", 
createShardingInlineAlgorithmConfiguration("t_order_${order_id % 2}"));
         shardingRuleConfig.getKeyGenerators().put("snowflake", 
createKeyGeneratorConfiguration());
         shardingRuleConfig.getAuditors().put("sharding_key_required_auditor", 
createAuditorConfiguration());
-        ShardingRuleConfigurationToDistSQLConverter 
shardingRuleConfigurationToDistSQLConverter = new 
ShardingRuleConfigurationToDistSQLConverter();
-        
assertThat(shardingRuleConfigurationToDistSQLConverter.convert(shardingRuleConfig),
+        assertThat(converter.convert(shardingRuleConfig),
                 is("CREATE SHARDING TABLE RULE t_order (" + 
System.lineSeparator() + "DATANODES('ds_${0..1}.t_order_${0..1}')," + 
System.lineSeparator()
                         + "TABLE_STRATEGY(TYPE='standard', 
SHARDING_COLUMN=order_id, SHARDING_ALGORITHM(TYPE(NAME='inline', 
PROPERTIES('algorithm-expression'='t_order_${order_id % 2}')))),"
                         + System.lineSeparator() + 
"KEY_GENERATE_STRATEGY(COLUMN=order_id, TYPE(NAME='snowflake'))," + 
System.lineSeparator()
@@ -67,12 +70,6 @@ class ShardingRuleConfigurationToDistSQLConverterTest {
                         + "CREATE DEFAULT SHARDING TABLE 
STRATEGY(TYPE='none');"));
     }
     
-    @Test
-    void assertGetType() {
-        ShardingRuleConfigurationToDistSQLConverter 
shardingRuleConfigurationToDistSQLConverter = new 
ShardingRuleConfigurationToDistSQLConverter();
-        
assertThat(shardingRuleConfigurationToDistSQLConverter.getType().getName(), 
is("org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration"));
-    }
-    
     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"));

Reply via email to