Search in sources :

Example 1 with XidImple

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

the class ExampleXAResource method recover.

/**
 * @param param1 <description>
 * @return <description>
 * @throws javax.transaction.xa.XAException
 *          <description>
 */
public Xid[] recover(int flag) throws XAException {
    myLog("recover");
    Xid[] xids = new Xid[2];
    if (ExampleXAResource.toRecover == null) {
        AtomicAction a = new AtomicAction();
        ExampleXAResource.toRecover = new XidImple(new AtomicAction());
    }
    xids[0] = ExampleXAResource.toRecover;
    xids[1] = new XidImple(new AtomicAction());
    return xids;
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) Xid(javax.transaction.xa.Xid)

Example 2 with XidImple

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

the class XARecoveryModuleUnitTest method testRecoverPassFailure.

@Test
public void testRecoverPassFailure() throws Exception {
    int orphanSafetyInterval = jtaPropertyManager.getJTAEnvironmentBean().getOrphanSafetyInterval();
    List<String> xaRecoveryNodes = jtaPropertyManager.getJTAEnvironmentBean().getXaRecoveryNodes();
    jtaPropertyManager.getJTAEnvironmentBean().setOrphanSafetyInterval(0);
    jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(Arrays.asList(new String[] { NodeNameXAResourceOrphanFilter.RECOVER_ALL_NODES }));
    XARecoveryModule xarm = new XARecoveryModule();
    xarm.addXAResourceOrphanFilter(new JTANodeNameXAResourceOrphanFilter());
    xarm.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {

        XAResource[] xares = new XAResource[] { new XAResourceWrapper() {

            @Override
            public XAResource getResource() {
                return null;
            }

            @Override
            public String getProductName() {
                return null;
            }

            @Override
            public String getProductVersion() {
                return null;
            }

            @Override
            public String getJndiName() {
                return "test";
            }

            int count = 0;

            Xid xid = new XidImple(new Uid());

            @Override
            public void commit(Xid xid, boolean b) throws XAException {
            }

            @Override
            public void end(Xid xid, int i) throws XAException {
            }

            @Override
            public void forget(Xid xid) throws XAException {
            }

            @Override
            public int getTransactionTimeout() throws XAException {
                return 0;
            }

            @Override
            public boolean isSameRM(XAResource xaResource) throws XAException {
                return false;
            }

            @Override
            public int prepare(Xid xid) throws XAException {
                return 0;
            }

            @Override
            public Xid[] recover(int i) throws XAException {
                count++;
                if (count == 1 || count == 5) {
                    return new Xid[] { xid };
                } else if (count > 5) {
                    return new Xid[0];
                } else {
                    throw new XAException();
                }
            }

            @Override
            public void rollback(Xid xid) throws XAException {
                if (count == 1) {
                    // This comes from the first end scan
                    throw new XAException(XAException.XA_RETRY);
                }
                rolledback = true;
            }

            @Override
            public boolean setTransactionTimeout(int i) throws XAException {
                return false;
            }

            @Override
            public void start(Xid xid, int i) throws XAException {
            }
        } };

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

        @Override
        public XAResource[] getXAResources() throws Exception {
            return xares;
        }
    });
    // The first two recovery cycles do nothing with the resource (because phase two is getting the exception)
    // When count reaches 6 it sees that the xid has gone and presumes abort so calls rollback and hence assertTrue(rolledback) passes
    // 1st pass: returns one xid (count is 1)
    xarm.periodicWorkFirstPass();
    // 2nd pass: throws an exception (count is 2)
    xarm.periodicWorkSecondPass();
    assertTrue(xarm.getContactedJndiNames().contains("test"));
    assertFalse(rolledback);
    // 1st pass: throws an exception (count is 3)
    xarm.periodicWorkFirstPass();
    // 2nd pass: throws an exception (count is 4)
    xarm.periodicWorkSecondPass();
    assertFalse(xarm.getContactedJndiNames().contains("test"));
    assertFalse(rolledback);
    // 1st pass: returns an empty list of xids (count is 5)
    xarm.periodicWorkFirstPass();
    // 2nd pass: returns an empty list of xids (count is 6)
    xarm.periodicWorkSecondPass();
    assertTrue(xarm.getContactedJndiNames().contains("test"));
    assertTrue(rolledback);
    jtaPropertyManager.getJTAEnvironmentBean().setOrphanSafetyInterval(orphanSafetyInterval);
    jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(xaRecoveryNodes);
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) JTANodeNameXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter) XAException(javax.transaction.xa.XAException) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) XAResourceWrapper(org.jboss.tm.XAResourceWrapper) XAException(javax.transaction.xa.XAException) Uid(com.arjuna.ats.arjuna.common.Uid) XAResource(javax.transaction.xa.XAResource) RecoveryXAResource(com.hp.mwtests.ts.jta.common.RecoveryXAResource) Xid(javax.transaction.xa.Xid) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Example 3 with XidImple

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

the class SubordinateTestCase method testTwoPhaseCommitSyncWithRollbackOnlyViaXATerminatorWithSeparateSync.

@Test
public void testTwoPhaseCommitSyncWithRollbackOnlyViaXATerminatorWithSeparateSync() throws Exception {
    final Xid xid = new XidImple(new Uid());
    final Transaction t = SubordinationManager.getTransactionImporter().importTransaction(xid);
    final TestSynchronization sync = new TestSynchronization();
    t.registerSynchronization(sync);
    t.setRollbackOnly();
    final XATerminator xaTerminator = SubordinationManager.getXATerminator();
    final XATerminatorExtensions xaTerminatorExtensions = (XATerminatorExtensions) xaTerminator;
    xaTerminatorExtensions.beforeCompletion(xid);
    try {
        xaTerminator.prepare(xid);
    } catch (XAException e) {
        assertEquals(XAException.XA_RBROLLBACK, e.errorCode);
    // expected - we tried to prepare a rollbackonly tx.
    }
    // no need to call rollback - the XA_RBROLLBACK code indicates its been done.
    assertTrue(sync.isBeforeCompletionDone());
    assertTrue(sync.isAfterCompletionDone());
    assertEquals(javax.transaction.Status.STATUS_ROLLEDBACK, 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) XAException(javax.transaction.xa.XAException) Transaction(javax.transaction.Transaction) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Example 4 with XidImple

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

the class SubordinateTestCase method testTwoPhaseCommitSyncViaXATerminatorWithSeparateSync.

@Test
public void testTwoPhaseCommitSyncViaXATerminatorWithSeparateSync() 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);
    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) 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 5 with XidImple

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

the class SubordinateTestCase method testTwoPhaseCommitSyncWithRollbackOnlyViaXATerminator.

@Test
public void testTwoPhaseCommitSyncWithRollbackOnlyViaXATerminator() throws Exception {
    final Xid xid = new XidImple(new Uid());
    final Transaction t = SubordinationManager.getTransactionImporter().importTransaction(xid);
    final TestSynchronization sync = new TestSynchronization();
    t.registerSynchronization(sync);
    t.setRollbackOnly();
    final XATerminator xaTerminator = SubordinationManager.getXATerminator();
    try {
        xaTerminator.prepare(xid);
    } catch (XAException e) {
        assertEquals(XAException.XA_RBROLLBACK, e.errorCode);
    // expected - we tried to prepare a rollbackonly tx.
    }
    // no need to call rollback - the XA_RBROLLBACK code indicates its been done.
    assertFalse(sync.isBeforeCompletionDone());
    assertTrue(sync.isAfterCompletionDone());
    assertEquals(javax.transaction.Status.STATUS_ROLLEDBACK, 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) XAException(javax.transaction.xa.XAException) 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