Search in sources :

Example 11 with SubordinateTransaction

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

the class TransactionImporterUnitTest method testDifferentInstanceFromRecovery.

@Test
public void testDifferentInstanceFromRecovery() throws XAException, RollbackException, SystemException, HeuristicRollbackException, HeuristicMixedException, HeuristicCommitException {
    Uid uid = new Uid();
    XidImple xid = new XidImple(uid);
    SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().importTransaction(xid);
    Uid subordinateTransactionUid = subordinateTransaction.get_uid();
    Xid subordinateTransactionXid = subordinateTransaction.baseXid();
    SubordinateTransaction importedTransaction = SubordinationManager.getTransactionImporter().getImportedTransaction(subordinateTransactionXid);
    assertTrue(subordinateTransaction == importedTransaction);
    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.doPrepare();
    Implementations.initialise();
    SubordinateTransaction subordinateTransaction1 = SubordinationManager.getTransactionImporter().recoverTransaction(subordinateTransactionUid);
    assertTrue(subordinateTransaction != subordinateTransaction1);
    SubordinateTransaction importedTransaction1 = SubordinationManager.getTransactionImporter().getImportedTransaction(subordinateTransactionXid);
    assertTrue(importedTransaction != importedTransaction1);
    SubordinateTransaction importedTransaction2 = SubordinationManager.getTransactionImporter().getImportedTransaction(subordinateTransactionXid);
    assertTrue(importedTransaction1 == importedTransaction2);
    importedTransaction2.doCommit();
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) Xid(javax.transaction.xa.Xid) XAResource(javax.transaction.xa.XAResource) XAException(javax.transaction.xa.XAException) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) Test(org.junit.Test)

Example 12 with SubordinateTransaction

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

the class XATerminatorImple method rollback.

public void rollback(Xid xid) throws XAException {
    // JBTM-927 this can happen if the transaction has been rolled back by
    // the TransactionReaper
    SubordinateTransaction tx = null;
    try {
        tx = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
    } catch (XAException xae) {
        if (xae.errorCode == XAException.XA_RBROLLBACK) {
            SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
            return;
        }
        throw xae;
    }
    try {
        if (tx == null)
            throw new XAException(XAException.XAER_INVAL);
        if (tx.baseXid() != null) {
            tx.doRollback();
            SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
        } else
            throw new XAException(XAException.XA_RETRY);
    } catch (XAException ex) {
        if (ex.errorCode != XAException.XA_RETRY) {
            SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
        }
        throw ex;
    } catch (HeuristicCommitException ex) {
        XAException xaException = new XAException(XAException.XA_HEURCOM);
        xaException.initCause(ex);
        throw xaException;
    } catch (final HeuristicRollbackException ex) {
        XAException xaException = new XAException(XAException.XA_HEURRB);
        xaException.initCause(ex);
        throw xaException;
    } catch (HeuristicMixedException ex) {
        XAException xaException = new XAException(XAException.XA_HEURMIX);
        xaException.initCause(ex);
        throw xaException;
    } catch (final IllegalStateException ex) {
        SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
        XAException xaException = new XAException(XAException.XAER_NOTA);
        xaException.initCause(ex);
        throw xaException;
    } catch (SystemException ex) {
        SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
        XAException xaException = new XAException(XAException.XAER_RMERR);
        xaException.initCause(ex);
        throw xaException;
    }
}
Also used : HeuristicRollbackException(javax.transaction.HeuristicRollbackException) XAException(javax.transaction.xa.XAException) SystemException(javax.transaction.SystemException) HeuristicMixedException(javax.transaction.HeuristicMixedException) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) HeuristicCommitException(javax.transaction.HeuristicCommitException)

Example 13 with SubordinateTransaction

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

the class TransactionImporterImple method removeImportedTransaction.

/**
 * Remove the subordinate (imported) transaction.
 *
 * @param xid the global transaction.
 *
 * @throws XAException thrown if there are any errors.
 */
public void removeImportedTransaction(Xid xid) throws XAException {
    if (xid == null)
        throw new IllegalArgumentException();
    AtomicReference<SubordinateTransaction> remove = _transactions.remove(new SubordinateXidImple(xid));
    if (remove != null) {
        synchronized (remove) {
            com.arjuna.ats.internal.jta.transaction.jts.TransactionImple transactionImple = (com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) remove.get();
            while (transactionImple == null) {
                try {
                    remove.wait();
                    transactionImple = (com.arjuna.ats.internal.jta.transaction.jts.TransactionImple) remove.get();
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    throw new XAException(XAException.XAER_RMFAIL);
                }
            }
            TransactionImple.removeTransaction(transactionImple);
        }
    }
}
Also used : SubordinateXidImple(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateXidImple) XAException(javax.transaction.xa.XAException) TransactionImple(com.arjuna.ats.internal.jta.transaction.jts.subordinate.jca.TransactionImple) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)

Example 14 with SubordinateTransaction

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

the class SubordinationManagerXAResourceOrphanFilter method checkXid.

@Override
public Vote checkXid(Xid xid) {
    if (xid.getFormatId() != XATxConverter.FORMAT_ID) {
        // we only care about Xids created by the JTA
        return Vote.ABSTAIN;
    }
    List<String> _xaRecoveryNodes = jtaPropertyManager.getJTAEnvironmentBean().getXaRecoveryNodes();
    if (_xaRecoveryNodes == null || _xaRecoveryNodes.size() == 0) {
        jtaLogger.i18NLogger.info_recovery_noxanodes();
        return Vote.ABSTAIN;
    }
    String nodeName = XATxConverter.getSubordinateNodeName(new XidImple(xid).getXID());
    if (jtaLogger.logger.isDebugEnabled()) {
        jtaLogger.logger.debug("subordinate node name of " + xid + " is " + nodeName);
    }
    if (!_xaRecoveryNodes.contains(nodeName)) {
        // It either doesn't have a subordinate node name or isn't for this server
        return Vote.ABSTAIN;
    }
    if (!getSubordinateAtomicActionRecoveryModule().isRecoveryScanCompletedWithoutError()) {
        // Xid alone
        return Vote.LEAVE_ALONE;
    }
    XidImple theXid = new XidImple(xid);
    SubordinateTransaction importedTransaction = null;
    try {
        importedTransaction = SubordinationManager.getTransactionImporter().getImportedTransaction(theXid);
    } catch (XAException e) {
        return Vote.LEAVE_ALONE;
    }
    if (importedTransaction != null) {
        return Vote.LEAVE_ALONE;
    } else {
        return Vote.ROLLBACK;
    }
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) XAException(javax.transaction.xa.XAException) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)

Example 15 with SubordinateTransaction

use of com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction 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

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