Search in sources :

Example 1 with XAResourceOrphanFilter

use of com.arjuna.ats.jta.recovery.XAResourceOrphanFilter in project narayana by jbosstm.

the class XAResourceOrphanFilterTest method testJTAActionStatusServiceXAResourceOrphanFilter.

@Test
public void testJTAActionStatusServiceXAResourceOrphanFilter() {
    XAResourceOrphanFilter orphanFilter = new JTAActionStatusServiceXAResourceOrphanFilter();
    List<String> xaRecoveryNodes = jtaPropertyManager.getJTAEnvironmentBean().getXaRecoveryNodes();
    List<String> recoveryNodes = new LinkedList<String>();
    recoveryNodes.add("1");
    jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(recoveryNodes);
    try {
        Uid uid = new Uid();
        Xid xid = XATxConverter.getXid(uid, false, XATxConverter.FORMAT_ID);
        assertEquals(XAResourceOrphanFilter.Vote.ROLLBACK, orphanFilter.checkXid(xid));
        TwoPhaseCoordinator tpc = new TwoPhaseCoordinator(uid);
        try {
            tpc.start();
            assertEquals(XAResourceOrphanFilter.Vote.LEAVE_ALONE, orphanFilter.checkXid(xid));
        } finally {
            tpc.cancel();
        }
        assertEquals(XAResourceOrphanFilter.Vote.ROLLBACK, orphanFilter.checkXid(xid));
        jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(null);
        TwoPhaseCoordinator tpc2 = new TwoPhaseCoordinator(uid);
        tpc2.start();
        assertEquals(XAResourceOrphanFilter.Vote.ABSTAIN, orphanFilter.checkXid(xid));
        tpc2.cancel();
    } finally {
        jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(xaRecoveryNodes);
    }
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) TwoPhaseCoordinator(com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator) Xid(javax.transaction.xa.Xid) JTAActionStatusServiceXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.JTAActionStatusServiceXAResourceOrphanFilter) JTANodeNameXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter) SubordinateJTAXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.SubordinateJTAXAResourceOrphanFilter) SubordinationManagerXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.SubordinationManagerXAResourceOrphanFilter) JTAActionStatusServiceXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.JTAActionStatusServiceXAResourceOrphanFilter) XAResourceOrphanFilter(com.arjuna.ats.jta.recovery.XAResourceOrphanFilter) NodeNameXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.NodeNameXAResourceOrphanFilter) JTATransactionLogXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 2 with XAResourceOrphanFilter

use of com.arjuna.ats.jta.recovery.XAResourceOrphanFilter in project narayana by jbosstm.

the class XAResourceOrphanFilterTest method testJTAActionStatusServiceXAResourceOrphanFilterSubordinate.

@Test
public void testJTAActionStatusServiceXAResourceOrphanFilterSubordinate() throws HeuristicRollbackException, HeuristicMixedException, HeuristicCommitException, SystemException, RollbackException, XAException {
    XAResourceOrphanFilter orphanFilter = new SubordinationManagerXAResourceOrphanFilter();
    List<String> xaRecoveryNodes = jtaPropertyManager.getJTAEnvironmentBean().getXaRecoveryNodes();
    List<String> recoveryNodes = new LinkedList<String>();
    recoveryNodes.add("1");
    jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(recoveryNodes);
    final List<String> recoveryExtensions = new ArrayList<String>();
    recoveryExtensions.add(com.arjuna.ats.internal.jta.recovery.arjunacore.SubordinateAtomicActionRecoveryModule.class.getName());
    recoveryExtensions.add(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule.class.getName());
    recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryModuleClassNames(recoveryExtensions);
    int recoveryBackoffPeriod = recoveryPropertyManager.getRecoveryEnvironmentBean().getRecoveryBackoffPeriod();
    recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(1);
    RecoveryManager.manager().scan();
    recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(recoveryBackoffPeriod);
    try {
        Xid xid = XATxConverter.getXid(Uid.nullUid(), false, XATxConverter.FORMAT_ID);
        assertEquals(XAResourceOrphanFilter.Vote.ABSTAIN, orphanFilter.checkXid(xid));
        SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().importTransaction(xid);
        final List<Xid> xids = new ArrayList<Xid>();
        XAResource xar = new SimpleXAResource() {

            @Override
            public void start(Xid xid, int flags) throws XAException {
                super.start(xid, flags);
                xids.add(xid);
            }
        };
        subordinateTransaction.enlistResource(xar);
        try {
            assertEquals(XAResourceOrphanFilter.Vote.LEAVE_ALONE, orphanFilter.checkXid(xids.get(0)));
        } finally {
            subordinateTransaction.doRollback();
        }
        assertEquals(XAResourceOrphanFilter.Vote.LEAVE_ALONE, orphanFilter.checkXid(xids.get(0)));
        SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
        assertEquals(XAResourceOrphanFilter.Vote.ROLLBACK, orphanFilter.checkXid(xids.get(0)));
    } finally {
        jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(xaRecoveryNodes);
        recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryModuleClassNames(null);
    }
}
Also used : ArrayList(java.util.ArrayList) SubordinationManagerXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.SubordinationManagerXAResourceOrphanFilter) LinkedList(java.util.LinkedList) Xid(javax.transaction.xa.Xid) SimpleXAResource(com.hp.mwtests.ts.jta.commitmarkable.SimpleXAResource) XAResource(javax.transaction.xa.XAResource) SimpleXAResource(com.hp.mwtests.ts.jta.commitmarkable.SimpleXAResource) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) JTANodeNameXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter) SubordinateJTAXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.SubordinateJTAXAResourceOrphanFilter) SubordinationManagerXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.SubordinationManagerXAResourceOrphanFilter) JTAActionStatusServiceXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.JTAActionStatusServiceXAResourceOrphanFilter) XAResourceOrphanFilter(com.arjuna.ats.jta.recovery.XAResourceOrphanFilter) NodeNameXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.NodeNameXAResourceOrphanFilter) JTATransactionLogXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter) Test(org.junit.Test)

Example 3 with XAResourceOrphanFilter

use of com.arjuna.ats.jta.recovery.XAResourceOrphanFilter in project narayana by jbosstm.

the class XARecoveryModule method handleOrphan.

/**
 * Apply use configurable filtering to determine how to handle the in-doubt resource.
 *
 * @param xares
 * @param xid
 * @return true if forget should be called, false otherwise.
 */
private boolean handleOrphan(XAResource xares, Xid xid) {
    // be default we play it safe and leave resources alone unless a filter explicitly recognizes them.
    // getting presumed abort behaviour therefore requires appropriate filters to be registered.
    XAResourceOrphanFilter.Vote votingOutcome = XAResourceOrphanFilter.Vote.LEAVE_ALONE;
    for (XAResourceOrphanFilter filter : _xaResourceOrphanFilters) {
        XAResourceOrphanFilter.Vote vote = filter.checkXid(xid);
        if (jtaLogger.logger.isDebugEnabled()) {
            jtaLogger.logger.debug("XAResourceOrphanFilter " + filter.getClass().getName() + " voted " + vote);
        }
        if (vote == XAResourceOrphanFilter.Vote.LEAVE_ALONE) {
            return false;
        } else if (vote == XAResourceOrphanFilter.Vote.ROLLBACK) {
            votingOutcome = vote;
        }
    }
    try {
        if (votingOutcome == XAResourceOrphanFilter.Vote.ROLLBACK) {
            jtaLogger.i18NLogger.info_recovery_rollingback(XAHelper.xidToString(xid));
            xares.rollback(xid);
        }
    } catch (XAException e1) {
        if (e1.errorCode == XAException.XAER_NOTA) {
            if (jtaLogger.logger.isDebugEnabled()) {
                jtaLogger.logger.debug(_logName + ".xaRecovery: XAER_NOTA received while rolling back " + XAHelper.xidToString(xid));
            }
        } else {
            jtaLogger.i18NLogger.warn_recovery_xarecovery1(_logName + ".xaRecovery", XAHelper.printXAErrorCode(e1), e1);
        }
        switch(e1.errorCode) {
            case XAException.XAER_RMERR:
                break;
            case XAException.XA_HEURHAZ:
            case XAException.XA_HEURCOM:
            case XAException.XA_HEURMIX:
            case XAException.XA_HEURRB:
            case XAException.XA_RBROLLBACK:
                {
                    return true;
                }
            default:
                break;
        }
    } catch (Exception e2) {
        jtaLogger.i18NLogger.warn_recovery_xarecovery2(_logName + ".xaRecovery", e2);
    }
    return false;
}
Also used : XAException(javax.transaction.xa.XAException) XAResourceOrphanFilter(com.arjuna.ats.jta.recovery.XAResourceOrphanFilter) IOException(java.io.IOException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) XAException(javax.transaction.xa.XAException)

Example 4 with XAResourceOrphanFilter

use of com.arjuna.ats.jta.recovery.XAResourceOrphanFilter in project narayana by jbosstm.

the class XARecoveryModuleUnitTest method testXAResourceOrphanFilterRegistration.

@Test
public void testXAResourceOrphanFilterRegistration() {
    XARecoveryModule xaRecoveryModule = new XARecoveryModule();
    XAResourceOrphanFilter xaResourceOrphanFilter = new DummyXAResourceOrphanFilter();
    xaRecoveryModule.addXAResourceOrphanFilter(xaResourceOrphanFilter);
    xaRecoveryModule.removeXAResourceOrphanFilter(xaResourceOrphanFilter);
}
Also used : JTANodeNameXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter) XAResourceOrphanFilter(com.arjuna.ats.jta.recovery.XAResourceOrphanFilter) NodeNameXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.NodeNameXAResourceOrphanFilter) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Example 5 with XAResourceOrphanFilter

use of com.arjuna.ats.jta.recovery.XAResourceOrphanFilter in project narayana by jbosstm.

the class XARecoveryModuleUnitTest method testXAResourceOrphanFilter.

@Test
public void testXAResourceOrphanFilter() throws Exception {
    XAResourceOrphanFilter xaResourceOrphanFilter = new DummyXAResourceOrphanFilter(XAResourceOrphanFilter.Vote.ROLLBACK);
    XARecoveryModule xarm = new XARecoveryModule();
    xarm.addXAResourceOrphanFilter(xaResourceOrphanFilter);
    Class[] parameterTypes = new Class[2];
    parameterTypes[0] = XAResource.class;
    parameterTypes[1] = Xid.class;
    Method m = xarm.getClass().getDeclaredMethod("handleOrphan", parameterTypes);
    m.setAccessible(true);
    Object[] parameters = new Object[2];
    parameters[0] = new RecoveryXAResource();
    parameters[1] = new XidImple();
    m.invoke(xarm, parameters);
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Method(java.lang.reflect.Method) RecoveryXAResource(com.hp.mwtests.ts.jta.common.RecoveryXAResource) JTANodeNameXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter) XAResourceOrphanFilter(com.arjuna.ats.jta.recovery.XAResourceOrphanFilter) NodeNameXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.NodeNameXAResourceOrphanFilter) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Aggregations

XAResourceOrphanFilter (com.arjuna.ats.jta.recovery.XAResourceOrphanFilter)9 Test (org.junit.Test)8 JTANodeNameXAResourceOrphanFilter (com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter)7 NodeNameXAResourceOrphanFilter (com.arjuna.ats.internal.jta.recovery.arjunacore.NodeNameXAResourceOrphanFilter)7 JTAActionStatusServiceXAResourceOrphanFilter (com.arjuna.ats.internal.jta.recovery.arjunacore.JTAActionStatusServiceXAResourceOrphanFilter)5 JTATransactionLogXAResourceOrphanFilter (com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter)5 SubordinateJTAXAResourceOrphanFilter (com.arjuna.ats.internal.jta.recovery.arjunacore.SubordinateJTAXAResourceOrphanFilter)5 SubordinationManagerXAResourceOrphanFilter (com.arjuna.ats.internal.jta.recovery.arjunacore.SubordinationManagerXAResourceOrphanFilter)5 Xid (javax.transaction.xa.Xid)4 Uid (com.arjuna.ats.arjuna.common.Uid)3 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)3 LinkedList (java.util.LinkedList)3 XidImple (com.arjuna.ats.jta.xa.XidImple)2 TwoPhaseCoordinator (com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator)1 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)1 RecoveryManager (com.arjuna.ats.arjuna.recovery.RecoveryManager)1 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)1 JDBCStore (com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore)1 SubordinateTransaction (com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction)1 XAResourceRecovery (com.arjuna.ats.jta.recovery.XAResourceRecovery)1