Search in sources :

Example 1 with UOWAction

use of com.ibm.wsspi.uow.UOWAction in project spring-framework by spring-projects.

the class WebSphereUowTransactionManagerTests method newTransactionWithCommitException.

@Test
public void newTransactionWithCommitException() {
    final RollbackException rex = new RollbackException();
    MockUOWManager manager = new MockUOWManager() {

        @Override
        public void runUnderUOW(int type, boolean join, UOWAction action) throws UOWException {
            throw new UOWException(rex);
        }
    };
    WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
    DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
    assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
    assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
    assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
    try {
        ptm.execute(definition, new TransactionCallback<String>() {

            @Override
            public String doInTransaction(TransactionStatus status) {
                assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
                assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
                assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
                return "result";
            }
        });
        fail("Should have thrown TransactionSystemException");
    } catch (TransactionSystemException ex) {
        // expected
        assertTrue(ex.getCause() instanceof UOWException);
        assertSame(rex, ex.getRootCause());
        assertSame(rex, ex.getMostSpecificCause());
    }
    assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
    assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
    assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
    assertEquals(0, manager.getUOWTimeout());
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) UOWException(com.ibm.wsspi.uow.UOWException) TransactionStatus(org.springframework.transaction.TransactionStatus) UOWAction(com.ibm.wsspi.uow.UOWAction) TransactionSystemException(org.springframework.transaction.TransactionSystemException) RollbackException(javax.transaction.RollbackException) Test(org.junit.Test)

Aggregations

UOWAction (com.ibm.wsspi.uow.UOWAction)1 UOWException (com.ibm.wsspi.uow.UOWException)1 RollbackException (javax.transaction.RollbackException)1 Test (org.junit.Test)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionSystemException (org.springframework.transaction.TransactionSystemException)1 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)1