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)));
}
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());
}
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());
}
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());
}
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")));
}
Aggregations