Search in sources :

Example 1 with XARecoveryModule

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

the class InboundBridgeRecoveryManager method stop.

/**
 * MC lifecycle callback, used to unregister components from the recovery manager.
 */
public void stop() {
    txbridgeLogger.i18NLogger.info_ibrm_stop();
    xtsATRecoveryManager.unregisterRecoveryModule(this);
    acRecoveryManager.removeModule(this, false);
    XARecoveryModule xaRecoveryModule = getXARecoveryModule();
    xaRecoveryModule.removeXAResourceOrphanFilter(this);
}
Also used : XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)

Example 2 with XARecoveryModule

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

the class XARecoveryModuleUnitTest method testNull.

@Test
public void testNull() {
    XARecoveryModule xarm = new XARecoveryModule();
    xarm.periodicWorkFirstPass();
    xarm.periodicWorkSecondPass();
    assertNotNull(xarm.id());
}
Also used : XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Example 3 with XARecoveryModule

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

the class XARecoveryModuleUnitTest method testCanRepeatFirstPass.

@Test
public void testCanRepeatFirstPass() throws Exception {
    XARecoveryModule xarm = new XARecoveryModule();
    xarm.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {

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

        @Override
        public XAResource[] getXAResources() throws Exception {
            return new XAResource[] { 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 {
                    recoverCalled++;
                    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 {
                }
            } };
        }
    });
    xarm.periodicWorkFirstPass();
    assertEquals(recoverCalled, 1);
    xarm.periodicWorkSecondPass();
    assertEquals(recoverCalled, 2);
    xarm.periodicWorkFirstPass();
    assertEquals(recoverCalled, 3);
    xarm.periodicWorkFirstPass();
    assertEquals(recoverCalled, 5);
    xarm.periodicWorkSecondPass();
    assertEquals(recoverCalled, 6);
}
Also used : XAResource(javax.transaction.xa.XAResource) RecoveryXAResource(com.hp.mwtests.ts.jta.common.RecoveryXAResource) Xid(javax.transaction.xa.Xid) XAException(javax.transaction.xa.XAException) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) XAException(javax.transaction.xa.XAException) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Example 4 with XARecoveryModule

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

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

the class XARecoveryModuleUnitTest method testXAResourceRecoveryHelperRegistration.

@Test
public void testXAResourceRecoveryHelperRegistration() {
    XARecoveryModule xaRecoveryModule = new XARecoveryModule();
    XAResourceRecoveryHelper xaResourceRecoveryHelper = new DummyXAResourceRecoveryHelper();
    xaRecoveryModule.addXAResourceRecoveryHelper(xaResourceRecoveryHelper);
    xaRecoveryModule.removeXAResourceRecoveryHelper(xaResourceRecoveryHelper);
}
Also used : XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Aggregations

XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)38 Test (org.junit.Test)25 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)19 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)18 XAResource (javax.transaction.xa.XAResource)17 Xid (javax.transaction.xa.Xid)14 Uid (com.arjuna.ats.arjuna.common.Uid)10 XidImple (com.arjuna.ats.jta.xa.XidImple)9 Enumeration (java.util.Enumeration)9 Vector (java.util.Vector)9 XAException (javax.transaction.xa.XAException)9 CommitMarkableResourceRecordRecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule)8 Connection (java.sql.Connection)8 InitialContext (javax.naming.InitialContext)7 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)7 RecoveryManager (com.arjuna.ats.arjuna.recovery.RecoveryManager)6 ExecuteException (org.jboss.byteman.rule.exception.ExecuteException)6 JTANodeNameXAResourceOrphanFilter (com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter)5 ArrayList (java.util.ArrayList)5 XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)4