Search in sources :

Example 26 with SubordinateTransaction

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

the class SubordinateTestCase method testTwoPhaseCommitSyncWithXAOK.

@Test
public void testTwoPhaseCommitSyncWithXAOK() throws Exception {
    final SubordinateTransaction tm = createTransaction();
    final TestSynchronization sync = new TestSynchronization();
    tm.registerSynchronization(sync);
    final TestXAResource xaResource = new TestXAResource();
    xaResource.setPrepareReturnValue(XAResource.XA_OK);
    tm.enlistResource(xaResource);
    assertEquals(TwoPhaseOutcome.PREPARE_OK, tm.doPrepare());
    tm.doCommit();
    assertTrue(sync.isBeforeCompletionDone());
    assertTrue(sync.isAfterCompletionDone());
    assertEquals(javax.transaction.Status.STATUS_COMMITTED, tm.getStatus());
}
Also used : SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Example 27 with SubordinateTransaction

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

the class SubordinateTestCase method testTwoPhaseCommitSyncWithRollbackOnlyWithSeparateSync.

@Test
public void testTwoPhaseCommitSyncWithRollbackOnlyWithSeparateSync() throws Exception {
    final SubordinateTransaction tm = createTransaction();
    final TestSynchronization sync = new TestSynchronization();
    tm.registerSynchronization(sync);
    tm.setRollbackOnly();
    tm.doBeforeCompletion();
    assertEquals(TwoPhaseOutcome.PREPARE_NOTOK, tm.doPrepare());
    tm.doRollback();
    assertTrue(sync.isBeforeCompletionDone());
    assertTrue(sync.isAfterCompletionDone());
    assertEquals(javax.transaction.Status.STATUS_ROLLEDBACK, tm.getStatus());
}
Also used : SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Example 28 with SubordinateTransaction

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

the class SubordinateTestCase method testTwoPhaseCommitSyncWithXAOKWithSeparateSync.

@Test
public void testTwoPhaseCommitSyncWithXAOKWithSeparateSync() throws Exception {
    final SubordinateTransaction tm = createTransaction();
    final TestSynchronization sync = new TestSynchronization();
    tm.registerSynchronization(sync);
    final TestXAResource xaResource = new TestXAResource();
    xaResource.setPrepareReturnValue(XAResource.XA_OK);
    tm.enlistResource(xaResource);
    tm.doBeforeCompletion();
    assertEquals(TwoPhaseOutcome.PREPARE_OK, tm.doPrepare());
    tm.doCommit();
    assertTrue(sync.isBeforeCompletionDone());
    assertTrue(sync.isAfterCompletionDone());
    assertEquals(javax.transaction.Status.STATUS_COMMITTED, tm.getStatus());
}
Also used : SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Example 29 with SubordinateTransaction

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

the class XATerminatorUnitTest method testImportMultipleTx.

@Test
public void testImportMultipleTx() throws XAException, RollbackException, SystemException {
    Implementations.initialise();
    XidImple xid = new XidImple(new Uid());
    TransactionImporter imp = SubordinationManager.getTransactionImporter();
    SubordinateTransaction subordinateTransaction = imp.importTransaction(xid);
    XATerminatorImple xa = new XATerminatorImple();
    XAResourceImple xar1 = new XAResourceImple(XAResource.XA_OK, XAResource.XA_OK);
    XAResourceImple xar2 = new XAResourceImple(XAResource.XA_OK, XAException.XAER_RMFAIL);
    subordinateTransaction.enlistResource(xar1);
    subordinateTransaction.enlistResource(xar2);
    xa.prepare(xid);
    try {
        xa.commit(xid, false);
        fail("Did not expect to pass");
    } catch (XAException xae) {
        assertTrue(xae.errorCode == XAException.XAER_RMFAIL);
    }
    XARecoveryModule xarm = new XARecoveryModule();
    xarm.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {

        @Override
        public boolean initialise(String p) throws Exception {
            return false;
        }

        @Override
        public XAResource[] getXAResources() throws Exception {
            return new XAResource[] { xar2 };
        }
    });
    RecoveryManager.manager().addModule(xarm);
    Xid[] xids = xa.recover(XAResource.TMSTARTRSCAN);
    assertTrue(Arrays.binarySearch(xids, xid, new Comparator<Xid>() {

        @Override
        public int compare(Xid o1, Xid o2) {
            if (((XidImple) o1).equals(o2)) {
                return 0;
            } else {
                return -1;
            }
        }
    }) != -1);
    xa.rollback(xid);
    assertTrue(xar2.rollbackCalled());
    xa.recover(XAResource.TMENDRSCAN);
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) XAException(javax.transaction.xa.XAException) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) UnexpectedConditionException(com.arjuna.ats.jta.exceptions.UnexpectedConditionException) RollbackException(javax.transaction.RollbackException) SystemException(javax.transaction.SystemException) XAException(javax.transaction.xa.XAException) Uid(com.arjuna.ats.arjuna.common.Uid) Xid(javax.transaction.xa.Xid) TransactionImporter(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter) XATerminatorImple(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.XATerminatorImple) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Example 30 with SubordinateTransaction

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

the class XATerminatorUnitTest method testConcurrentImport.

@Test
public void testConcurrentImport() throws Exception {
    AtomicInteger completionCount = new AtomicInteger(0);
    XidImple xid = new XidImple(new Uid());
    final int TASK_COUNT = 400;
    final int THREAD_COUNT = 200;
    final CyclicBarrier gate = new CyclicBarrier(THREAD_COUNT + 1);
    ArrayList<CompletableFuture<SubordinateTransaction>> futures = new ArrayList<>();
    ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);
    for (int i = 0; i < TASK_COUNT; i++) futures.add(doAsync(completionCount, gate, i < THREAD_COUNT, executor, xid));
    gate.await();
    SubordinateTransaction prevStx = null;
    for (CompletableFuture<SubordinateTransaction> future : futures) {
        SubordinateTransaction stx = future.get();
        if (stx == null) {
            fail("transaction import returned null for future ");
        } else {
            if (prevStx != null)
                assertEquals("transaction import for same xid returned a different instance", stx, prevStx);
            else
                prevStx = stx;
        }
    }
    assertEquals("some transaction import futures did not complete", completionCount.get(), TASK_COUNT);
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.junit.Test)

Aggregations

SubordinateTransaction (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)42 Test (org.junit.Test)35 XAException (javax.transaction.xa.XAException)18 Uid (com.arjuna.ats.arjuna.common.Uid)16 Xid (javax.transaction.xa.Xid)13 XidImple (com.arjuna.ats.jta.xa.XidImple)12 TransactionImporter (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter)7 XATerminatorImple (com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple)6 RollbackException (javax.transaction.RollbackException)6 SystemException (javax.transaction.SystemException)6 XAResource (javax.transaction.xa.XAResource)6 XATerminatorImple (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.XATerminatorImple)4 ArrayList (java.util.ArrayList)4 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)3 SubordinateXidImple (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateXidImple)3 UnexpectedConditionException (com.arjuna.ats.jta.exceptions.UnexpectedConditionException)3 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)3 TestXAResource (com.hp.mwtests.ts.jta.jts.TestXAResource)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 HeuristicMixedException (javax.transaction.HeuristicMixedException)3