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 2020/08/14 09:00:48 UTC

[shardingsphere] branch master updated: Add test cases for rule builder (#6836)

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 db1cdbc  Add test cases for rule builder (#6836)
db1cdbc is described below

commit db1cdbc4c71378036faf28fd1fdbcd4b855a02bb
Author: Andrew <zh...@aliyun.com>
AuthorDate: Fri Aug 14 17:00:33 2020 +0800

    Add test cases for rule builder (#6836)
    
    * Add test case for MasterSlaveRuleBuilder
    
    * Add test case for ReplicaRuleBuilder
    
    * Add test case for ShadowRuleBuilder
    
    * Add test case for ShardingRuleBuilder
---
 .../rule/biulder/MasterSlaveRuleBuilderTest.java   | 50 ++++++++++++++++++++++
 .../rule/builder/ReplicaRuleBuilderTest.java       | 45 +++++++++++++++++++
 .../shadow/rule/builder/ShadowRuleBuilderTest.java | 45 +++++++++++++++++++
 .../rule/builder/ShardingRuleBuilderTest.java      | 45 +++++++++++++++++++
 4 files changed, 185 insertions(+)

diff --git a/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/rule/biulder/MasterSlaveRuleBuilderTest.java b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/rule/biulder/MasterSlaveRuleBuilderTest.java
new file mode 100644
index 0000000..e19a174
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-master-slave/shardingsphere-master-slave-common/src/test/java/org/apache/shardingsphere/masterslave/rule/biulder/MasterSlaveRuleBuilderTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.masterslave.rule.biulder;
+
+import org.apache.shardingsphere.infra.rule.ShardingSphereRuleBuilder;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.order.OrderedSPIRegistry;
+import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration;
+import org.apache.shardingsphere.masterslave.api.config.rule.MasterSlaveDataSourceRuleConfiguration;
+import org.apache.shardingsphere.masterslave.rule.MasterSlaveRule;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class MasterSlaveRuleBuilderTest {
+    
+    static {
+        ShardingSphereServiceLoader.register(ShardingSphereRuleBuilder.class);
+    }
+    
+    @Test
+    public void assertBuild() {
+        MasterSlaveRuleConfiguration ruleConfig = mock(MasterSlaveRuleConfiguration.class);
+        MasterSlaveDataSourceRuleConfiguration ruleConfiguration = new MasterSlaveDataSourceRuleConfiguration("name", "masterDataSourceName",
+                Collections.singletonList("name"), "loadBalancerName");
+        when(ruleConfig.getDataSources()).thenReturn(Collections.singletonList(ruleConfiguration));
+        ShardingSphereRuleBuilder builder = OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(ruleConfig), ShardingSphereRuleBuilder.class).get(ruleConfig);
+        assertThat(builder.build(ruleConfig, Collections.emptyList()), instanceOf(MasterSlaveRule.class));
+    }
+}
diff --git a/shardingsphere-features/shardingsphere-replica/shardingsphere-replica-common/src/test/java/org/apache/shardingsphere/replica/rule/builder/ReplicaRuleBuilderTest.java b/shardingsphere-features/shardingsphere-replica/shardingsphere-replica-common/src/test/java/org/apache/shardingsphere/replica/rule/builder/ReplicaRuleBuilderTest.java
new file mode 100644
index 0000000..97c9796
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-replica/shardingsphere-replica-common/src/test/java/org/apache/shardingsphere/replica/rule/builder/ReplicaRuleBuilderTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.replica.rule.builder;
+
+import org.apache.shardingsphere.infra.rule.ShardingSphereRuleBuilder;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.order.OrderedSPIRegistry;
+import org.apache.shardingsphere.replica.api.config.ReplicaRuleConfiguration;
+import org.apache.shardingsphere.replica.rule.ReplicaRule;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+
+public final class ReplicaRuleBuilderTest {
+    
+    static {
+        ShardingSphereServiceLoader.register(ShardingSphereRuleBuilder.class);
+    }
+    
+    @Test
+    public void assertBuild() {
+        ReplicaRuleConfiguration ruleConfig = mock(ReplicaRuleConfiguration.class);
+        ShardingSphereRuleBuilder builder = OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(ruleConfig), ShardingSphereRuleBuilder.class).get(ruleConfig);
+        assertThat(builder.build(ruleConfig, Collections.emptyList()), instanceOf(ReplicaRule.class));
+    }
+}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-common/src/test/java/org/apache/shardingsphere/shadow/rule/builder/ShadowRuleBuilderTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-common/src/test/java/org/apache/shardingsphere/shadow/rule/builder/ShadowRuleBuilderTest.java
new file mode 100644
index 0000000..5bee3a2
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-common/src/test/java/org/apache/shardingsphere/shadow/rule/builder/ShadowRuleBuilderTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.shadow.rule.builder;
+
+import org.apache.shardingsphere.infra.rule.ShardingSphereRuleBuilder;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.order.OrderedSPIRegistry;
+import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
+import org.apache.shardingsphere.shadow.rule.ShadowRule;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+
+public final class ShadowRuleBuilderTest {
+    
+    static {
+        ShardingSphereServiceLoader.register(ShardingSphereRuleBuilder.class);
+    }
+    
+    @Test
+    public void assertBuild() {
+        ShadowRuleConfiguration ruleConfig = mock(ShadowRuleConfiguration.class);
+        ShardingSphereRuleBuilder builder = OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(ruleConfig), ShardingSphereRuleBuilder.class).get(ruleConfig);
+        assertThat(builder.build(ruleConfig, Collections.emptyList()), instanceOf(ShadowRule.class));
+    }
+}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilderTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilderTest.java
new file mode 100644
index 0000000..fc5edf6
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/rule/builder/ShardingRuleBuilderTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.builder;
+
+import org.apache.shardingsphere.infra.rule.ShardingSphereRuleBuilder;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.order.OrderedSPIRegistry;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import org.apache.shardingsphere.sharding.rule.ShardingRule;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+
+public final class ShardingRuleBuilderTest {
+    
+    static {
+        ShardingSphereServiceLoader.register(ShardingSphereRuleBuilder.class);
+    }
+    
+    @Test
+    public void assertBuild() {
+        ShardingRuleConfiguration ruleConfig = mock(ShardingRuleConfiguration.class);
+        ShardingSphereRuleBuilder builder = OrderedSPIRegistry.getRegisteredServices(Collections.singletonList(ruleConfig), ShardingSphereRuleBuilder.class).get(ruleConfig);
+        assertThat(builder.build(ruleConfig, Collections.singletonList("name")), instanceOf(ShardingRule.class));
+    }
+}