Search in sources :

Example 1 with TransactionImporter

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

the class XATerminatorImple method getXidsToRecoverForParentNode.

public Xid[] getXidsToRecoverForParentNode(boolean recoverInFlight, String parentNodeName, int recoveryFlags) throws XAException {
    final Set<Xid> xidsToRecover = new HashSet<Xid>();
    if (recoverInFlight) {
        final TransactionImporter transactionImporter = SubordinationManager.getTransactionImporter();
        if (transactionImporter instanceof TransactionImporterImple) {
            throw new UnsupportedOperationException(jtaxLogger.i18NLogger.get_not_supported());
        }
    }
    final javax.resource.spi.XATerminator xaTerminator = SubordinationManager.getXATerminator();
    if (xaTerminator instanceof XATerminatorImple) {
        throw new UnsupportedOperationException(jtaxLogger.i18NLogger.get_not_supported());
    } else {
        final Xid[] inDoubtTransactions = xaTerminator.recover(recoveryFlags);
        if (inDoubtTransactions != null) {
            xidsToRecover.addAll(Arrays.asList(inDoubtTransactions));
        }
    }
    return xidsToRecover.toArray(NO_XIDS);
}
Also used : Xid(javax.transaction.xa.Xid) TransactionImporter(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter) HashSet(java.util.HashSet)

Example 2 with TransactionImporter

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

the class XATerminatorImpleUnitTest method testForget.

@Test
public void testForget() throws Exception {
    XidImple xid = new XidImple(new Uid());
    TransactionImporter imp = SubordinationManager.getTransactionImporter();
    imp.importTransaction(xid);
    XATerminatorImple xa = new XATerminatorImple();
    xa.forget(xid);
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) TransactionImporter(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter) XATerminatorImple(com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple) Test(org.junit.Test)

Example 3 with TransactionImporter

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

the class XATerminatorImpleUnitTest method testOnePhaseCommit.

@Test
public void testOnePhaseCommit() throws Exception {
    XidImple xid = new XidImple(new Uid());
    TransactionImporter imp = SubordinationManager.getTransactionImporter();
    imp.importTransaction(xid);
    XATerminatorImple xa = new XATerminatorImple();
    xa.commit(xid, true);
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) TransactionImporter(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter) XATerminatorImple(com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple) Test(org.junit.Test)

Example 4 with TransactionImporter

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

the class XATerminatorImpleUnitTest method testRecover.

@Test
public void testRecover() throws Exception {
    XidImple xid = new XidImple(new Uid());
    TransactionImporter imp = SubordinationManager.getTransactionImporter();
    imp.importTransaction(xid);
    XATerminatorImple xa = new XATerminatorImple();
    xa.recover(XAResource.TMSTARTRSCAN);
    try {
        xa.recover(XAResource.TMSTARTRSCAN);
        fail();
    } catch (final Exception ex) {
    }
    xa.recover(XAResource.TMENDRSCAN);
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) TransactionImporter(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter) XATerminatorImple(com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple) XAException(javax.transaction.xa.XAException) RollbackException(javax.transaction.RollbackException) SystemException(javax.transaction.SystemException) Test(org.junit.Test)

Example 5 with TransactionImporter

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

the class XATerminatorImpleUnitTest method testXARetry.

@Test
public void testXARetry() throws Exception {
    XidImple xid = new XidImple(new Uid());
    TransactionImporter imp = SubordinationManager.getTransactionImporter();
    SubordinateTransaction subordinateTransaction = imp.importTransaction(xid);
    XATerminatorImple xa = new XATerminatorImple();
    subordinateTransaction.enlistResource(new XAResource() {

        @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 {
            return new Xid[0];
        }

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

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

        @Override
        public void start(Xid xid, int i) throws XAException {
        }
    });
    subordinateTransaction.enlistResource(new XAResource() {

        boolean firstAttempt = true;

        @Override
        public void commit(Xid xid, boolean b) throws XAException {
            if (firstAttempt) {
                try {
                    failedResourceXid = xid;
                    throw new XAException(XAException.XA_RETRY);
                } finally {
                    firstAttempt = false;
                }
            }
            if (failedResourceXid != null) {
                failedResourceXid = null;
            } else {
                throw new XAException(XAException.XAER_PROTO);
            }
        }

        @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 {
            return new Xid[0];
        }

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

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

        @Override
        public void start(Xid xid, int i) throws XAException {
        }
    });
    assertEquals(xa.prepare(xid), XAResource.XA_OK);
    try {
        xa.commit(xid, false);
        fail("Expecting XATerminator throwing XAException as commit should fail" + " as TestXAResource was instructed to throw an exception");
    } catch (final XAException ex) {
        assertEquals("XATerminator commit should throw XAER_RMFAIL when commit fails", XAException.XAER_RMFAIL, ex.errorCode);
    }
    Implementationsx.initialise();
    xa.recover(XAResource.TMSTARTRSCAN);
    assertNotNull(failedResourceXid);
    try {
        xa.commit(xid, false);
    } catch (XAException expected) {
        Assert.assertTrue("On commit XAException error code indicating more recover call is expected but it's " + expected.errorCode, XAException.XA_RETRY == expected.errorCode || XAException.XAER_RMFAIL == expected.errorCode);
    } finally {
        xa.recover(XAResource.TMENDRSCAN);
    }
    assertNull(failedResourceXid);
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) XAResource(javax.transaction.xa.XAResource) TestXAResource(com.hp.mwtests.ts.jta.jts.TestXAResource) Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) TransactionImporter(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter) XATerminatorImple(com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Aggregations

TransactionImporter (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter)15 Uid (com.arjuna.ats.arjuna.common.Uid)14 Test (org.junit.Test)14 XATerminatorImple (com.arjuna.ats.internal.jta.transaction.jts.jca.XATerminatorImple)12 XidImple (com.arjuna.ats.jta.xa.XidImple)12 XAException (javax.transaction.xa.XAException)10 Xid (javax.transaction.xa.Xid)8 SubordinateTransaction (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)7 RollbackException (javax.transaction.RollbackException)4 SystemException (javax.transaction.SystemException)4 TestXAResource (com.hp.mwtests.ts.jta.jts.TestXAResource)3 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)2 XATerminatorImple (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.XATerminatorImple)2 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)2 XAResource (javax.transaction.xa.XAResource)2 ObjectStoreIterator (com.arjuna.ats.arjuna.objectstore.ObjectStoreIterator)1 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)1 ObjStoreBrowser (com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser)1 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule)1 XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)1