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

wuweijie 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 9afdabb  Refactor FunctionSegment (#10824)
9afdabb is described below

commit 9afdabb364aefe06baaa83f7d2d3cb1f7e4516db
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Jun 15 22:01:55 2021 +0800

    Refactor FunctionSegment (#10824)
---
 .../distsql/parser/segment/FunctionSegment.java    |  8 ++--
 .../DatabaseDiscoveryRuleSQLStatementVisitor.java  | 18 +++++----
 .../EncryptRuleStatementConverterTest.java         |  5 +--
 .../core/EncryptRuleSQLStatementVisitor.java       | 18 +++++----
 .../ReadwriteSplittingRuleSQLStatementVisitor.java | 18 +++++----
 .../ShardingRuleStatementConverterTest.java        |  5 +--
 .../core/ShardingRuleSQLStatementVisitor.java      | 18 +++++----
 .../impl/AlterEncryptRuleBackendHandlerTest.java   | 47 ++++++++++------------
 .../AlterShardingTableRuleBackendHandlerTest.java  | 17 +++-----
 .../impl/CreateEncryptRuleBackendHandlerTest.java  | 19 +++++----
 .../CreateShardingTableRuleBackendHandlerTest.java |  9 ++---
 11 files changed, 85 insertions(+), 97 deletions(-)

diff --git 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/FunctionSegment.java
 
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/FunctionSegment.java
index 79727e9..958ba48 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/FunctionSegment.java
+++ 
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/FunctionSegment.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.distsql.parser.segment;
 
 import lombok.Getter;
-import lombok.Setter;
+import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
 
 import java.util.Properties;
@@ -26,11 +26,11 @@ import java.util.Properties;
 /**
  * Function segment.
  */
+@RequiredArgsConstructor
 @Getter
-@Setter
 public final class FunctionSegment implements ASTNode {
     
-    private String algorithmName;
+    private final String algorithmName;
     
-    private Properties algorithmProps;
+    private final Properties algorithmProps;
 }
diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryRuleSQLStatementVisitor.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryRuleSQLStatementVisitor.java
index 0b695b0..cc89f83 100644
--- 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryRuleSQLStatementVisitor.java
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryRuleSQLStatementVisitor.java
@@ -93,15 +93,17 @@ public final class DatabaseDiscoveryRuleSQLStatementVisitor 
extends DatabaseDisc
     
     @Override
     public ASTNode visitFunctionDefinition(final FunctionDefinitionContext 
ctx) {
-        FunctionSegment result = new FunctionSegment();
-        result.setAlgorithmName(ctx.functionName().getText());
-        Properties algorithmProps = new Properties();
-        if (null != ctx.algorithmProperties()) {
-            for (AlgorithmPropertyContext each : 
ctx.algorithmProperties().algorithmProperty()) {
-                algorithmProps.setProperty(new 
IdentifierValue(each.key.getText()).getValue(), new 
IdentifierValue(each.value.getText()).getValue());
-            }
+        return new FunctionSegment(ctx.functionName().getText(), 
getAlgorithmProperties(ctx));
+    }
+    
+    private Properties getAlgorithmProperties(final FunctionDefinitionContext 
ctx) {
+        Properties result = new Properties();
+        if (null == ctx.algorithmProperties()) {
+            return result;
+        }
+        for (AlgorithmPropertyContext each : 
ctx.algorithmProperties().algorithmProperty()) {
+            result.setProperty(new 
IdentifierValue(each.key.getText()).getValue(), new 
IdentifierValue(each.value.getText()).getValue());
         }
-        result.setAlgorithmProps(algorithmProps);
         return result;
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/yaml/converter/EncryptRuleStatementConverterTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/yaml/converter/EncryptRuleStatementConverterTest.java
index f9241a9..d27db9a 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/yaml/converter/EncryptRuleStatementConverterTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/yaml/converter/EncryptRuleStatementConverterTest.java
@@ -52,12 +52,9 @@ public final class EncryptRuleStatementConverterTest {
         encryptColumnSegment.setName("user_id");
         encryptColumnSegment.setPlainColumn("user_plain");
         encryptColumnSegment.setCipherColumn("user_cipher");
-        FunctionSegment functionSegment = new FunctionSegment();
-        functionSegment.setAlgorithmName("MD5");
         Properties properties = new Properties();
         properties.setProperty("MD5-key", "MD5-value");
-        functionSegment.setAlgorithmProps(properties);
-        encryptColumnSegment.setEncryptor(functionSegment);
+        encryptColumnSegment.setEncryptor(new FunctionSegment("MD5", 
properties));
         return Collections.singleton(encryptColumnSegment);
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptRuleSQLStatementVisitor.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptRuleSQLStatementVisitor.java
index 332703b..084694c 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptRuleSQLStatementVisitor.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptRuleSQLStatementVisitor.java
@@ -91,15 +91,17 @@ public final class EncryptRuleSQLStatementVisitor extends 
EncryptRuleStatementBa
     
     @Override
     public ASTNode visitFunctionDefinition(final FunctionDefinitionContext 
ctx) {
-        FunctionSegment result = new FunctionSegment();
-        result.setAlgorithmName(ctx.functionName().getText());
-        Properties algorithmProps = new Properties();
-        if (null != ctx.algorithmProperties()) {
-            for (AlgorithmPropertyContext each : 
ctx.algorithmProperties().algorithmProperty()) {
-                algorithmProps.setProperty(new 
IdentifierValue(each.key.getText()).getValue(), new 
IdentifierValue(each.value.getText()).getValue());
-            }
+        return new FunctionSegment(ctx.functionName().getText(), 
getAlgorithmProperties(ctx));
+    }
+    
+    private Properties getAlgorithmProperties(final FunctionDefinitionContext 
ctx) {
+        Properties result = new Properties();
+        if (null == ctx.algorithmProperties()) {
+            return result;
+        }
+        for (AlgorithmPropertyContext each : 
ctx.algorithmProperties().algorithmProperty()) {
+            result.setProperty(new 
IdentifierValue(each.key.getText()).getValue(), new 
IdentifierValue(each.value.getText()).getValue());
         }
-        result.setAlgorithmProps(algorithmProps);
         return result;
     }
     
diff --git 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingRuleSQLStatementVisitor.java
 
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingRuleSQLStatementVisitor.java
index 945c281..94fffd0 100644
--- 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingRuleSQLStatementVisitor.java
+++ 
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingRuleSQLStatementVisitor.java
@@ -107,15 +107,17 @@ public final class 
ReadwriteSplittingRuleSQLStatementVisitor extends ReadwriteSp
     
     @Override
     public ASTNode visitFunctionDefinition(final FunctionDefinitionContext 
ctx) {
-        FunctionSegment result = new FunctionSegment();
-        result.setAlgorithmName(ctx.functionName().getText());
-        Properties algorithmProps = new Properties();
-        if (null != ctx.algorithmProperties()) {
-            for (AlgorithmPropertyContext each : 
ctx.algorithmProperties().algorithmProperty()) {
-                algorithmProps.setProperty(new 
IdentifierValue(each.key.getText()).getValue(), new 
IdentifierValue(each.value.getText()).getValue());
-            }
+        return new FunctionSegment(ctx.functionName().getText(), 
getAlgorithmProperties(ctx));
+    }
+    
+    private Properties getAlgorithmProperties(final FunctionDefinitionContext 
ctx) {
+        Properties result = new Properties();
+        if (null == ctx.algorithmProperties()) {
+            return result;
+        }
+        for (AlgorithmPropertyContext each : 
ctx.algorithmProperties().algorithmProperty()) {
+            result.setProperty(new 
IdentifierValue(each.key.getText()).getValue(), new 
IdentifierValue(each.value.getText()).getValue());
         }
-        result.setAlgorithmProps(algorithmProps);
         return result;
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/converter/ShardingRuleStatementConverterTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/converter/ShardingRuleStatementConverterTest.java
index c78111f..589f3fc 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/converter/ShardingRuleStatementConverterTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/converter/ShardingRuleStatementConverterTest.java
@@ -47,12 +47,9 @@ public final class ShardingRuleStatementConverterTest {
         segment.setLogicTable("t_order");
         segment.setDataSources(Arrays.asList("ds0", "ds1"));
         segment.setTableStrategyColumn("order_id");
-        FunctionSegment functionSegment = new FunctionSegment();
-        functionSegment.setAlgorithmName("MOD");
         Properties props = new Properties();
         props.setProperty("sharding_count", "2");
-        functionSegment.setAlgorithmProps(props);
-        segment.setTableStrategy(functionSegment);
+        segment.setTableStrategy(new FunctionSegment("MOD", props));
         sqlStatement = new 
CreateShardingTableRuleStatement(Collections.singleton(segment));
     }
     
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingRuleSQLStatementVisitor.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingRuleSQLStatementVisitor.java
index b54526a..0ead4e4 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingRuleSQLStatementVisitor.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingRuleSQLStatementVisitor.java
@@ -157,15 +157,17 @@ public final class ShardingRuleSQLStatementVisitor 
extends ShardingRuleStatement
     
     @Override
     public ASTNode visitFunctionDefinition(final FunctionDefinitionContext 
ctx) {
-        FunctionSegment result = new FunctionSegment();
-        result.setAlgorithmName(ctx.functionName().getText());
-        Properties algorithmProps = new Properties();
-        if (null != ctx.algorithmProperties()) {
-            for (AlgorithmPropertyContext each : 
ctx.algorithmProperties().algorithmProperty()) {
-                algorithmProps.setProperty(new 
IdentifierValue(each.key.getText()).getValue(), new 
IdentifierValue(each.value.getText()).getValue());
-            }
+        return new FunctionSegment(ctx.functionName().getText(), 
getAlgorithmProperties(ctx));
+    }
+    
+    private Properties getAlgorithmProperties(final FunctionDefinitionContext 
ctx) {
+        Properties result = new Properties();
+        if (null == ctx.algorithmProperties()) {
+            return result;
+        }
+        for (AlgorithmPropertyContext each : 
ctx.algorithmProperties().algorithmProperty()) {
+            result.setProperty(new 
IdentifierValue(each.key.getText()).getValue(), new 
IdentifierValue(each.value.getText()).getValue());
         }
-        result.setAlgorithmProps(algorithmProps);
         return result;
     }
     
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterEncryptRuleBackendHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterEncryptRuleBackendHandlerTest.java
index b5278dc..aec9f62 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterEncryptRuleBackendHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterEncryptRuleBackendHandlerTest.java
@@ -17,13 +17,12 @@
 
 package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.impl;
 
-import com.google.common.collect.Maps;
 import org.apache.shardingsphere.distsql.parser.segment.FunctionSegment;
-import 
org.apache.shardingsphere.encrypt.distsql.parser.statement.segment.EncryptColumnSegment;
-import 
org.apache.shardingsphere.encrypt.distsql.parser.statement.segment.EncryptRuleSegment;
-import 
org.apache.shardingsphere.encrypt.distsql.parser.statement.AlterEncryptRuleStatement;
 import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
 import 
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
+import 
org.apache.shardingsphere.encrypt.distsql.parser.statement.AlterEncryptRuleStatement;
+import 
org.apache.shardingsphere.encrypt.distsql.parser.statement.segment.EncryptColumnSegment;
+import 
org.apache.shardingsphere.encrypt.distsql.parser.statement.segment.EncryptRuleSegment;
 import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
 import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -44,7 +43,9 @@ import org.mockito.junit.MockitoJUnitRunner;
 
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.LinkedList;
+import java.util.Properties;
 
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
@@ -71,9 +72,9 @@ public final class AlterEncryptRuleBackendHandlerTest {
     
     @Mock
     private ShardingSphereRuleMetaData ruleMetaData;
-
+    
     @Mock
-    private EncryptTableRuleConfiguration encryptTableRuleConfiguration;
+    private EncryptTableRuleConfiguration encryptTableRuleConfig;
     
     private final AlterEncryptRuleBackendHandler handler = new 
AlterEncryptRuleBackendHandler(sqlStatement, backendConnection);
     
@@ -90,10 +91,8 @@ public final class AlterEncryptRuleBackendHandlerTest {
     public void assertExecute() {
         EncryptRuleSegment encryptRuleSegment = new 
EncryptRuleSegment("t_encrypt", buildColumns("MD5"));
         
when(sqlStatement.getRules()).thenReturn(Collections.singletonList(encryptRuleSegment));
-        when(ruleMetaData.getConfigurations()).thenReturn(Collections
-                .singletonList(new EncryptRuleConfiguration(new 
LinkedList<>(Collections
-                        .singleton(encryptTableRuleConfiguration)), 
Maps.newHashMap())));
-        when(encryptTableRuleConfiguration.getName()).thenReturn("t_encrypt");
+        
when(ruleMetaData.getConfigurations()).thenReturn(Collections.singleton(new 
EncryptRuleConfiguration(new 
LinkedList<>(Collections.singleton(encryptTableRuleConfig)), new HashMap<>())));
+        when(encryptTableRuleConfig.getName()).thenReturn("t_encrypt");
         ResponseHeader responseHeader = handler.execute("test", sqlStatement);
         assertNotNull(responseHeader);
         assertTrue(responseHeader instanceof UpdateResponseHeader);
@@ -104,34 +103,30 @@ public final class AlterEncryptRuleBackendHandlerTest {
         
when(ruleMetaData.getConfigurations()).thenReturn(Collections.emptyList());
         handler.execute("test", sqlStatement);
     }
-
+    
     @Test(expected = EncryptRulesNotExistedException.class)
     public void assertExecuteWithNoAlteredEncryptRules() {
         EncryptRuleSegment encryptRuleSegment = new 
EncryptRuleSegment("t_encrypt", buildColumns("MD5"));
         
when(sqlStatement.getRules()).thenReturn(Collections.singletonList(encryptRuleSegment));
-        
when(ruleMetaData.getConfigurations()).thenReturn(Collections.singletonList(new 
EncryptRuleConfiguration(Collections.emptyList(), Maps.newHashMap())));
+        
when(ruleMetaData.getConfigurations()).thenReturn(Collections.singletonList(new 
EncryptRuleConfiguration(Collections.emptyList(), new HashMap<>())));
         handler.execute("test", sqlStatement);
     }
-
+    
     @Test(expected = InvalidEncryptorsException.class)
     public void assertExecuteWithInvalidEncryptors() {
         EncryptRuleSegment encryptRuleSegment = new 
EncryptRuleSegment("t_encrypt", buildColumns("notExistEncryptor"));
         
when(sqlStatement.getRules()).thenReturn(Collections.singletonList(encryptRuleSegment));
-        when(ruleMetaData.getConfigurations()).thenReturn(Collections
-                .singletonList(new EncryptRuleConfiguration(Collections
-                        .singleton(encryptTableRuleConfiguration), 
Maps.newHashMap())));
-        when(encryptTableRuleConfiguration.getName()).thenReturn("t_encrypt");
+        
when(ruleMetaData.getConfigurations()).thenReturn(Collections.singletonList(new 
EncryptRuleConfiguration(Collections.singleton(encryptTableRuleConfig), new 
HashMap<>())));
+        when(encryptTableRuleConfig.getName()).thenReturn("t_encrypt");
         handler.execute("test", sqlStatement);
     }
-
+    
     private Collection<EncryptColumnSegment> buildColumns(final String 
encryptorName) {
-        EncryptColumnSegment encryptColumnSegment = new EncryptColumnSegment();
-        encryptColumnSegment.setName("user_id");
-        encryptColumnSegment.setPlainColumn("user_plain");
-        encryptColumnSegment.setCipherColumn("user_cipher");
-        FunctionSegment functionSegment = new FunctionSegment();
-        functionSegment.setAlgorithmName(encryptorName);
-        encryptColumnSegment.setEncryptor(functionSegment);
-        return Collections.singleton(encryptColumnSegment);
+        EncryptColumnSegment result = new EncryptColumnSegment();
+        result.setName("user_id");
+        result.setPlainColumn("user_plain");
+        result.setCipherColumn("user_cipher");
+        result.setEncryptor(new FunctionSegment(encryptorName, new 
Properties()));
+        return Collections.singleton(result);
     }
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandlerTest.java
index 45cea80..8e85ba2 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AlterShardingTableRuleBackendHandlerTest.java
@@ -101,10 +101,7 @@ public final class 
AlterShardingTableRuleBackendHandlerTest {
     public void assertExecute() {
         TableRuleSegment tableRuleSegment = new TableRuleSegment();
         tableRuleSegment.setLogicTable("t_order");
-        FunctionSegment functionSegment = new FunctionSegment();
-        functionSegment.setAlgorithmName("hash_mod");
-        functionSegment.setAlgorithmProps(new Properties());
-        tableRuleSegment.setTableStrategy(functionSegment);
+        tableRuleSegment.setTableStrategy(new FunctionSegment("hash_mod", new 
Properties()));
         tableRuleSegment.setDataSources(Collections.singleton("ds_0"));
         tableRuleSegment.setTableStrategyColumn("order_id");
         
when(ruleMetaData.getConfigurations()).thenReturn(buildShardingConfigurations());
@@ -143,20 +140,18 @@ public final class 
AlterShardingTableRuleBackendHandlerTest {
         TableRuleSegment tableRuleSegment = new TableRuleSegment();
         tableRuleSegment.setLogicTable("t_order_item");
         tableRuleSegment.setDataSources(Collections.emptyList());
-        FunctionSegment shardingAlgorithm = new FunctionSegment();
-        shardingAlgorithm.setAlgorithmName("algorithm-not-exist");
-        tableRuleSegment.setTableStrategy(shardingAlgorithm);
+        tableRuleSegment.setTableStrategy(new 
FunctionSegment("algorithm-not-exist", new Properties()));
         
when(sqlStatement.getRules()).thenReturn(Collections.singleton(tableRuleSegment));
         
when(ruleMetaData.getConfigurations()).thenReturn(buildShardingConfigurations());
         handler.execute("test", sqlStatement);
     }
     
     private Collection<RuleConfiguration> buildShardingConfigurations() {
-        ShardingRuleConfiguration config = new ShardingRuleConfiguration();
-        config.getTables().add(new 
ShardingTableRuleConfiguration("t_order_item"));
+        ShardingRuleConfiguration result = new ShardingRuleConfiguration();
+        result.getTables().add(new 
ShardingTableRuleConfiguration("t_order_item"));
         ShardingAutoTableRuleConfiguration shardingAutoTableRuleConfiguration 
= new ShardingAutoTableRuleConfiguration("t_order");
         shardingAutoTableRuleConfiguration.setShardingStrategy(new 
StandardShardingStrategyConfiguration("order_id", "test"));
-        config.getAutoTables().add(shardingAutoTableRuleConfiguration);
-        return new ArrayList<>(Collections.singleton(config));
+        result.getAutoTables().add(shardingAutoTableRuleConfiguration);
+        return new ArrayList<>(Collections.singleton(result));
     }
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateEncryptRuleBackendHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateEncryptRuleBackendHandlerTest.java
index bc1e54d..7ace988 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateEncryptRuleBackendHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateEncryptRuleBackendHandlerTest.java
@@ -44,6 +44,7 @@ import org.mockito.junit.MockitoJUnitRunner;
 
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Properties;
 
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
@@ -100,22 +101,20 @@ public final class CreateEncryptRuleBackendHandlerTest {
         
when(sqlStatement.getRules()).thenReturn(Collections.singletonList(encryptRuleSegment));
         handler.execute("test", sqlStatement);
     }
-
+    
     @Test(expected = InvalidEncryptorsException.class)
     public void assertExecuteWithInvalidEncryptors() {
         EncryptRuleSegment encryptRuleSegment = new 
EncryptRuleSegment("t_encrypt", buildColumns("notExistEncryptor"));
         
when(sqlStatement.getRules()).thenReturn(Collections.singletonList(encryptRuleSegment));
         handler.execute("test", sqlStatement);
     }
-
+    
     private Collection<EncryptColumnSegment> buildColumns(final String 
encryptorName) {
-        EncryptColumnSegment encryptColumnSegment = new EncryptColumnSegment();
-        encryptColumnSegment.setName("user_id");
-        encryptColumnSegment.setPlainColumn("user_plain");
-        encryptColumnSegment.setCipherColumn("user_cipher");
-        FunctionSegment functionSegment = new FunctionSegment();
-        functionSegment.setAlgorithmName(encryptorName);
-        encryptColumnSegment.setEncryptor(functionSegment);
-        return Collections.singleton(encryptColumnSegment);
+        EncryptColumnSegment result = new EncryptColumnSegment();
+        result.setName("user_id");
+        result.setPlainColumn("user_plain");
+        result.setCipherColumn("user_cipher");
+        result.setEncryptor(new FunctionSegment(encryptorName, new 
Properties()));
+        return Collections.singleton(result);
     }
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingTableRuleBackendHandlerTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingTableRuleBackendHandlerTest.java
index 00a923c..9359861 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingTableRuleBackendHandlerTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/CreateShardingTableRuleBackendHandlerTest.java
@@ -39,6 +39,7 @@ import org.mockito.junit.MockitoJUnitRunner;
 
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.Properties;
 
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
@@ -86,9 +87,7 @@ public final class CreateShardingTableRuleBackendHandlerTest {
         TableRuleSegment tableRuleSegment = new TableRuleSegment();
         tableRuleSegment.setLogicTable("t_order_item");
         tableRuleSegment.setDataSources(Collections.emptyList());
-        FunctionSegment shardingAlgorithm = new FunctionSegment();
-        shardingAlgorithm.setAlgorithmName("hash_mod");
-        tableRuleSegment.setTableStrategy(shardingAlgorithm);
+        tableRuleSegment.setTableStrategy(new FunctionSegment("hash_mod", new 
Properties()));
         ResponseHeader responseHeader = handler.execute("test", sqlStatement);
         assertNotNull(responseHeader);
         assertTrue(responseHeader instanceof UpdateResponseHeader);
@@ -117,9 +116,7 @@ public final class 
CreateShardingTableRuleBackendHandlerTest {
         TableRuleSegment tableRuleSegment = new TableRuleSegment();
         tableRuleSegment.setLogicTable("t_order_item");
         tableRuleSegment.setDataSources(Collections.emptyList());
-        FunctionSegment shardingAlgorithm = new FunctionSegment();
-        shardingAlgorithm.setAlgorithmName("algorithm-not-exist");
-        tableRuleSegment.setTableStrategy(shardingAlgorithm);
+        tableRuleSegment.setTableStrategy(new 
FunctionSegment("algorithm-not-exist", new Properties()));
         
when(sqlStatement.getRules()).thenReturn(Collections.singleton(tableRuleSegment));
         handler.execute("test", sqlStatement);
     }

Reply via email to