From 6857281339027484e510ba7fa993cec805a04fb9 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Fri, 1 Sep 2017 18:25:54 +0800 Subject: [PATCH] for #98 add test case for spring namespace --- .../ddframe/rdb/sharding/AllSpringTests.java | 8 +++-- ...ForMasterSlaveWithDefaultStrategyTest.java | 34 +++++++++++++++++++ ...aceForMasterSlaveWithStrategyRefTest.java} | 4 +-- ...aceForMasterSlaveWithStrategyTypeTest.java | 34 +++++++++++++++++++ ...paceForMasterSlaveWithDefaultStrategy.xml} | 0 ...NamespaceForMasterSlaveWithStrategyRef.xml | 31 +++++++++++++++++ ...amespaceForMasterSlaveWithStrategyType.xml | 29 ++++++++++++++++ .../MasterSlaveLoadBalanceStrategyType.java | 6 ++-- 8 files changed, 139 insertions(+), 7 deletions(-) create mode 100644 sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/spring/cases/namespace/WithNamespaceForMasterSlaveWithDefaultStrategyTest.java rename sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/spring/cases/namespace/{WithNamespaceForMasterSlaveTest.java => WithNamespaceForMasterSlaveWithStrategyRefTest.java} (87%) create mode 100644 sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/spring/cases/namespace/WithNamespaceForMasterSlaveWithStrategyTypeTest.java rename sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/resources/META-INF/rdb/namespace/{withNamespaceForMasterSlave.xml => withNamespaceForMasterSlaveWithDefaultStrategy.xml} (100%) create mode 100644 sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/resources/META-INF/rdb/namespace/withNamespaceForMasterSlaveWithStrategyRef.xml create mode 100644 sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/resources/META-INF/rdb/namespace/withNamespaceForMasterSlaveWithStrategyType.xml diff --git a/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/AllSpringTests.java b/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/AllSpringTests.java index 4e59cf0bc147c..898299eeb3d32 100644 --- a/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/AllSpringTests.java +++ b/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/AllSpringTests.java @@ -27,7 +27,9 @@ import com.dangdang.ddframe.rdb.sharding.spring.cases.namespace.WithNamespaceDefaultStrategyTest; import com.dangdang.ddframe.rdb.sharding.spring.cases.namespace.WithNamespaceDifferentTablesTest; import com.dangdang.ddframe.rdb.sharding.spring.cases.namespace.WithNamespaceForIndicatedDataSourceNamesTest; -import com.dangdang.ddframe.rdb.sharding.spring.cases.namespace.WithNamespaceForMasterSlaveTest; +import com.dangdang.ddframe.rdb.sharding.spring.cases.namespace.WithNamespaceForMasterSlaveWithDefaultStrategyTest; +import com.dangdang.ddframe.rdb.sharding.spring.cases.namespace.WithNamespaceForMasterSlaveWithStrategyRefTest; +import com.dangdang.ddframe.rdb.sharding.spring.cases.namespace.WithNamespaceForMasterSlaveWithStrategyTypeTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @@ -44,7 +46,9 @@ WithoutNamespaceDefaultStrategyTest.class, WithNamespaceDifferentTablesTest.class, WithNamespaceForIndicatedDataSourceNamesTest.class, - WithNamespaceForMasterSlaveTest.class, + WithNamespaceForMasterSlaveWithDefaultStrategyTest.class, + WithNamespaceForMasterSlaveWithStrategyRefTest.class, + WithNamespaceForMasterSlaveWithStrategyTypeTest.class, GenerateKeyDBUnitTest.class }) public class AllSpringTests { diff --git a/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/spring/cases/namespace/WithNamespaceForMasterSlaveWithDefaultStrategyTest.java b/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/spring/cases/namespace/WithNamespaceForMasterSlaveWithDefaultStrategyTest.java new file mode 100644 index 0000000000000..2be5049a4e4bf --- /dev/null +++ b/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/spring/cases/namespace/WithNamespaceForMasterSlaveWithDefaultStrategyTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 1999-2015 dangdang.com. + *

+ * Licensed 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 com.dangdang.ddframe.rdb.sharding.spring.cases.namespace; + +import com.dangdang.ddframe.rdb.sharding.spring.AbstractShardingBothDataBasesAndTablesSpringDBUnitTest; +import org.springframework.test.context.ContextConfiguration; + +import java.util.Arrays; +import java.util.List; + +@ContextConfiguration(locations = "classpath:META-INF/rdb/namespace/withNamespaceForMasterSlaveWithDefaultStrategy.xml") +public final class WithNamespaceForMasterSlaveWithDefaultStrategyTest extends AbstractShardingBothDataBasesAndTablesSpringDBUnitTest { + + @Override + protected List getSchemaFiles() { + return Arrays.asList("schema/dbtbl_0_master.sql", "schema/dbtbl_0_slave_0.sql", "schema/dbtbl_0_slave_1.sql", + "schema/dbtbl_1_master.sql", "schema/dbtbl_1_slave_0.sql", "schema/dbtbl_1_slave_1.sql"); + } +} diff --git a/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/spring/cases/namespace/WithNamespaceForMasterSlaveTest.java b/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/spring/cases/namespace/WithNamespaceForMasterSlaveWithStrategyRefTest.java similarity index 87% rename from sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/spring/cases/namespace/WithNamespaceForMasterSlaveTest.java rename to sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/spring/cases/namespace/WithNamespaceForMasterSlaveWithStrategyRefTest.java index 0c6e7d4adb12b..a1afd22b62e9b 100644 --- a/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/spring/cases/namespace/WithNamespaceForMasterSlaveTest.java +++ b/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/spring/cases/namespace/WithNamespaceForMasterSlaveWithStrategyRefTest.java @@ -23,8 +23,8 @@ import java.util.Arrays; import java.util.List; -@ContextConfiguration(locations = "classpath:META-INF/rdb/namespace/withNamespaceForMasterSlave.xml") -public final class WithNamespaceForMasterSlaveTest extends AbstractShardingBothDataBasesAndTablesSpringDBUnitTest { +@ContextConfiguration(locations = "classpath:META-INF/rdb/namespace/withNamespaceForMasterSlaveWithStrategyRef.xml") +public final class WithNamespaceForMasterSlaveWithStrategyRefTest extends AbstractShardingBothDataBasesAndTablesSpringDBUnitTest { @Override protected List getSchemaFiles() { diff --git a/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/spring/cases/namespace/WithNamespaceForMasterSlaveWithStrategyTypeTest.java b/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/spring/cases/namespace/WithNamespaceForMasterSlaveWithStrategyTypeTest.java new file mode 100644 index 0000000000000..91f96671f1e21 --- /dev/null +++ b/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/java/com/dangdang/ddframe/rdb/sharding/spring/cases/namespace/WithNamespaceForMasterSlaveWithStrategyTypeTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 1999-2015 dangdang.com. + *

+ * Licensed 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 com.dangdang.ddframe.rdb.sharding.spring.cases.namespace; + +import com.dangdang.ddframe.rdb.sharding.spring.AbstractShardingBothDataBasesAndTablesSpringDBUnitTest; +import org.springframework.test.context.ContextConfiguration; + +import java.util.Arrays; +import java.util.List; + +@ContextConfiguration(locations = "classpath:META-INF/rdb/namespace/withNamespaceForMasterSlaveWithStrategyType.xml") +public final class WithNamespaceForMasterSlaveWithStrategyTypeTest extends AbstractShardingBothDataBasesAndTablesSpringDBUnitTest { + + @Override + protected List getSchemaFiles() { + return Arrays.asList("schema/dbtbl_0_master.sql", "schema/dbtbl_0_slave_0.sql", "schema/dbtbl_0_slave_1.sql", + "schema/dbtbl_1_master.sql", "schema/dbtbl_1_slave_0.sql", "schema/dbtbl_1_slave_1.sql"); + } +} diff --git a/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/resources/META-INF/rdb/namespace/withNamespaceForMasterSlave.xml b/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/resources/META-INF/rdb/namespace/withNamespaceForMasterSlaveWithDefaultStrategy.xml similarity index 100% rename from sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/resources/META-INF/rdb/namespace/withNamespaceForMasterSlave.xml rename to sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/resources/META-INF/rdb/namespace/withNamespaceForMasterSlaveWithDefaultStrategy.xml diff --git a/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/resources/META-INF/rdb/namespace/withNamespaceForMasterSlaveWithStrategyRef.xml b/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/resources/META-INF/rdb/namespace/withNamespaceForMasterSlaveWithStrategyRef.xml new file mode 100644 index 0000000000000..1a594593f5e82 --- /dev/null +++ b/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/resources/META-INF/rdb/namespace/withNamespaceForMasterSlaveWithStrategyRef.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/resources/META-INF/rdb/namespace/withNamespaceForMasterSlaveWithStrategyType.xml b/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/resources/META-INF/rdb/namespace/withNamespaceForMasterSlaveWithStrategyType.xml new file mode 100644 index 0000000000000..c30e73b72ee5e --- /dev/null +++ b/sharding-jdbc-config-parent/sharding-jdbc-config-spring/src/test/resources/META-INF/rdb/namespace/withNamespaceForMasterSlaveWithStrategyType.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/strategy/slave/MasterSlaveLoadBalanceStrategyType.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/strategy/slave/MasterSlaveLoadBalanceStrategyType.java index dcbe56fea1ab3..31f49514aacc1 100644 --- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/strategy/slave/MasterSlaveLoadBalanceStrategyType.java +++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/api/strategy/slave/MasterSlaveLoadBalanceStrategyType.java @@ -29,8 +29,8 @@ @Getter public enum MasterSlaveLoadBalanceStrategyType { - RoundRobin(new RoundRobinMasterSlaveLoadBalanceStrategy()), - Random(new RandomMasterSlaveLoadBalanceStrategy()); + ROUND_ROBIN(new RoundRobinMasterSlaveLoadBalanceStrategy()), + RANDOM(new RandomMasterSlaveLoadBalanceStrategy()); private final MasterSlaveLoadBalanceStrategy strategy; @@ -40,6 +40,6 @@ public enum MasterSlaveLoadBalanceStrategyType { * @return default master-slave database load-balance strategy type */ public static MasterSlaveLoadBalanceStrategyType getDefaultStrategyType() { - return RoundRobin; + return ROUND_ROBIN; } }