You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2021/06/10 15:30:49 UTC

[shardingsphere] branch master updated: Add test case for ShardingRuleConfigurationChecker & AlgorithmProvidedShardingRuleConfigurationChecker (#10755)

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 5ad1c76  Add test case for ShardingRuleConfigurationChecker & AlgorithmProvidedShardingRuleConfigurationChecker (#10755)
5ad1c76 is described below

commit 5ad1c76b366549a057205d9eb5345a9f436a8431
Author: Zhu jun <zh...@163.com>
AuthorDate: Thu Jun 10 23:30:09 2021 +0800

    Add test case for ShardingRuleConfigurationChecker & AlgorithmProvidedShardingRuleConfigurationChecker (#10755)
    
    * Add test case for RuleConfigurationCheckerFactory with RuleConfigurationChecker fixture
    
    * add test case
---
 ...ovidedShardingRuleConfigurationCheckerTest.java | 68 +++++++++++++++++++++
 .../ShardingRuleConfigurationCheckerTest.java      | 69 ++++++++++++++++++++++
 2 files changed, 137 insertions(+)

diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/checker/AlgorithmProvidedShardingRuleConfigurationCheckerTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/checker/AlgorithmProvidedShardingRuleConfigurationCheckerTest.java
new file mode 100644
index 0000000..e82d12e
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/checker/AlgorithmProvidedShardingRuleConfigurationCheckerTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.rule.checker;
+
+import org.apache.shardingsphere.infra.rule.checker.RuleConfigurationChecker;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.ordered.OrderedSPIRegistry;
+import org.apache.shardingsphere.sharding.algorithm.config.AlgorithmProvidedShardingRuleConfiguration;
+import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
+import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
+import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class AlgorithmProvidedShardingRuleConfigurationCheckerTest {
+    static {
+        ShardingSphereServiceLoader.register(RuleConfigurationChecker.class);
+    }
+
+    @Test
+    public void assertCheckPass() {
+        ShardingStrategyConfiguration strategyConfiguration = mock(ShardingStrategyConfiguration.class);
+        ShardingTableRuleConfiguration ruleConfiguration = mock(ShardingTableRuleConfiguration.class);
+        ShardingAutoTableRuleConfiguration autoTableRuleConfiguration = mock(ShardingAutoTableRuleConfiguration.class);
+        AlgorithmProvidedShardingRuleConfiguration ruleConfig = mock(AlgorithmProvidedShardingRuleConfiguration.class);
+        when(ruleConfig.getTables()).thenReturn(Collections.singletonList(ruleConfiguration));
+        when(ruleConfig.getAutoTables()).thenReturn(Collections.singletonList(autoTableRuleConfiguration));
+        when(ruleConfig.getDefaultTableShardingStrategy()).thenReturn(strategyConfiguration);
+        RuleConfigurationChecker checker = OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(ruleConfig), RuleConfigurationChecker.class).get(ruleConfig);
+        assertNotNull(checker);
+        assertThat(checker, instanceOf(AlgorithmProvidedShardingRuleConfigurationChecker.class));
+        checker.check("test", ruleConfig);
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void assertCheckNoPass() {
+        AlgorithmProvidedShardingRuleConfiguration ruleConfig = mock(AlgorithmProvidedShardingRuleConfiguration.class);
+        when(ruleConfig.getTables()).thenReturn(Collections.emptyList());
+        when(ruleConfig.getAutoTables()).thenReturn(Collections.emptyList());
+        when(ruleConfig.getDefaultTableShardingStrategy()).thenReturn(null);
+        RuleConfigurationChecker checker = OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(ruleConfig), RuleConfigurationChecker.class).get(ruleConfig);
+        assertNotNull(checker);
+        assertThat(checker, instanceOf(AlgorithmProvidedShardingRuleConfigurationChecker.class));
+        checker.check("test", ruleConfig);
+    }
+}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/checker/ShardingRuleConfigurationCheckerTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/checker/ShardingRuleConfigurationCheckerTest.java
new file mode 100644
index 0000000..71781bf
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/checker/ShardingRuleConfigurationCheckerTest.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.sharding.rule.checker;
+
+import org.apache.shardingsphere.infra.rule.checker.RuleConfigurationChecker;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.ordered.OrderedSPIRegistry;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
+import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
+import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ShardingRuleConfigurationCheckerTest {
+
+    static {
+        ShardingSphereServiceLoader.register(RuleConfigurationChecker.class);
+    }
+
+    @Test
+    public void assertCheckPass() {
+        ShardingStrategyConfiguration strategyConfiguration = mock(ShardingStrategyConfiguration.class);
+        ShardingTableRuleConfiguration ruleConfiguration = mock(ShardingTableRuleConfiguration.class);
+        ShardingAutoTableRuleConfiguration autoTableRuleConfiguration = mock(ShardingAutoTableRuleConfiguration.class);
+        ShardingRuleConfiguration ruleConfig = mock(ShardingRuleConfiguration.class);
+        when(ruleConfig.getTables()).thenReturn(Collections.singletonList(ruleConfiguration));
+        when(ruleConfig.getAutoTables()).thenReturn(Collections.singletonList(autoTableRuleConfiguration));
+        when(ruleConfig.getDefaultTableShardingStrategy()).thenReturn(strategyConfiguration);
+        RuleConfigurationChecker checker = OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(ruleConfig), RuleConfigurationChecker.class).get(ruleConfig);
+        assertNotNull(checker);
+        assertThat(checker, instanceOf(ShardingRuleConfigurationChecker.class));
+        checker.check("test", ruleConfig);
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void assertCheckNoPass() {
+        ShardingRuleConfiguration ruleConfig = mock(ShardingRuleConfiguration.class);
+        when(ruleConfig.getTables()).thenReturn(Collections.emptyList());
+        when(ruleConfig.getAutoTables()).thenReturn(Collections.emptyList());
+        when(ruleConfig.getDefaultTableShardingStrategy()).thenReturn(null);
+        RuleConfigurationChecker checker = OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(ruleConfig), RuleConfigurationChecker.class).get(ruleConfig);
+        assertNotNull(checker);
+        assertThat(checker, instanceOf(ShardingRuleConfigurationChecker.class));
+        checker.check("test", ruleConfig);
+    }
+}