Search in sources :

Example 1 with ShardColModShardStrategy

use of com.ctrip.platform.dal.dao.strategy.ShardColModShardStrategy in project dal by ctripcorp.

the class ShardColModShardStrategyTest method testLocateDbShardByShardValue.

@Test
public void testLocateDbShardByShardValue() throws Exception {
    DalConfigure configure = DalConfigureFactory.load();
    ShardColModShardStrategy strategy = new ShardColModShardStrategy();
    Map<String, String> settings = new HashMap<String, String>();
    settings.put(ShardColModShardStrategy.COLUMNS, "id,id1");
    settings.put(ShardColModShardStrategy.MOD, "2");
    settings.put(ShardColModShardStrategy.TABLE_COLUMNS, "index,index1");
    settings.put(ShardColModShardStrategy.TABLE_MOD, "4");
    strategy.initialize(settings);
    assertEquals("0", strategy.locateDbShard(configure, logicDbName, new DalHints().setShardValue(0)));
    assertEquals("1", strategy.locateDbShard(configure, logicDbName, new DalHints().setShardValue(1)));
    assertEquals("0", strategy.locateDbShard(configure, logicDbName, new DalHints().setShardValue(2)));
    assertEquals("1", strategy.locateDbShard(configure, logicDbName, new DalHints().setShardValue(3)));
    assertEquals("0", strategy.locateDbShard(configure, logicDbName, new DalHints().setShardValue(100000000000L)));
    assertEquals("1", strategy.locateDbShard(configure, logicDbName, new DalHints().setShardValue(100000000001L)));
    assertEquals("0", strategy.locateDbShard(configure, logicDbName, new DalHints().setShardValue(100000000002L)));
    assertEquals("1", strategy.locateDbShard(configure, logicDbName, new DalHints().setShardValue(100000000003L)));
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalConfigure(com.ctrip.platform.dal.dao.configure.DalConfigure) HashMap(java.util.HashMap) ShardColModShardStrategy(com.ctrip.platform.dal.dao.strategy.ShardColModShardStrategy) Test(org.junit.Test)

Example 2 with ShardColModShardStrategy

use of com.ctrip.platform.dal.dao.strategy.ShardColModShardStrategy in project dal by ctripcorp.

the class ShardColModShardStrategyTest method testIsShardingByTableTrue.

@Test
public void testIsShardingByTableTrue() {
    ShardColModShardStrategy strategy = new ShardColModShardStrategy();
    Map<String, String> settings = new HashMap<String, String>();
    settings.put(ShardColModShardStrategy.TABLE_COLUMNS, "index,index1");
    settings.put(ShardColModShardStrategy.TABLE_MOD, "4");
    strategy.initialize(settings);
    assertTrue(strategy.isShardingByTable());
}
Also used : HashMap(java.util.HashMap) ShardColModShardStrategy(com.ctrip.platform.dal.dao.strategy.ShardColModShardStrategy) Test(org.junit.Test)

Example 3 with ShardColModShardStrategy

use of com.ctrip.platform.dal.dao.strategy.ShardColModShardStrategy in project dal by ctripcorp.

the class ShardColModShardStrategyTest method testIsShardingByDbTrue.

@Test
public void testIsShardingByDbTrue() {
    ShardColModShardStrategy strategy = new ShardColModShardStrategy();
    Map<String, String> settings = new HashMap<String, String>();
    settings.put(ShardColModShardStrategy.COLUMNS, "id,id1");
    settings.put(ShardColModShardStrategy.MOD, "2");
    strategy.initialize(settings);
    assertTrue(strategy.isShardingByDb());
}
Also used : HashMap(java.util.HashMap) ShardColModShardStrategy(com.ctrip.platform.dal.dao.strategy.ShardColModShardStrategy) Test(org.junit.Test)

Example 4 with ShardColModShardStrategy

use of com.ctrip.platform.dal.dao.strategy.ShardColModShardStrategy in project dal by ctripcorp.

the class ShardColModShardStrategyTest method testIsShardingBytableFalse.

@Test
public void testIsShardingBytableFalse() {
    ShardColModShardStrategy strategy = new ShardColModShardStrategy();
    Map<String, String> settings = new HashMap<String, String>();
    settings.put(ShardColModShardStrategy.TABLE_MOD, "4");
    strategy.initialize(settings);
    assertFalse(strategy.isShardingByTable());
}
Also used : HashMap(java.util.HashMap) ShardColModShardStrategy(com.ctrip.platform.dal.dao.strategy.ShardColModShardStrategy) Test(org.junit.Test)

Example 5 with ShardColModShardStrategy

use of com.ctrip.platform.dal.dao.strategy.ShardColModShardStrategy in project dal by ctripcorp.

the class ShardColModShardStrategyTest method testLocateTableShardByTableShard.

@Test
public void testLocateTableShardByTableShard() throws Exception {
    DalConfigure configure = DalConfigureFactory.load();
    ShardColModShardStrategy strategy = new ShardColModShardStrategy();
    Map<String, String> settings = new HashMap<String, String>();
    settings.put(ShardColModShardStrategy.COLUMNS, "id,id1");
    settings.put(ShardColModShardStrategy.MOD, "2");
    settings.put(ShardColModShardStrategy.TABLE_COLUMNS, "index,index1");
    settings.put(ShardColModShardStrategy.TABLE_MOD, "4");
    settings.put(ShardColModShardStrategy.SEPARATOR, "_");
    strategy.initialize(settings);
    assertEquals("0", strategy.locateTableShard(configure, logicDbName, tableName, new DalHints().inTableShard("0")));
    assertEquals("1", strategy.locateTableShard(configure, logicDbName, tableName, new DalHints().inTableShard("1")));
    assertEquals("2", strategy.locateTableShard(configure, logicDbName, tableName, new DalHints().inTableShard("2")));
    assertEquals("3", strategy.locateTableShard(configure, logicDbName, tableName, new DalHints().inTableShard("3")));
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalConfigure(com.ctrip.platform.dal.dao.configure.DalConfigure) HashMap(java.util.HashMap) ShardColModShardStrategy(com.ctrip.platform.dal.dao.strategy.ShardColModShardStrategy) Test(org.junit.Test)

Aggregations

ShardColModShardStrategy (com.ctrip.platform.dal.dao.strategy.ShardColModShardStrategy)16 HashMap (java.util.HashMap)16 Test (org.junit.Test)16 DalHints (com.ctrip.platform.dal.dao.DalHints)11 DalConfigure (com.ctrip.platform.dal.dao.configure.DalConfigure)11 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)2