use of org.apache.aries.transaction.test.TestBean in project aries by apache.
the class AbstractIntegrationTest method assertInsertWithRuntimeExceptionRolledBack.
// Test with client transaction and runtime exception - the user transaction is rolled back
protected void assertInsertWithRuntimeExceptionRolledBack() throws Exception {
TestBean bean = getBean();
int initialRows = counter.countRows();
if (clientTransaction) {
tran.begin();
}
bean.insertRow("testWithClientTranAndWithRuntimeException", 1, null);
try {
bean.insertRow("testWithClientTranAndWithRuntimeException", 2, new RuntimeException("Dummy exception"));
} catch (RuntimeException e) {
Assert.assertEquals("Dummy exception", e.getMessage());
}
if (clientTransaction) {
try {
tran.commit();
fail("RollbackException not thrown");
} catch (RollbackException e) {
// Ignore expected
}
}
int finalRows = counter.countRows();
// In case of client transaction both are rolled back
// In case of container transaction only second insert is rolled back
assertEquals("Added rows", clientTransaction ? 0 : 1, finalRows - initialRows);
}
Aggregations