Search in sources :

Example 1 with JTANodeNameXAResourceOrphanFilter

use of com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter 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 2 with JTANodeNameXAResourceOrphanFilter

use of com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter in project narayana by jbosstm.

the class XAResourceOrphanFilterTest method testJTANodeNameXAResourceOrphanFilter.

@Test
public void testJTANodeNameXAResourceOrphanFilter() {
    XAResourceOrphanFilter orphanFilter = new JTANodeNameXAResourceOrphanFilter();
    Xid notJTAFormatId = XATxConverter.getXid(new Uid(), false, 0);
    assertEquals(XAResourceOrphanFilter.Vote.ABSTAIN, orphanFilter.checkXid(notJTAFormatId));
    List<String> recoveryNodes = new LinkedList<String>();
    recoveryNodes.add("1");
    jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(recoveryNodes);
    String notRecoverableNodeName = "2";
    TxControl.setXANodeName(notRecoverableNodeName);
    Xid jtaNotRecoverableNodeName = XATxConverter.getXid(new Uid(), false, XATxConverter.FORMAT_ID);
    assertEquals(XAResourceOrphanFilter.Vote.ABSTAIN, orphanFilter.checkXid(jtaNotRecoverableNodeName));
    String recoverableNodeName = "1";
    TxControl.setXANodeName(recoverableNodeName);
    Xid jtaRecoverableNodeName = XATxConverter.getXid(new Uid(), false, XATxConverter.FORMAT_ID);
    assertEquals(XAResourceOrphanFilter.Vote.ROLLBACK, orphanFilter.checkXid(jtaRecoverableNodeName));
    recoveryNodes.clear();
    recoveryNodes.add(NodeNameXAResourceOrphanFilter.RECOVER_ALL_NODES);
    jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(recoveryNodes);
    assertEquals(XAResourceOrphanFilter.Vote.ROLLBACK, orphanFilter.checkXid(jtaNotRecoverableNodeName));
    assertEquals(XAResourceOrphanFilter.Vote.ROLLBACK, orphanFilter.checkXid(jtaRecoverableNodeName));
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) Xid(javax.transaction.xa.Xid) JTANodeNameXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter) 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)

Aggregations

Uid (com.arjuna.ats.arjuna.common.Uid)2 JTANodeNameXAResourceOrphanFilter (com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter)2 Xid (javax.transaction.xa.Xid)2 Test (org.junit.Test)2 JTAActionStatusServiceXAResourceOrphanFilter (com.arjuna.ats.internal.jta.recovery.arjunacore.JTAActionStatusServiceXAResourceOrphanFilter)1 JTATransactionLogXAResourceOrphanFilter (com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter)1 NodeNameXAResourceOrphanFilter (com.arjuna.ats.internal.jta.recovery.arjunacore.NodeNameXAResourceOrphanFilter)1 SubordinateJTAXAResourceOrphanFilter (com.arjuna.ats.internal.jta.recovery.arjunacore.SubordinateJTAXAResourceOrphanFilter)1 SubordinationManagerXAResourceOrphanFilter (com.arjuna.ats.internal.jta.recovery.arjunacore.SubordinationManagerXAResourceOrphanFilter)1 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)1 XAResourceOrphanFilter (com.arjuna.ats.jta.recovery.XAResourceOrphanFilter)1 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)1 XidImple (com.arjuna.ats.jta.xa.XidImple)1 RecoveryXAResource (com.hp.mwtests.ts.jta.common.RecoveryXAResource)1 LinkedList (java.util.LinkedList)1 XAException (javax.transaction.xa.XAException)1 XAResource (javax.transaction.xa.XAResource)1 XAResourceWrapper (org.jboss.tm.XAResourceWrapper)1