use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class MySqlHelperTest method replaceTest.
@Test
public void replaceTest() throws SQLException {
int count = 3;
List<Person> persons = new ArrayList<>();
for (int i = 1; i <= count; i++) {
Person pojo1 = new Person();
pojo1.setID(i);
pojo1.setName("forest" + i);
pojo1.setBirth(new Timestamp(System.currentTimeMillis()));
persons.add(pojo1);
}
client.delete(hints, persons);
KeyHolder holder = new KeyHolder();
helper.replace(holder, hints, persons);
List<Map<String, Object>> generateKeys = holder.getKeyList();
assertTrue(generateKeys.size() == 3);
assertTrue(generateKeys.get(0).containsKey("GENERATED_KEY"));
persons.get(1).setName("jack1");
helper.replace(holder, new DalHints(), persons);
Person rep = client.queryByPk(2, hints);
assertTrue(rep.getName().equals("jack1"));
client.delete(hints, persons);
}
use of com.ctrip.platform.dal.dao.DalHints in project dal by ctripcorp.
the class HATest method testFirstRetrySecondeFailOver.
@Test
public void testFirstRetrySecondeFailOver() {
hints = new DalHints();
Integer count = 0;
try {
count = database2.query(sql, new StatementParameters(), hints, new DalResultSetExtractor<Integer>() {
@Override
public Integer extract(ResultSet rs) throws SQLException {
if (0 == markCount) {
markCount++;
mockRetryThrows(hints.getHA());
}
if (1 == markCount) {
markCount++;
mockFailOverThrow(hints.getHA());
} else {
//Here fail over to the third slave
while (rs.next()) {
return rs.getInt(1);
}
}
return 0;
}
});
} catch (SQLException e) {
}
Assert.assertEquals(3, count == null ? 0 : count.intValue());
}
use of com.ctrip.platform.dal.dao.DalHints 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.DalHints 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.DalHints 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)));
}
Aggregations