Search in sources :

Example 16 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.

the class EnlistResourceDuringCommit method testEnlistResourceDuringBeforeCompletion.

@Test
public void testEnlistResourceDuringBeforeCompletion() throws IllegalStateException, RollbackException, SystemException, SecurityException, HeuristicMixedException, HeuristicRollbackException {
    final TransactionImple tx = new TransactionImple(0);
    tx.registerSynchronization(new Synchronization() {

        @Override
        public void beforeCompletion() {
            System.out.println(new Throwable().getStackTrace()[0].getMethodName());
            try {
                tx.enlistResource(new XAResource() {

                    @Override
                    public void start(Xid arg0, int arg1) throws XAException {
                        System.out.println(new Throwable().getStackTrace()[0].getMethodName());
                    }

                    @Override
                    public boolean setTransactionTimeout(int arg0) throws XAException {
                        System.out.println(new Throwable().getStackTrace()[0].getMethodName());
                        return false;
                    }

                    @Override
                    public void rollback(Xid arg0) throws XAException {
                        System.out.println(new Throwable().getStackTrace()[0].getMethodName());
                    }

                    @Override
                    public Xid[] recover(int arg0) throws XAException {
                        System.out.println(new Throwable().getStackTrace()[0].getMethodName());
                        return null;
                    }

                    @Override
                    public int prepare(Xid arg0) throws XAException {
                        System.out.println(new Throwable().getStackTrace()[0].getMethodName());
                        return 0;
                    }

                    @Override
                    public boolean isSameRM(XAResource arg0) throws XAException {
                        System.out.println(new Throwable().getStackTrace()[0].getMethodName());
                        return false;
                    }

                    @Override
                    public int getTransactionTimeout() throws XAException {
                        System.out.println(new Throwable().getStackTrace()[0].getMethodName());
                        return 0;
                    }

                    @Override
                    public void forget(Xid arg0) throws XAException {
                        System.out.println(new Throwable().getStackTrace()[0].getMethodName());
                    }

                    @Override
                    public void end(Xid arg0, int arg1) throws XAException {
                        System.out.println(new Throwable().getStackTrace()[0].getMethodName());
                    }

                    @Override
                    public void commit(Xid arg0, boolean arg1) throws XAException {
                        System.out.println(new Throwable().getStackTrace()[0].getMethodName());
                    }
                });
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (RollbackException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SystemException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        @Override
        public void afterCompletion(int status) {
            System.out.println(new Throwable().getStackTrace()[0].getMethodName());
        }
    });
    tx.commit();
}
Also used : XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) SystemException(javax.transaction.SystemException) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) Synchronization(javax.transaction.Synchronization) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) RollbackException(javax.transaction.RollbackException) Test(org.junit.Test)

Example 17 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.

the class ExceptionDeferrerTest method testCheckDeferredHeuristicRollbackFirstResourceFails.

@Test
public void testCheckDeferredHeuristicRollbackFirstResourceFails() throws Exception {
    ThreadActionData.purgeActions();
    TxControl.setXANodeName("test");
    TransactionImple tx = new TransactionImple(500);
    try {
        tx.enlistResource(new FailureXAResource(FailLocation.commit, FailType.nota));
        tx.enlistResource(new TestResource());
    } catch (final RollbackException ex) {
        fail();
    }
    try {
        tx.commit();
        fail();
    } catch (final HeuristicMixedException ex) {
        assertEquals(XAException.XAER_NOTA, ((XAException) ex.getSuppressed()[0]).errorCode);
    }
}
Also used : XAException(javax.transaction.xa.XAException) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) FailureXAResource(com.hp.mwtests.ts.jta.common.FailureXAResource) HeuristicMixedException(javax.transaction.HeuristicMixedException) TestResource(com.hp.mwtests.ts.jta.common.TestResource) RollbackException(javax.transaction.RollbackException) Test(org.junit.Test)

Example 18 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.

the class ExceptionDeferrerTest method testCheckDeferredPrepareRollbackException.

@Test
public void testCheckDeferredPrepareRollbackException() throws Exception {
    ThreadActionData.purgeActions();
    TransactionImple tx = new TransactionImple(0);
    tx.enlistResource(new FailureXAResource());
    try {
        tx.enlistResource(new FailureXAResource(FailLocation.prepare, FailType.rollback));
    } catch (final RollbackException ex) {
        fail();
    }
    try {
        tx.commit();
        fail();
    } catch (final RollbackException ex) {
        assertEquals(XAException.XAER_INVAL, ((XAException) ex.getSuppressed()[0]).errorCode);
    }
}
Also used : XAException(javax.transaction.xa.XAException) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) FailureXAResource(com.hp.mwtests.ts.jta.common.FailureXAResource) RollbackException(javax.transaction.RollbackException) Test(org.junit.Test)

Example 19 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.

the class ExceptionDeferrerTest method testCheckDeferredPrepareInitCause.

@Test
public void testCheckDeferredPrepareInitCause() throws Exception {
    ThreadActionData.purgeActions();
    TransactionImple tx = new TransactionImple(0);
    tx.enlistResource(new FailureXAResource());
    try {
        tx.enlistResource(new FailureXAResource(FailLocation.prepare, FailType.message));
    } catch (final RollbackException ex) {
        fail();
    }
    try {
        tx.commit();
        fail();
    } catch (final RollbackException ex) {
        assertEquals(XAException.XA_RBROLLBACK, ((XAException) ex.getSuppressed()[0]).errorCode);
        assertEquals("test message", ((XAException) ex.getSuppressed()[0]).getCause().getMessage());
    }
}
Also used : XAException(javax.transaction.xa.XAException) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) FailureXAResource(com.hp.mwtests.ts.jta.common.FailureXAResource) RollbackException(javax.transaction.RollbackException) Test(org.junit.Test)

Example 20 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.

the class ExceptionDeferrerTest method testCheckDeferredPrepareHeuristic.

@Test
public void testCheckDeferredPrepareHeuristic() throws Exception {
    ThreadActionData.purgeActions();
    TransactionImple tx = new TransactionImple(0);
    tx.enlistResource(new FailureXAResource());
    try {
        tx.enlistResource(new FailureXAResource(FailLocation.prepare, FailType.XA_HEURHAZ));
    } catch (final RollbackException ex) {
        fail();
    }
    try {
        tx.commit();
        fail();
    } catch (final HeuristicMixedException ex) {
        assertEquals(XAException.XA_HEURHAZ, ((XAException) ex.getSuppressed()[0]).errorCode);
    }
}
Also used : XAException(javax.transaction.xa.XAException) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) FailureXAResource(com.hp.mwtests.ts.jta.common.FailureXAResource) HeuristicMixedException(javax.transaction.HeuristicMixedException) RollbackException(javax.transaction.RollbackException) Test(org.junit.Test)

Aggregations

TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple)32 Test (org.junit.Test)30 FailureXAResource (com.hp.mwtests.ts.jta.common.FailureXAResource)12 XAException (javax.transaction.xa.XAException)11 RollbackException (javax.transaction.RollbackException)10 DummyXA (com.hp.mwtests.ts.jta.common.DummyXA)9 Uid (com.arjuna.ats.arjuna.common.Uid)7 XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)7 HeuristicMixedException (javax.transaction.HeuristicMixedException)6 TestResource (com.hp.mwtests.ts.jta.common.TestResource)5 XAResource (javax.transaction.xa.XAResource)5 Xid (javax.transaction.xa.Xid)5 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)4 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)4 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)4 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)4 SystemException (javax.transaction.SystemException)4 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)3 CommitMarkableResourceRecordRecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule)3 XidImple (com.arjuna.ats.jta.xa.XidImple)3