use of com.ctrip.platform.dal.dao.configure.DalConfigure 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.configure.DalConfigure in project dal by ctripcorp.
the class ShardColModShardStrategyTest method testLocateDbShardByParameters.
@Test
public void testLocateDbShardByParameters() 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);
StatementParameters parameters = null;
parameters = new StatementParameters();
parameters.set(1, "id", Types.INTEGER, 0);
parameters.set(1, "abc", Types.INTEGER, 1);
parameters.set(1, "def", Types.INTEGER, 1);
assertEquals("0", strategy.locateDbShard(configure, logicDbName, new DalHints().setParameters(parameters)));
parameters = new StatementParameters();
parameters.set(1, "id", Types.INTEGER, 1);
parameters.set(1, "abc", Types.INTEGER, 1);
parameters.set(1, "def", Types.INTEGER, 1);
assertEquals("1", strategy.locateDbShard(configure, logicDbName, new DalHints().setParameters(parameters)));
parameters = new StatementParameters();
parameters.set(1, "id", Types.INTEGER, 2);
parameters.set(2, "abc", Types.INTEGER, 1);
parameters.set(3, "def", Types.INTEGER, 1);
assertEquals("0", strategy.locateDbShard(configure, logicDbName, new DalHints().setParameters(parameters)));
parameters = new StatementParameters();
parameters.set(1, "id", Types.INTEGER, 3);
parameters.set(2, "abc", Types.INTEGER, 1);
parameters.set(3, "def", Types.INTEGER, 1);
assertEquals("1", strategy.locateDbShard(configure, logicDbName, new DalHints().setParameters(parameters)));
parameters = new StatementParameters();
parameters.set(1, "id", Types.BIGINT, 100000000003L);
parameters.set(2, "abc", Types.INTEGER, 1);
parameters.set(3, "def", Types.INTEGER, 1);
assertEquals("1", strategy.locateDbShard(configure, logicDbName, new DalHints().setParameters(parameters)));
}
use of com.ctrip.platform.dal.dao.configure.DalConfigure in project dal by ctripcorp.
the class ShardColModShardStrategyTest method testLocateTableShardByTableShardValue.
@Test
public void testLocateTableShardByTableShardValue() 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, new DalHints().setTableShardValue("0")));
assertEquals("1", strategy.locateTableShard(configure, logicDbName, new DalHints().setTableShardValue("1")));
assertEquals("2", strategy.locateTableShard(configure, logicDbName, new DalHints().setTableShardValue("2")));
assertEquals("3", strategy.locateTableShard(configure, logicDbName, new DalHints().setTableShardValue("3")));
assertEquals("0", strategy.locateTableShard(configure, logicDbName, new DalHints().setTableShardValue("4")));
assertEquals("1", strategy.locateTableShard(configure, logicDbName, new DalHints().setTableShardValue("5")));
assertEquals("2", strategy.locateTableShard(configure, logicDbName, new DalHints().setTableShardValue("6")));
assertEquals("3", strategy.locateTableShard(configure, logicDbName, new DalHints().setTableShardValue("7")));
assertEquals("0", strategy.locateTableShard(configure, logicDbName, new DalHints().setTableShardValue(0)));
assertEquals("1", strategy.locateTableShard(configure, logicDbName, new DalHints().setTableShardValue(1)));
assertEquals("2", strategy.locateTableShard(configure, logicDbName, new DalHints().setTableShardValue(2)));
assertEquals("3", strategy.locateTableShard(configure, logicDbName, new DalHints().setTableShardValue(3)));
assertEquals("0", strategy.locateTableShard(configure, logicDbName, new DalHints().setTableShardValue(4)));
assertEquals("1", strategy.locateTableShard(configure, logicDbName, new DalHints().setTableShardValue(5)));
assertEquals("2", strategy.locateTableShard(configure, logicDbName, new DalHints().setTableShardValue(6)));
assertEquals("3", strategy.locateTableShard(configure, logicDbName, new DalHints().setTableShardValue(7)));
assertEquals("0", strategy.locateTableShard(configure, logicDbName, new DalHints().setTableShardValue(100000000004L)));
assertEquals("1", strategy.locateTableShard(configure, logicDbName, new DalHints().setTableShardValue(100000000005L)));
assertEquals("2", strategy.locateTableShard(configure, logicDbName, new DalHints().setTableShardValue(100000000006L)));
assertEquals("3", strategy.locateTableShard(configure, logicDbName, new DalHints().setTableShardValue(100000000007L)));
}
use of com.ctrip.platform.dal.dao.configure.DalConfigure 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, new DalHints().inTableShard("0")));
assertEquals("1", strategy.locateTableShard(configure, logicDbName, new DalHints().inTableShard("1")));
assertEquals("2", strategy.locateTableShard(configure, logicDbName, new DalHints().inTableShard("2")));
assertEquals("3", strategy.locateTableShard(configure, logicDbName, new DalHints().inTableShard("3")));
}
use of com.ctrip.platform.dal.dao.configure.DalConfigure in project dal by ctripcorp.
the class ShardColModShardStrategyTest method testLocateTableShardByFields.
@Test
public void testLocateTableShardByFields() 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);
Map<String, Object> fields = null;
fields = new HashMap<String, Object>();
fields.put("index", 0);
assertEquals("0", strategy.locateTableShard(configure, logicDbName, new DalHints().setFields(fields)));
fields = new HashMap<String, Object>();
fields.put("index1", 1);
assertEquals("1", strategy.locateTableShard(configure, logicDbName, new DalHints().setFields(fields)));
fields = new HashMap<String, Object>();
fields.put("index", 2);
assertEquals("2", strategy.locateTableShard(configure, logicDbName, new DalHints().setFields(fields)));
fields = new HashMap<String, Object>();
fields.put("index1", 3);
assertEquals("3", strategy.locateTableShard(configure, logicDbName, new DalHints().setFields(fields)));
fields = new HashMap<String, Object>();
fields.put("index", 4);
assertEquals("0", strategy.locateTableShard(configure, logicDbName, new DalHints().setFields(fields)));
fields = new HashMap<String, Object>();
fields.put("index1", 5);
assertEquals("1", strategy.locateTableShard(configure, logicDbName, new DalHints().setFields(fields)));
fields = new HashMap<String, Object>();
fields.put("index", 6);
assertEquals("2", strategy.locateTableShard(configure, logicDbName, new DalHints().setFields(fields)));
fields = new HashMap<String, Object>();
fields.put("index1", 7);
assertEquals("3", strategy.locateTableShard(configure, logicDbName, new DalHints().setFields(fields)));
fields = new HashMap<String, Object>();
fields.put("index1", 100000000007L);
assertEquals("3", strategy.locateTableShard(configure, logicDbName, new DalHints().setFields(fields)));
}
Aggregations