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());
}
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());
}
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());
}
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);
}
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);
}
Aggregations