use of com.ctrip.platform.dal.dao.client.DalTransactionManager in project dal by ctripcorp.
the class DalTransactionManagerTest method testRegister.
@Test
public void testRegister() {
final DalHints hints = new DalHints();
final DalTransactionListener testListener = new DalTransactionListener() {
@Override
public void beforeCommit() {
}
@Override
public void beforeRollback() {
}
@Override
public void afterCommit() {
}
@Override
public void afterRollback() {
}
};
try {
final DalTransactionManager test = new DalTransactionManager(getDalConnectionManager());
DalTransactionManager.register(testListener);
fail();
} catch (Exception e) {
}
try {
final DalTransactionManager test = new DalTransactionManager(getDalConnectionManager());
ConnectionAction<?> action = new ConnectionAction<Object>() {
public Object execute() throws Exception {
DalTransactionManager.register(testListener);
return null;
}
};
action.operation = DalEventEnum.EXECUTE;
test.doInTransaction(action, hints);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of com.ctrip.platform.dal.dao.client.DalTransactionManager in project dal by ctripcorp.
the class DalTransactionManagerTest method testIsInTransaction.
@Test
public void testIsInTransaction() {
try {
final DalTransactionManager test = new DalTransactionManager(getDalConnectionManager());
assertFalse(DalTransactionManager.isInTransaction());
ConnectionAction<?> action = new ConnectionAction<Object>() {
public Object execute() throws Exception {
Assert.assertTrue(DalTransactionManager.isInTransaction());
return null;
}
};
action.operation = DalEventEnum.EXECUTE;
test.doInTransaction(action, new DalHints());
} catch (Exception e) {
fail();
e.printStackTrace();
}
}
use of com.ctrip.platform.dal.dao.client.DalTransactionManager in project dal by ctripcorp.
the class DalTransactionManagerTest method testClearCurrentTransaction.
@Test
public void testClearCurrentTransaction() {
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.DalTransactionManager in project dal by ctripcorp.
the class DalTransactionManagerTest method testRollbackListeners.
@Test
public void testRollbackListeners() {
final DalHints hints = new DalHints();
final DalTransactionListener testListener = new DalTransactionListener() {
@Override
public void beforeCommit() {
}
@Override
public void beforeRollback() {
Assert.assertTrue(DalTransactionManager.isInTransaction());
}
@Override
public void afterCommit() {
fail();
}
@Override
public void afterRollback() {
Assert.assertFalse(DalTransactionManager.isInTransaction());
}
};
final DalTransactionListener testListener1 = new DalTransactionListener() {
@Override
public void beforeCommit() throws SQLException {
throw new SQLException();
}
@Override
public void beforeRollback() {
Assert.assertTrue(DalTransactionManager.isInTransaction());
}
@Override
public void afterCommit() {
fail();
}
@Override
public void afterRollback() {
Assert.assertFalse(DalTransactionManager.isInTransaction());
}
};
try {
final DalTransactionManager test = new DalTransactionManager(getDalConnectionManager());
ConnectionAction<?> action = new ConnectionAction<Object>() {
public Object execute() throws Exception {
DalTransactionManager.register(testListener);
// The 2nd listener will cause transaction rollback
DalTransactionManager.register(testListener1);
return null;
}
};
action.operation = DalEventEnum.EXECUTE;
test.doInTransaction(action, hints);
fail();
} catch (Exception e) {
}
}
use of com.ctrip.platform.dal.dao.client.DalTransactionManager in project dal by ctripcorp.
the class DalTransactionManagerTest method testGetCurrentListeners.
@Test
public void testGetCurrentListeners() {
final DalHints hints = new DalHints();
final DalTransactionListener testListener = new DalTransactionListener() {
@Override
public void beforeCommit() {
}
@Override
public void beforeRollback() {
}
@Override
public void afterCommit() {
}
@Override
public void afterRollback() {
}
};
try {
final DalTransactionManager test = new DalTransactionManager(getDalConnectionManager());
DalTransactionManager.getCurrentListeners();
fail();
} catch (Exception e) {
}
try {
final DalTransactionManager test = new DalTransactionManager(getDalConnectionManager());
ConnectionAction<?> action = new ConnectionAction<Object>() {
public Object execute() throws Exception {
DalTransactionManager.register(testListener);
DalTransactionManager.register(testListener);
Assert.assertEquals(2, DalTransactionManager.getCurrentListeners().size());
return null;
}
};
action.operation = DalEventEnum.EXECUTE;
test.doInTransaction(action, hints);
try {
DalTransactionManager.getCurrentListeners();
fail();
} catch (Exception e) {
}
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
Aggregations