-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
for #98 add test case for spring namespace
- Loading branch information
Showing
8 changed files
with
139 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...b/sharding/spring/cases/namespace/WithNamespaceForMasterSlaveWithDefaultStrategyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 1999-2015 dangdang.com. | ||
* <p> | ||
* 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. | ||
* </p> | ||
*/ | ||
|
||
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<String> 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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
.../rdb/sharding/spring/cases/namespace/WithNamespaceForMasterSlaveWithStrategyTypeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 1999-2015 dangdang.com. | ||
* <p> | ||
* 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. | ||
* </p> | ||
*/ | ||
|
||
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<String> 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"); | ||
} | ||
} |
File renamed without changes.
31 changes: 31 additions & 0 deletions
31
.../src/test/resources/META-INF/rdb/namespace/withNamespaceForMasterSlaveWithStrategyRef.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:rdb="http://www.dangdang.com/schema/ddframe/rdb" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans | ||
http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.dangdang.com/schema/ddframe/rdb | ||
http://www.dangdang.com/schema/ddframe/rdb/rdb.xsd | ||
"> | ||
<import resource="../datasource/masterSlaveDataSource.xml" /> | ||
|
||
<bean id="randomStrategy" class="com.dangdang.ddframe.rdb.sharding.api.strategy.slave.RandomMasterSlaveLoadBalanceStrategy" /> | ||
|
||
<rdb:master-slave-data-source id="dbtbl_0" master-data-source-ref="dbtbl_0_master" slave-data-sources-ref="dbtbl_0_slave_0, dbtbl_0_slave_1" strategy-ref="randomStrategy" /> | ||
<rdb:master-slave-data-source id="dbtbl_1" master-data-source-ref="dbtbl_1_master" slave-data-sources-ref="dbtbl_1_slave_0, dbtbl_1_slave_1" strategy-ref="randomStrategy" /> | ||
|
||
<rdb:strategy id="databaseStrategy" sharding-columns="user_id" algorithm-expression="dbtbl_${user_id.longValue() % 2}"/> | ||
|
||
<rdb:strategy id="orderTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_${order_id.longValue() % 4}"/> | ||
|
||
<rdb:strategy id="orderItemTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_item_${order_id.longValue() % 4}"/> | ||
|
||
<rdb:data-source id="shardingDataSource"> | ||
<rdb:sharding-rule data-sources="dbtbl_0,dbtbl_1" default-data-source="dbtbl_0"> | ||
<rdb:table-rules> | ||
<rdb:table-rule logic-table="t_order" actual-tables="t_order_${0..3}, t_order_${0..3}" data-source-names="dbtbl_0, dbtbl_1" database-strategy="databaseStrategy" table-strategy="orderTableStrategy"/> | ||
<rdb:table-rule logic-table="t_order_item" actual-tables="t_order_item_${0..3}" data-source-names="dbtbl_${0..1}" database-strategy="databaseStrategy" table-strategy="orderItemTableStrategy"/> | ||
</rdb:table-rules> | ||
</rdb:sharding-rule> | ||
</rdb:data-source> | ||
</beans> |
29 changes: 29 additions & 0 deletions
29
...src/test/resources/META-INF/rdb/namespace/withNamespaceForMasterSlaveWithStrategyType.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:rdb="http://www.dangdang.com/schema/ddframe/rdb" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans | ||
http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.dangdang.com/schema/ddframe/rdb | ||
http://www.dangdang.com/schema/ddframe/rdb/rdb.xsd | ||
"> | ||
<import resource="../datasource/masterSlaveDataSource.xml" /> | ||
|
||
<rdb:master-slave-data-source id="dbtbl_0" master-data-source-ref="dbtbl_0_master" slave-data-sources-ref="dbtbl_0_slave_0, dbtbl_0_slave_1" strategy-type="RANDOM" /> | ||
<rdb:master-slave-data-source id="dbtbl_1" master-data-source-ref="dbtbl_1_master" slave-data-sources-ref="dbtbl_1_slave_0, dbtbl_1_slave_1" strategy-type="RANDOM" /> | ||
|
||
<rdb:strategy id="databaseStrategy" sharding-columns="user_id" algorithm-expression="dbtbl_${user_id.longValue() % 2}"/> | ||
|
||
<rdb:strategy id="orderTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_${order_id.longValue() % 4}"/> | ||
|
||
<rdb:strategy id="orderItemTableStrategy" sharding-columns="order_id" algorithm-expression="t_order_item_${order_id.longValue() % 4}"/> | ||
|
||
<rdb:data-source id="shardingDataSource"> | ||
<rdb:sharding-rule data-sources="dbtbl_0,dbtbl_1" default-data-source="dbtbl_0"> | ||
<rdb:table-rules> | ||
<rdb:table-rule logic-table="t_order" actual-tables="t_order_${0..3}, t_order_${0..3}" data-source-names="dbtbl_0, dbtbl_1" database-strategy="databaseStrategy" table-strategy="orderTableStrategy"/> | ||
<rdb:table-rule logic-table="t_order_item" actual-tables="t_order_item_${0..3}" data-source-names="dbtbl_${0..1}" database-strategy="databaseStrategy" table-strategy="orderItemTableStrategy"/> | ||
</rdb:table-rules> | ||
</rdb:sharding-rule> | ||
</rdb:data-source> | ||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters