Search in sources :

Example 6 with TestBean

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);
}
Also used : TestBean(org.apache.aries.transaction.test.TestBean) RollbackException(javax.transaction.RollbackException)

Aggregations

TestBean (org.apache.aries.transaction.test.TestBean)6 SQLException (java.sql.SQLException)1 RollbackException (javax.transaction.RollbackException)1