use of com.ctrip.platform.dal.dao.client.DalConnectionManager in project dal by ctripcorp.
the class DalConnectionManagerTest method testEvaluate.
@Test
public void testEvaluate() {
boolean useMaster = true;
DalHints hints = new DalHints();
try {
DalConnectionManager test = getDalConnectionManager(noShardDb);
String id = test.evaluateShard(hints);
assertNull(id);
} catch (Exception e) {
e.printStackTrace();
fail();
}
try {
DalConnectionManager test = getDalConnectionManager(shardDb);
hints = new DalHints();
hints.inShard(1);
String id = test.evaluateShard(hints);
assertEquals("1", id);
} catch (Exception e) {
e.printStackTrace();
fail();
}
try {
DalConnectionManager test = getDalConnectionManager(shardDb);
hints = new DalHints();
hints.inShard("1");
String id = test.evaluateShard(hints);
assertEquals("1", id);
} catch (Exception e) {
e.printStackTrace();
fail();
}
try {
DalConnectionManager test = getDalConnectionManager(shardDb);
hints = new DalHints();
hints.setShardValue("3");
String id = test.evaluateShard(hints);
assertEquals("1", id);
} catch (Exception e) {
e.printStackTrace();
fail();
}
try {
DalConnectionManager test = getDalConnectionManager(shardDb);
hints = new DalHints();
hints.setShardColValue("index", "3");
String id = test.evaluateShard(hints);
assertEquals("1", id);
} catch (Exception e) {
e.printStackTrace();
fail();
}
try {
DalConnectionManager test = getDalConnectionManager(shardDb);
hints = new DalHints();
Map<String, String> shardColValues = new HashMap<>();
shardColValues.put("index", "3");
hints.setShardColValues(shardColValues);
String id = test.evaluateShard(hints);
assertEquals("1", id);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of com.ctrip.platform.dal.dao.client.DalConnectionManager in project dal by ctripcorp.
the class DalConnectionManagerTest method testDoInConnectionException.
@Test
public void testDoInConnectionException() {
final boolean useMaster = true;
final DalHints hints = new DalHints();
final String message = "testDoInConnectionException";
ConnectionAction<Object> action = null;
try {
final DalConnectionManager test = getDalConnectionManager(noShardDb);
action = new ConnectionAction<Object>() {
public Object execute() throws Exception {
connHolder = test.getNewConnection(hints, useMaster, DalEventEnum.BATCH_CALL);
statement = connHolder.getConn().createStatement();
rs = statement.executeQuery("select * from City");
rs.next();
throw new RuntimeException(message);
}
};
test.doInConnection(action, hints);
fail();
} catch (Exception e) {
e.printStackTrace();
assertNotNull(action);
assertTrue(action.conn == null);
assertTrue(action.statement == null);
assertTrue(action.rs == null);
assertTrue(action.connHolder == null);
}
}
use of com.ctrip.platform.dal.dao.client.DalConnectionManager in project dal by ctripcorp.
the class DalConnectionManagerTest method testGetNewConnection.
@Test
public void testGetNewConnection() {
boolean useMaster = true;
DalHints hints = new DalHints();
try {
DalConnectionManager test = getDalConnectionManager(noShardDb);
DalConnection conn = test.getNewConnection(hints, useMaster, DalEventEnum.BATCH_CALL);
assertNotNull(conn);
assertNotNull(conn.getConn());
conn.getConn().close();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of com.ctrip.platform.dal.dao.client.DalConnectionManager in project dal by ctripcorp.
the class DalConnectionManagerTest method testDoInConnection.
@Test
public void testDoInConnection() {
final boolean useMaster = true;
final DalHints hints = new DalHints();
try {
final DalConnectionManager test = getDalConnectionManager(noShardDb);
ConnectionAction<Object> action = new ConnectionAction<Object>() {
public Object execute() throws Exception {
connHolder = test.getNewConnection(hints, useMaster, DalEventEnum.BATCH_CALL);
statement = connHolder.getConn().createStatement();
rs = statement.executeQuery("select * from " + SqlServerTestInitializer.TABLE_NAME);
rs.next();
return null;
}
};
action.operation = DalEventEnum.EXECUTE;
test.doInConnection(action, hints);
assertTrue(action.conn == null);
assertTrue(action.statement == null);
assertTrue(action.rs == null);
assertTrue(action.connHolder == null);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
Aggregations