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

panjuan 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 bc727f1  Optimize shadow checker (#13124)
bc727f1 is described below

commit bc727f16e7b29c5f50fbbe18c3626c34ae6ae7d2
Author: gin <[email protected]>
AuthorDate: Tue Oct 19 17:37:42 2021 +0800

    Optimize shadow checker (#13124)
---
 .../AbstractShadowRuleConfigurationChecker.java    | 49 +++++++++++-
 ...ithmProvidedShadowRuleConfigurationChecker.java | 19 ++++-
 .../checker/ShadowRuleConfigurationChecker.java    | 19 ++++-
 .../engine/determiner/ShadowDeterminerFactory.java |  3 +
 .../shardingsphere/shadow/rule/ShadowRule.java     | 22 +-----
 .../shadow/rule/checker/ShadowRuleChecker.java     | 47 +-----------
 ...ProvidedShadowRuleConfigurationCheckerTest.java | 86 +++++++++++++++++++---
 .../ShadowRuleConfigurationCheckerTest.java        | 83 +++++++++++++++++----
 .../shadow/rule/checker/ShadowRuleCheckerTest.java | 16 ----
 9 files changed, 233 insertions(+), 111 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/checker/AbstractShadowRuleConfigurationChecker.java
 
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/checker/AbstractShadowRuleConfigurationChecker.java
index 82b55f6..e1f934c 100644
--- 
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/checker/AbstractShadowRuleConfigurationChecker.java
+++ 
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/checker/AbstractShadowRuleConfigurationChecker.java
@@ -19,7 +19,15 @@ package org.apache.shardingsphere.shadow.checker;
 
 import com.google.common.base.Preconditions;
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import 
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
 import org.apache.shardingsphere.infra.config.checker.RuleConfigurationChecker;
+import 
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
+import 
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
+import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * Abstract shadow rule configuration checker.
@@ -30,8 +38,45 @@ public abstract class 
AbstractShadowRuleConfigurationChecker<T extends RuleConfi
     
     @Override
     public final void check(final String schemaName, final T config) {
-        Preconditions.checkState(isAvailableShadowRule(config), "No available 
shadow rule configuration in schema `%s`.", schemaName);
+        checkShadowRuleConfiguration(config);
+    }
+    
+    protected abstract void checkShadowRuleConfiguration(T config);
+    
+    protected void sizeCheck(final Map<String, ShadowDataSourceConfiguration> 
dataSources, final Map<String, ShadowTableConfiguration> shadowTables) {
+        Preconditions.checkState(!dataSources.isEmpty(), "No available shadow 
data sources mappings in shadow configuration.");
+        Preconditions.checkState(!shadowTables.isEmpty(), "No available shadow 
tables in shadow configuration.");
+    }
+    
+    protected void shadowAlgorithmsSizeCheck(final Map<String, 
ShadowAlgorithm> shadowAlgorithms) {
+        Preconditions.checkState(!shadowAlgorithms.isEmpty(), "No available 
shadow algorithms in shadow configuration.");
+    }
+    
+    protected void shadowAlgorithmConfigurationsSizeCheck(final Map<String, 
ShardingSphereAlgorithmConfiguration> shadowAlgorithmConfigurations) {
+        Preconditions.checkState(!shadowAlgorithmConfigurations.isEmpty(), "No 
available shadow data algorithms in shadow configuration.");
     }
     
-    protected abstract boolean isAvailableShadowRule(T config);
+    protected void shadowTableDataSourcesAutoReferences(final Map<String, 
ShadowTableConfiguration> shadowTables, final Map<String, 
ShadowDataSourceConfiguration> dataSources) {
+        if (1 == dataSources.size()) {
+            String dataSourceName = dataSources.keySet().iterator().next();
+            
shadowTables.values().stream().map(ShadowTableConfiguration::getDataSourceNames).filter(Collection::isEmpty).forEach(dataSourceNames
 -> dataSourceNames.add(dataSourceName));
+        }
+    }
+    
+    protected void shadowTableDataSourcesReferencesCheck(final Map<String, 
ShadowTableConfiguration> shadowTables, final Map<String, 
ShadowDataSourceConfiguration> dataSources) {
+        Set<String> dataSourceNames = dataSources.keySet();
+        shadowTables.forEach((key, value) -> {
+            for (String each : value.getDataSourceNames()) {
+                Preconditions.checkState(dataSourceNames.contains(each), "No 
available shadow data sources mappings in shadow table `%s`.", key);
+            }
+        });
+    }
+    
+    protected void shadowTableAlgorithmsAutoReferences(final Map<String, 
ShadowTableConfiguration> shadowTables, final Set<String> shadowAlgorithmNames) 
{
+        shadowTables.forEach((key, value) -> 
value.getShadowAlgorithmNames().removeIf(each -> 
!shadowAlgorithmNames.contains(each)));
+    }
+    
+    protected void shadowTableAlgorithmsReferencesCheck(final Map<String, 
ShadowTableConfiguration> shadowTables) {
+        shadowTables.forEach((key, value) -> 
Preconditions.checkState(!value.getShadowAlgorithmNames().isEmpty(), "No 
available shadow Algorithm configuration in shadow table `%s`.", key));
+    }
 }
diff --git 
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/checker/AlgorithmProvidedShadowRuleConfigurationChecker.java
 
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/checker/AlgorithmProvidedShadowRuleConfigurationChecker.java
index 82f765b..2dff600 100644
--- 
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/checker/AlgorithmProvidedShadowRuleConfigurationChecker.java
+++ 
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/checker/AlgorithmProvidedShadowRuleConfigurationChecker.java
@@ -18,7 +18,12 @@
 package org.apache.shardingsphere.shadow.checker;
 
 import 
org.apache.shardingsphere.shadow.algorithm.config.AlgorithmProvidedShadowRuleConfiguration;
+import 
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
+import 
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
 import org.apache.shardingsphere.shadow.constant.ShadowOrder;
+import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
+
+import java.util.Map;
 
 /**
  * Algorithm provided shadow rule configuration checker.
@@ -26,8 +31,18 @@ import org.apache.shardingsphere.shadow.constant.ShadowOrder;
 public final class AlgorithmProvidedShadowRuleConfigurationChecker extends 
AbstractShadowRuleConfigurationChecker<AlgorithmProvidedShadowRuleConfiguration>
 {
     
     @Override
-    protected boolean isAvailableShadowRule(final 
AlgorithmProvidedShadowRuleConfiguration config) {
-        return true;
+    protected void checkShadowRuleConfiguration(final 
AlgorithmProvidedShadowRuleConfiguration config) {
+        if (config.isEnable()) {
+            Map<String, ShadowDataSourceConfiguration> dataSources = 
config.getDataSources();
+            Map<String, ShadowTableConfiguration> shadowTables = 
config.getTables();
+            Map<String, ShadowAlgorithm> shadowAlgorithms = 
config.getShadowAlgorithms();
+            sizeCheck(dataSources, shadowTables);
+            shadowAlgorithmsSizeCheck(shadowAlgorithms);
+            shadowTableDataSourcesAutoReferences(shadowTables, dataSources);
+            shadowTableDataSourcesReferencesCheck(shadowTables, dataSources);
+            shadowTableAlgorithmsAutoReferences(shadowTables, 
shadowAlgorithms.keySet());
+            shadowTableAlgorithmsReferencesCheck(shadowTables);
+        }
     }
     
     @Override
diff --git 
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
 
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
index bc66261..d335ddd 100644
--- 
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
+++ 
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationChecker.java
@@ -17,17 +17,32 @@
 
 package org.apache.shardingsphere.shadow.checker;
 
+import 
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
 import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
+import 
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
+import 
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
 import org.apache.shardingsphere.shadow.constant.ShadowOrder;
 
+import java.util.Map;
+
 /**
  * Shadow rule configuration checker.
  */
 public final class ShadowRuleConfigurationChecker extends 
AbstractShadowRuleConfigurationChecker<ShadowRuleConfiguration> {
     
     @Override
-    protected boolean isAvailableShadowRule(final ShadowRuleConfiguration 
config) {
-        return true;
+    protected void checkShadowRuleConfiguration(final ShadowRuleConfiguration 
config) {
+        if (config.isEnable()) {
+            Map<String, ShadowDataSourceConfiguration> dataSources = 
config.getDataSources();
+            Map<String, ShadowTableConfiguration> shadowTables = 
config.getTables();
+            Map<String, ShardingSphereAlgorithmConfiguration> 
shadowAlgorithmConfigurations = config.getShadowAlgorithms();
+            sizeCheck(dataSources, shadowTables);
+            
shadowAlgorithmConfigurationsSizeCheck(shadowAlgorithmConfigurations);
+            shadowTableDataSourcesAutoReferences(shadowTables, dataSources);
+            shadowTableDataSourcesReferencesCheck(shadowTables, dataSources);
+            shadowTableAlgorithmsAutoReferences(shadowTables, 
shadowAlgorithmConfigurations.keySet());
+            shadowTableAlgorithmsReferencesCheck(shadowTables);
+        }
     }
     
     @Override
diff --git 
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/ShadowDeterminerFactory.java
 
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/ShadowDeterminerFactory.java
index 4e1f2b2..a488434 100644
--- 
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/ShadowDeterminerFactory.java
+++ 
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/route/engine/determiner/ShadowDeterminerFactory.java
@@ -17,6 +17,8 @@
 
 package org.apache.shardingsphere.shadow.route.engine.determiner;
 
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
 import 
org.apache.shardingsphere.shadow.algorithm.shadow.ShadowAlgorithmException;
 import 
org.apache.shardingsphere.shadow.api.shadow.column.ColumnShadowAlgorithm;
 import org.apache.shardingsphere.shadow.api.shadow.note.NoteShadowAlgorithm;
@@ -27,6 +29,7 @@ import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
 /**
  * Shadow determiner factory.
  */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
 public final class ShadowDeterminerFactory {
     
     /**
diff --git 
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
 
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
index d05cb52..af0e4cc 100644
--- 
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
+++ 
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
@@ -82,38 +82,18 @@ public final class ShadowRule implements SchemaRule, 
DataSourceContainedRule {
     }
     
     private void initShadowTableRules(final Map<String, 
ShadowTableConfiguration> tables) {
-        ShadowRuleChecker.checkShadowTables(tables);
         tables.forEach((key, value) -> {
             Collection<String> tableShadowAlgorithmNames = 
value.getShadowAlgorithmNames();
-            uselessShadowAlgorithmFilter(tableShadowAlgorithmNames, 
shadowAlgorithms);
             ShadowRuleChecker.checkTableShadowAlgorithms(key, 
tableShadowAlgorithmNames, shadowAlgorithms);
-            shadowTableRules.put(key, new ShadowTableRule(key, 
getDataSourceName(value), tableShadowAlgorithmNames));
+            shadowTableRules.put(key, new ShadowTableRule(key, 
value.getDataSourceNames(), tableShadowAlgorithmNames));
         });
     }
     
-    private Collection<String> getDataSourceName(final 
ShadowTableConfiguration shadowTableConfiguration) {
-        Collection<String> result = new LinkedList<>();
-        Collection<String> dataSourceNames = 
shadowTableConfiguration.getDataSourceNames();
-        if (1 == shadowDataSourceMappings.size() && dataSourceNames.isEmpty()) 
{
-            result.add(shadowDataSourceMappings.keySet().iterator().next());
-            return result;
-        }
-        result = dataSourceNames.stream().filter(each -> null != 
shadowDataSourceMappings.get(each)).collect(Collectors.toCollection(LinkedList::new));
-        ShadowRuleChecker.checkShadowTableDataSources(result);
-        return result;
-    }
-    
-    private void uselessShadowAlgorithmFilter(final Collection<String> 
tableShadowAlgorithmNames, final Map<String, ShadowAlgorithm> shadowAlgorithms) 
{
-        tableShadowAlgorithmNames.removeIf(each -> 
Objects.isNull(shadowAlgorithms.get(each)));
-    }
-    
     private void initShadowAlgorithms(final Map<String, ShadowAlgorithm> 
shadowAlgorithms) {
-        ShadowRuleChecker.checkShadowAlgorithms(shadowAlgorithms);
         this.shadowAlgorithms.putAll(shadowAlgorithms);
     }
     
     private void initShadowDataSourceMappings(final Map<String, 
ShadowDataSourceConfiguration> dataSources) {
-        ShadowRuleChecker.checkDataSources(dataSources);
         dataSources.forEach((key, value) -> shadowDataSourceMappings.put(key, 
new ShadowDataSourceRule(value.getSourceDataSourceName(), 
value.getShadowDataSourceName())));
     }
     
diff --git 
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/checker/ShadowRuleChecker.java
 
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/checker/ShadowRuleChecker.java
index 71b557e..79d3a8a 100644
--- 
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/checker/ShadowRuleChecker.java
+++ 
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rule/checker/ShadowRuleChecker.java
@@ -18,8 +18,6 @@
 package org.apache.shardingsphere.shadow.rule.checker;
 
 import com.google.common.base.Preconditions;
-import 
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
-import 
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
 import org.apache.shardingsphere.shadow.api.shadow.ShadowOperationType;
 import 
org.apache.shardingsphere.shadow.api.shadow.column.ColumnShadowAlgorithm;
 import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
@@ -37,42 +35,6 @@ import java.util.stream.Collectors;
 public final class ShadowRuleChecker {
     
     /**
-     * Check data sources mappings size.
-     *
-     * @param dataSources data sources mappings
-     */
-    public static void checkDataSources(final Map<String, 
ShadowDataSourceConfiguration> dataSources) {
-        Preconditions.checkState(!dataSources.isEmpty(), "No available shadow 
data sources mappings in shadow configuration.");
-    }
-    
-    /**
-     * Check shadow tables size.
-     *
-     * @param shadowTables shadow tables
-     */
-    public static void checkShadowTables(final Map<String, 
ShadowTableConfiguration> shadowTables) {
-        Preconditions.checkState(!shadowTables.isEmpty(), "No available shadow 
tables in shadow configuration.");
-    }
-    
-    /**
-     * Check shadow table data sources.
-     *
-     * @param shadowTableDataSources shadow table sata sources
-     */
-    public static void checkShadowTableDataSources(final Collection<String> 
shadowTableDataSources) {
-        Preconditions.checkState(!shadowTableDataSources.isEmpty(), "No 
available shadow data sources in shadow table.");
-    }
-    
-    /**
-     * Check shadow algorithms size.
-     *
-     * @param shadowAlgorithms shadow algorithms
-     */
-    public static void checkShadowAlgorithms(final Map<String, 
ShadowAlgorithm> shadowAlgorithms) {
-        Preconditions.checkState(!shadowAlgorithms.isEmpty(), "No available 
shadow data algorithms in shadow configuration.");
-    }
-    
-    /**
      * Check table shadow algorithms.
      *
      * @param tableName table name
@@ -80,10 +42,13 @@ public final class ShadowRuleChecker {
      * @param shadowAlgorithms shadow algorithms
      */
     public static void checkTableShadowAlgorithms(final String tableName, 
final Collection<String> tableShadowAlgorithmNames, final Map<String, 
ShadowAlgorithm> shadowAlgorithms) {
-        Preconditions.checkState(!tableShadowAlgorithmNames.isEmpty(), "No 
available shadow Algorithm configuration in shadow table `%s`.", tableName);
         checkTableColumnShadowAlgorithms(tableName, 
createTableShadowAlgorithms(tableShadowAlgorithmNames, shadowAlgorithms));
     }
     
+    private static Collection<ShadowAlgorithm> 
createTableShadowAlgorithms(final Collection<String> tableShadowAlgorithmNames, 
final Map<String, ShadowAlgorithm> shadowAlgorithms) {
+        return 
tableShadowAlgorithmNames.stream().map(shadowAlgorithms::get).filter(shadowAlgorithm
 -> 
!Objects.isNull(shadowAlgorithm)).collect(Collectors.toCollection(LinkedList::new));
+    }
+    
     private static void checkTableColumnShadowAlgorithms(final String 
tableName, final Collection<ShadowAlgorithm> tableShadowAlgorithms) {
         int[] operationCount = new int[4];
         tableShadowAlgorithms.stream().filter(each -> each instanceof 
ColumnShadowAlgorithm).forEach(each -> checkTableColumnShadowAlgorithm(each, 
operationCount, tableName));
@@ -121,8 +86,4 @@ public final class ShadowRuleChecker {
         Preconditions.checkState(operationCount <= 1, "Column shadow algorithm 
`%s` operation only supports one column mapping in shadow table `%s`.",
                 shadowOperationType.name(), tableName);
     }
-    
-    private static Collection<ShadowAlgorithm> 
createTableShadowAlgorithms(final Collection<String> tableShadowAlgorithmNames, 
final Map<String, ShadowAlgorithm> shadowAlgorithms) {
-        return 
tableShadowAlgorithmNames.stream().map(shadowAlgorithms::get).filter(shadowAlgorithm
 -> 
!Objects.isNull(shadowAlgorithm)).collect(Collectors.toCollection(LinkedList::new));
-    }
 }
diff --git 
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/checker/AlgorithmProvidedShadowRuleConfigurationCheckerTest.java
 
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/checker/AlgorithmProvidedShadowRuleConfigurationCheckerTest.java
index 70627a6..f8740b8 100644
--- 
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/checker/AlgorithmProvidedShadowRuleConfigurationCheckerTest.java
+++ 
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/checker/AlgorithmProvidedShadowRuleConfigurationCheckerTest.java
@@ -19,27 +19,89 @@ package org.apache.shardingsphere.shadow.checker;
 
 import org.apache.shardingsphere.infra.config.checker.RuleConfigurationChecker;
 import 
org.apache.shardingsphere.shadow.algorithm.config.AlgorithmProvidedShadowRuleConfiguration;
-import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.ordered.OrderedSPIRegistry;
+import 
org.apache.shardingsphere.shadow.algorithm.shadow.column.ColumnRegexMatchShadowAlgorithm;
+import 
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
+import 
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
+import org.apache.shardingsphere.shadow.constant.ShadowOrder;
+import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
+import org.junit.Before;
 import org.junit.Test;
 
-import java.util.Collections;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Properties;
 
-import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
 
 public final class AlgorithmProvidedShadowRuleConfigurationCheckerTest {
     
-    static {
-        ShardingSphereServiceLoader.register(RuleConfigurationChecker.class);
+    private RuleConfigurationChecker<AlgorithmProvidedShadowRuleConfiguration> 
checker;
+    
+    @Before
+    public void init() {
+        checker = new AlgorithmProvidedShadowRuleConfigurationChecker();
+    }
+    
+    @Test
+    public void assertCheck() {
+        checker.check("", createAlgorithmProvidedShadowRuleConfiguration());
+    }
+    
+    private AlgorithmProvidedShadowRuleConfiguration 
createAlgorithmProvidedShadowRuleConfiguration() {
+        AlgorithmProvidedShadowRuleConfiguration result = new 
AlgorithmProvidedShadowRuleConfiguration();
+        result.setEnable(true);
+        result.setShadowAlgorithms(createShadowAlgorithms());
+        result.setDataSources(createDataSources());
+        result.setTables(createTables());
+        return result;
+    }
+    
+    private Map<String, ShadowTableConfiguration> createTables() {
+        Map<String, ShadowTableConfiguration> result = new LinkedHashMap<>();
+        Collection<String> dataSourceNames = new LinkedList<>();
+        Collection<String> shadowAlgorithmNames = new LinkedList<>();
+        shadowAlgorithmNames.add("user-id-insert-match-algorithm");
+        result.put("t_order", new ShadowTableConfiguration(dataSourceNames, 
shadowAlgorithmNames));
+        return result;
+    }
+    
+    private Map<String, ShadowDataSourceConfiguration> createDataSources() {
+        Map<String, ShadowDataSourceConfiguration> result = new 
LinkedHashMap<>();
+        result.put("shadow-data-source", new 
ShadowDataSourceConfiguration("ds", "ds_shadow"));
+        return result;
+    }
+    
+    private Map<String, ShadowAlgorithm> createShadowAlgorithms() {
+        Map<String, ShadowAlgorithm> result = new LinkedHashMap<>();
+        result.put("user-id-insert-match-algorithm", 
createColumnRegexMatchShadowAlgorithm());
+        return result;
+    }
+    
+    private ShadowAlgorithm createColumnRegexMatchShadowAlgorithm() {
+        ColumnRegexMatchShadowAlgorithm result = new 
ColumnRegexMatchShadowAlgorithm();
+        result.setProps(createProperties());
+        result.init();
+        return result;
+    }
+    
+    private Properties createProperties() {
+        Properties properties = new Properties();
+        properties.setProperty("column", "shadow");
+        properties.setProperty("operation", "insert");
+        properties.setProperty("regex", "[1]");
+        return properties;
+    }
+    
+    @Test
+    public void assertGetOrder() {
+        assertThat(checker.getOrder() == ShadowOrder.ALGORITHM_PROVIDER_ORDER, 
is(true));
     }
     
-    @SuppressWarnings("rawtypes")
     @Test
-    public void assertValidCheck() {
-        AlgorithmProvidedShadowRuleConfiguration config = 
mock(AlgorithmProvidedShadowRuleConfiguration.class);
-        RuleConfigurationChecker checker = 
OrderedSPIRegistry.getRegisteredServices(RuleConfigurationChecker.class, 
Collections.singletonList(config)).get(config);
-        assertThat(checker, 
instanceOf(AlgorithmProvidedShadowRuleConfigurationChecker.class));
+    public void assertGetTypeClass() {
+        assertThat(checker.getTypeClass() == 
AlgorithmProvidedShadowRuleConfiguration.class, is(true));
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationCheckerTest.java
 
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationCheckerTest.java
index 9980b88..dc1f6fe 100644
--- 
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationCheckerTest.java
+++ 
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/checker/ShadowRuleConfigurationCheckerTest.java
@@ -17,30 +17,87 @@
 
 package org.apache.shardingsphere.shadow.checker;
 
+import 
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
 import org.apache.shardingsphere.infra.config.checker.RuleConfigurationChecker;
 import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
-import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.ordered.OrderedSPIRegistry;
+import 
org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
+import 
org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
+import org.apache.shardingsphere.shadow.constant.ShadowOrder;
+import org.junit.Before;
 import org.junit.Test;
 
-import java.util.Collections;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Properties;
 
-import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
 
 public final class ShadowRuleConfigurationCheckerTest {
     
-    static {
-        ShardingSphereServiceLoader.register(RuleConfigurationChecker.class);
+    private RuleConfigurationChecker<ShadowRuleConfiguration> checker;
+    
+    @Before
+    public void init() {
+        checker = new ShadowRuleConfigurationChecker();
+    }
+    
+    @Test
+    public void assertCheck() {
+        checker.check("", createShadowRuleConfiguration());
+    }
+    
+    private ShadowRuleConfiguration createShadowRuleConfiguration() {
+        ShadowRuleConfiguration result = new ShadowRuleConfiguration();
+        result.setEnable(true);
+        result.setShadowAlgorithms(createShadowAlgorithmConfigurations());
+        result.setDataSources(createDataSources());
+        result.setTables(createTables());
+        return result;
+    }
+    
+    private Map<String, ShardingSphereAlgorithmConfiguration> 
createShadowAlgorithmConfigurations() {
+        Map<String, ShardingSphereAlgorithmConfiguration> result = new 
LinkedHashMap<>();
+        result.put("user-id-insert-match-algorithm", 
createShardingSphereAlgorithmConfiguration());
+        return result;
+    }
+    
+    private ShardingSphereAlgorithmConfiguration 
createShardingSphereAlgorithmConfiguration() {
+        return new 
ShardingSphereAlgorithmConfiguration("user-id-insert-match-algorithm", 
createProperties());
+    }
+    
+    private Properties createProperties() {
+        Properties properties = new Properties();
+        properties.setProperty("column", "shadow");
+        properties.setProperty("operation", "insert");
+        properties.setProperty("regex", "[1]");
+        return properties;
+    }
+    
+    private Map<String, ShadowTableConfiguration> createTables() {
+        Map<String, ShadowTableConfiguration> result = new LinkedHashMap<>();
+        Collection<String> dataSourceNames = new LinkedList<>();
+        Collection<String> shadowAlgorithmNames = new LinkedList<>();
+        shadowAlgorithmNames.add("user-id-insert-match-algorithm");
+        result.put("t_order", new ShadowTableConfiguration(dataSourceNames, 
shadowAlgorithmNames));
+        return result;
+    }
+    
+    private Map<String, ShadowDataSourceConfiguration> createDataSources() {
+        Map<String, ShadowDataSourceConfiguration> result = new 
LinkedHashMap<>();
+        result.put("shadow-data-source", new 
ShadowDataSourceConfiguration("ds", "ds_shadow"));
+        return result;
+    }
+    
+    @Test
+    public void assertGetOrder() {
+        assertThat(checker.getOrder() == ShadowOrder.ORDER, is(true));
     }
     
-    @SuppressWarnings({"rawtypes", "unchecked"})
     @Test
-    public void assertValidCheck() {
-        ShadowRuleConfiguration config = mock(ShadowRuleConfiguration.class);
-        RuleConfigurationChecker checker = 
OrderedSPIRegistry.getRegisteredServices(RuleConfigurationChecker.class, 
Collections.singletonList(config)).get(config);
-        assertThat(checker, instanceOf(ShadowRuleConfigurationChecker.class));
-        checker.check("test", config);
+    public void assertGetTypeClass() {
+        assertThat(checker.getTypeClass() == ShadowRuleConfiguration.class, 
is(true));
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rule/checker/ShadowRuleCheckerTest.java
 
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rule/checker/ShadowRuleCheckerTest.java
index 7d58606..2602d38 100644
--- 
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rule/checker/ShadowRuleCheckerTest.java
+++ 
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/rule/checker/ShadowRuleCheckerTest.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.shadow.rule.checker;
 
-import com.google.common.collect.Maps;
 import 
org.apache.shardingsphere.shadow.algorithm.shadow.column.ColumnRegexMatchShadowAlgorithm;
 import 
org.apache.shardingsphere.shadow.algorithm.shadow.note.SimpleSQLNoteShadowAlgorithm;
 import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
@@ -31,21 +30,6 @@ import java.util.Properties;
 
 public final class ShadowRuleCheckerTest {
     
-    @Test(expected = IllegalStateException.class)
-    public void assertCheckDataSources() {
-        ShadowRuleChecker.checkDataSources(Maps.newLinkedHashMap());
-    }
-    
-    @Test(expected = IllegalStateException.class)
-    public void assertCheckShadowTables() {
-        ShadowRuleChecker.checkShadowTables(Maps.newLinkedHashMap());
-    }
-    
-    @Test(expected = IllegalStateException.class)
-    public void assertCheckShadowAlgorithms() {
-        ShadowRuleChecker.checkShadowAlgorithms(Maps.newLinkedHashMap());
-    }
-    
     @Test
     public void assertCheckTableShadowAlgorithmsPass() {
         Collection<String> tableShadowAlgorithmNames = 
createTableShadowAlgorithmNames();

Reply via email to