Search in sources :

Example 61 with XidImple

use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.

the class SubordinateTestCase method testTwoPhaseCommitSyncWithXAOKViaXATerminator.

@Test
public void testTwoPhaseCommitSyncWithXAOKViaXATerminator() throws Exception {
    final Xid xid = new XidImple(new Uid());
    final Transaction t = SubordinationManager.getTransactionImporter().importTransaction(xid);
    final TestSynchronization sync = new TestSynchronization();
    t.registerSynchronization(sync);
    final TestXAResource xaResource = new TestXAResource();
    xaResource.setPrepareReturnValue(XAResource.XA_OK);
    t.enlistResource(xaResource);
    final XATerminator xaTerminator = SubordinationManager.getXATerminator();
    assertEquals(XAResource.XA_OK, xaTerminator.prepare(xid));
    xaTerminator.commit(xid, false);
    assertTrue(sync.isBeforeCompletionDone());
    assertTrue(sync.isAfterCompletionDone());
    assertEquals(javax.transaction.Status.STATUS_COMMITTED, t.getStatus());
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) XATerminator(javax.resource.spi.XATerminator) Xid(javax.transaction.xa.Xid) Transaction(javax.transaction.Transaction) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Example 62 with XidImple

use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.

the class SubordinateTestCase method testFailOnCommitRetry.

@Test
public void testFailOnCommitRetry() throws Exception {
    final Xid xid = new XidImple(new Uid());
    final Transaction t = SubordinationManager.getTransactionImporter().importTransaction(xid);
    final TestXAResource xaResource = new TestXAResource();
    xaResource.setCommitException(new XAException(XAException.XA_RETRY));
    t.enlistResource(xaResource);
    final XATerminator xaTerminator = SubordinationManager.getXATerminator();
    Xid[] recover1 = xaTerminator.recover(XAResource.TMSTARTRSCAN);
    xaTerminator.recover(XAResource.TMENDRSCAN);
    xaTerminator.prepare(xid);
    try {
        xaTerminator.commit(xid, false);
        fail("Expected an error");
    } catch (XAException e) {
        assertTrue(e.errorCode == XAException.XAER_RMFAIL);
    }
    Xid[] recover2 = xaTerminator.recover(XAResource.TMSTARTRSCAN);
    xaTerminator.recover(XAResource.TMENDRSCAN);
    if (recover1 == null) {
        recover1 = new Xid[0];
    }
    int difference = recover2.length - recover1.length;
    assertTrue("" + difference, difference == 1);
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) XATerminator(javax.resource.spi.XATerminator) Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) Transaction(javax.transaction.Transaction) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Example 63 with XidImple

use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.

the class SubordinateTestCase method testOnePhaseCommitSyncViaXATerminatorWithSeparateSync.

@Test
public void testOnePhaseCommitSyncViaXATerminatorWithSeparateSync() throws Exception {
    final Xid xid = new XidImple(new Uid());
    final Transaction t = SubordinationManager.getTransactionImporter().importTransaction(xid);
    final TestSynchronization sync = new TestSynchronization();
    t.registerSynchronization(sync);
    final XATerminator xaTerminator = SubordinationManager.getXATerminator();
    final XATerminatorExtensions xaTerminatorExtensions = (XATerminatorExtensions) xaTerminator;
    xaTerminatorExtensions.beforeCompletion(xid);
    xaTerminator.commit(xid, true);
    assertTrue(sync.isBeforeCompletionDone());
    assertTrue(sync.isAfterCompletionDone());
    assertEquals(javax.transaction.Status.STATUS_COMMITTED, t.getStatus());
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) XATerminator(javax.resource.spi.XATerminator) Xid(javax.transaction.xa.Xid) XATerminatorExtensions(com.arjuna.ats.internal.jta.resources.spi.XATerminatorExtensions) Transaction(javax.transaction.Transaction) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Example 64 with XidImple

use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.

the class SubordinateTestCase method testFailOnCommit.

@Test
public void testFailOnCommit() throws Exception {
    final Xid xid = new XidImple(new Uid());
    final Transaction t = SubordinationManager.getTransactionImporter().importTransaction(xid);
    final TestXAResource xaResource = new TestXAResource();
    // provoke commit into failing with TwoPhaseOutcome.FINISH_ERROR
    // warning: this is sensitive to the impl exception handling in
    // XAResourceRecord.topLevelCommit
    // throw a little spice into things!
    xaResource.setCommitException(new XAException(XAException.XA_HEURHAZ));
    t.enlistResource(xaResource);
    final XATerminator xaTerminator = SubordinationManager.getXATerminator();
    try {
        xaTerminator.prepare(xid);
        xaTerminator.commit(xid, false);
    } catch (final XAException ex) {
        return;
    }
    assertTrue("commit should throw an exception and not get to here", false);
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) XATerminator(javax.resource.spi.XATerminator) Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) Transaction(javax.transaction.Transaction) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Example 65 with XidImple

use of com.arjuna.ats.jta.xa.XidImple in project narayana by jbosstm.

the class SubordinateTestCase method testTwoPhaseCommitSyncViaXATerminator.

@Test
public void testTwoPhaseCommitSyncViaXATerminator() throws Exception {
    final Xid xid = new XidImple(new Uid());
    final Transaction t = SubordinationManager.getTransactionImporter().importTransaction(xid);
    final TestSynchronization sync = new TestSynchronization();
    t.registerSynchronization(sync);
    final XATerminator xaTerminator = SubordinationManager.getXATerminator();
    assertEquals(XAResource.XA_RDONLY, xaTerminator.prepare(xid));
    // don't call commit for read only case
    assertTrue(sync.isBeforeCompletionDone());
    assertTrue(sync.isAfterCompletionDone());
    assertEquals(javax.transaction.Status.STATUS_COMMITTED, t.getStatus());
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) XATerminator(javax.resource.spi.XATerminator) Xid(javax.transaction.xa.Xid) Transaction(javax.transaction.Transaction) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Aggregations

XidImple (com.arjuna.ats.jta.xa.XidImple)90 Uid (com.arjuna.ats.arjuna.common.Uid)71 Test (org.junit.Test)71 Xid (javax.transaction.xa.Xid)35 XAException (javax.transaction.xa.XAException)28 SubordinateTransaction (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)27 Transaction (javax.transaction.Transaction)16 XATerminator (javax.resource.spi.XATerminator)15 TransactionImporter (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter)12 XATerminatorImple (com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple)10 IOException (java.io.IOException)10 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)9 XAOnePhaseResource (com.arjuna.ats.internal.jta.resources.arjunacore.XAOnePhaseResource)9 XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)9 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)8 SampleOnePhaseResource (com.hp.mwtests.ts.jta.common.SampleOnePhaseResource)8 RollbackException (javax.transaction.RollbackException)8 SystemException (javax.transaction.SystemException)8 XAResource (javax.transaction.xa.XAResource)8 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)7