Search in sources :

Example 6 with ShardingStrategy

use of com.dangdang.ddframe.rdb.sharding.router.strategy.ShardingStrategy in project sharding-jdbc by dangdangdotcom.

the class ShardingStrategyTest method assertDoStaticShardingForInsertWithoutShardingColumns.

@Test(expected = IllegalStateException.class)
public void assertDoStaticShardingForInsertWithoutShardingColumns() {
    ShardingStrategy strategy = new ShardingStrategy(Collections.singletonList("column"), null);
    strategy.doStaticSharding(SQLStatementType.INSERT, targets, Collections.<ShardingValue<?>>emptyList());
}
Also used : ShardingStrategy(com.dangdang.ddframe.rdb.sharding.router.strategy.ShardingStrategy) Test(org.junit.Test)

Example 7 with ShardingStrategy

use of com.dangdang.ddframe.rdb.sharding.router.strategy.ShardingStrategy in project sharding-jdbc by dangdangdotcom.

the class ShardingStrategyTest method assertDoDynamicShardingWithoutShardingColumns.

@Test(expected = IllegalStateException.class)
public void assertDoDynamicShardingWithoutShardingColumns() {
    ShardingStrategy strategy = new ShardingStrategy(Collections.singletonList("column"), null);
    strategy.doDynamicSharding(Collections.<ShardingValue<?>>emptyList());
}
Also used : ShardingStrategy(com.dangdang.ddframe.rdb.sharding.router.strategy.ShardingStrategy) Test(org.junit.Test)

Example 8 with ShardingStrategy

use of com.dangdang.ddframe.rdb.sharding.router.strategy.ShardingStrategy in project sharding-jdbc by dangdangdotcom.

the class ShardingStrategyTest method assertDoStaticShardingForEqualSingleKey.

@Test
public void assertDoStaticShardingForEqualSingleKey() {
    ShardingStrategy strategy = new ShardingStrategy("column", new TestSingleKeyShardingAlgorithm());
    assertThat(strategy.doStaticSharding(SQLStatementType.SELECT, targets, createShardingValues(new ShardingValue<>("logicTable", "column", "1"))), is((Collection<String>) Collections.singletonList("1")));
}
Also used : ShardingStrategy(com.dangdang.ddframe.rdb.sharding.router.strategy.ShardingStrategy) Collection(java.util.Collection) TestSingleKeyShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.api.strategy.fixture.TestSingleKeyShardingAlgorithm) Test(org.junit.Test)

Example 9 with ShardingStrategy

use of com.dangdang.ddframe.rdb.sharding.router.strategy.ShardingStrategy in project sharding-jdbc by dangdangdotcom.

the class ShardingStrategyTest method assertDoDynamicShardingForBetweenSingleKey.

@Test
public void assertDoDynamicShardingForBetweenSingleKey() {
    ShardingStrategy strategy = new ShardingStrategy("column", new TestSingleKeyShardingAlgorithm());
    assertThat(strategy.doDynamicSharding(createShardingValues(new ShardingValue<>("logicTable", "column", Range.open("1", "3")))), is((Collection<String>) Arrays.asList("1", "2", "3")));
}
Also used : ShardingStrategy(com.dangdang.ddframe.rdb.sharding.router.strategy.ShardingStrategy) Collection(java.util.Collection) TestSingleKeyShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.api.strategy.fixture.TestSingleKeyShardingAlgorithm) Test(org.junit.Test)

Example 10 with ShardingStrategy

use of com.dangdang.ddframe.rdb.sharding.router.strategy.ShardingStrategy in project sharding-jdbc by dangdangdotcom.

the class ShardingStrategyTest method assertDoDynamicShardingForEqualSingleKey.

@Test
public void assertDoDynamicShardingForEqualSingleKey() {
    ShardingStrategy strategy = new ShardingStrategy("column", new TestSingleKeyShardingAlgorithm());
    assertThat(strategy.doDynamicSharding(createShardingValues(new ShardingValue<>("logicTable", "column", "1"))), is((Collection<String>) Collections.singletonList("1")));
}
Also used : ShardingStrategy(com.dangdang.ddframe.rdb.sharding.router.strategy.ShardingStrategy) Collection(java.util.Collection) TestSingleKeyShardingAlgorithm(com.dangdang.ddframe.rdb.sharding.api.strategy.fixture.TestSingleKeyShardingAlgorithm) Test(org.junit.Test)

Aggregations

ShardingStrategy (com.dangdang.ddframe.rdb.sharding.router.strategy.ShardingStrategy)11 Test (org.junit.Test)11 Collection (java.util.Collection)8 TestSingleKeyShardingAlgorithm (com.dangdang.ddframe.rdb.sharding.api.strategy.fixture.TestSingleKeyShardingAlgorithm)6 TestMultipleKeysShardingAlgorithm (com.dangdang.ddframe.rdb.sharding.api.strategy.fixture.TestMultipleKeysShardingAlgorithm)2 ShardingValue (com.dangdang.ddframe.rdb.sharding.api.ShardingValue)1