use of com.ctrip.platform.dal.dao.client.ConnectionAction in project dal by ctripcorp.
the class DalTransactionManagerTest method testDoInTransaction.
@Test
public void testDoInTransaction() {
final DalHints hints = new DalHints();
try {
final DalTransactionManager test = new DalTransactionManager(getDalConnectionManager());
assertFalse(DalTransactionManager.isInTransaction());
ConnectionAction<?> action = new ConnectionAction<Object>() {
public Object execute() throws Exception {
assertNotNull(DalTransactionManager.getCurrentDbMeta());
return null;
}
};
action.operation = DalEventEnum.EXECUTE;
test.doInTransaction(action, hints);
} catch (Exception e) {
e.printStackTrace();
fail();
}
assertFalse(DalTransactionManager.isInTransaction());
assertNull(DalTransactionManager.getCurrentDbMeta());
}
use of com.ctrip.platform.dal.dao.client.ConnectionAction 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