use of com.ctrip.platform.dal.dao.client.ConnectionAction in project dal by ctripcorp.
the class DalTransactionManagerTest method testGetConnection.
@Test
public void testGetConnection() {
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 {
Assert.assertNotNull(test.getConnection(hints, DalEventEnum.BATCH_CALL));
return null;
}
};
action.operation = DalEventEnum.EXECUTE;
test.doInTransaction(action, hints);
} catch (Exception e) {
fail();
e.printStackTrace();
}
}
use of com.ctrip.platform.dal.dao.client.ConnectionAction in project dal by ctripcorp.
the class DalTransactionManagerTest method testGetCurrentDbMeta.
@Test
public void testGetCurrentDbMeta() {
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) {
fail();
e.printStackTrace();
}
assertFalse(DalTransactionManager.isInTransaction());
assertNull(DalTransactionManager.getCurrentDbMeta());
}
use of com.ctrip.platform.dal.dao.client.ConnectionAction in project dal by ctripcorp.
the class DalTransactionManagerTest method testDoInTransactionFail.
@Test
public void testDoInTransactionFail() {
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 {
throw new NullPointerException("test");
}
};
action.operation = DalEventEnum.EXECUTE;
test.doInTransaction(action, hints);
fail();
} catch (Exception e) {
assertFalse(DalTransactionManager.isInTransaction());
e.printStackTrace();
}
}
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();
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