Search in sources :

Example 11 with XAResourceRecord

use of com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord in project narayana by jbosstm.

the class XARecoveryModuleUnitTest method testRecover.

@Test
public void testRecover() throws Exception {
    ArrayList<String> r = new ArrayList<String>();
    TransactionImple tx = new TransactionImple(0);
    assertTrue(tx.enlistResource(new RecoveryXAResource()));
    assertEquals(tx.doPrepare(), TwoPhaseOutcome.PREPARE_OK);
    r.add("com.hp.mwtests.ts.jta.recovery.DummyXARecoveryResource");
    jtaPropertyManager.getJTAEnvironmentBean().setXaResourceRecoveryClassNames(r);
    XARecoveryModule xarm = new XARecoveryModule();
    assertNull(xarm.getNewXAResource(new XAResourceRecord(null, null, new XidImple(), null)));
    for (int i = 0; i < 11; i++) {
        xarm.periodicWorkFirstPass();
        xarm.periodicWorkSecondPass();
    }
    assertTrue(xarm.getNewXAResource(new XAResourceRecord(null, null, new XidImple(new Uid()), null)) == null);
    assertNull(xarm.getNewXAResource(new XAResourceRecord(null, null, new XidImple(), null)));
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) XAResourceRecord(com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.TransactionImple) ArrayList(java.util.ArrayList) RecoveryXAResource(com.hp.mwtests.ts.jta.common.RecoveryXAResource) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Example 12 with XAResourceRecord

use of com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord in project narayana by jbosstm.

the class XARecoveryModuleUnitTest method testRecoverFromMultipleXAResourceRecovery.

@Test
public void testRecoverFromMultipleXAResourceRecovery() throws Exception {
    // Make sure the file doesn't exist
    assertFalse(new File("XARR.txt").exists());
    ArrayList<String> r = new ArrayList<String>();
    AtomicAction aa = new AtomicAction();
    aa.begin();
    assertEquals(AddOutcome.AR_ADDED, aa.add(new XAResourceRecord(null, new XARRTestResource(), new XidImple(aa), null)));
    Class c = BasicAction.class;
    Method method = c.getDeclaredMethod("prepare", boolean.class);
    method.setAccessible(true);
    int result = (Integer) method.invoke(aa, new Object[] { true });
    assertEquals(result, TwoPhaseOutcome.PREPARE_OK);
    // Make sure the file exists
    assertTrue(new File("XARR.txt").exists());
    // AtomicActionRecoveryModule aaRecoveryModule = new AtomicActionRecoveryModule();
    // aaRecoveryModule.periodicWorkFirstPass();
    // aaRecoveryModule.periodicWorkSecondPass();
    RecordTypeManager.manager().add(new RecordTypeMap() {

        @SuppressWarnings("unchecked")
        public Class getRecordClass() {
            return XAResourceRecord.class;
        }

        public int getType() {
            return RecordType.JTA_RECORD;
        }
    });
    List<String> xarn = new ArrayList<String>();
    xarn.add(NodeNameXAResourceOrphanFilter.RECOVER_ALL_NODES);
    jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(xarn);
    XARecoveryModule xaRecoveryModule = new XARecoveryModule();
    Field safetyIntervalMillis = RecoveryXids.class.getDeclaredField("safetyIntervalMillis");
    safetyIntervalMillis.setAccessible(true);
    safetyIntervalMillis.set(null, 0);
    xaRecoveryModule.addXAResourceRecoveryHelper(new XARROne());
    xaRecoveryModule.addXAResourceRecoveryHelper(new XARRTwo());
    xaRecoveryModule.addXAResourceOrphanFilter(new com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter());
    xaRecoveryModule.addXAResourceOrphanFilter(new com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter());
    RecoveryManager.manager().addModule(xaRecoveryModule);
    // This is done rather than using the AtomicActionRecoveryModule as the transaction is inflight
    RecoverAtomicAction rcvAtomicAction = new RecoverAtomicAction(aa.get_uid(), ActionStatus.COMMITTED);
    rcvAtomicAction.replayPhase2();
    // The XARM would execute next
    xaRecoveryModule.periodicWorkFirstPass();
    xaRecoveryModule.periodicWorkSecondPass();
    // Make sure the file doesn't exist
    assertFalse(new File("XARR.txt").exists());
    aa.abort();
}
Also used : JTANodeNameXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter) ArrayList(java.util.ArrayList) AtomicAction(com.arjuna.ats.internal.jta.transaction.arjunacore.AtomicAction) RecoverAtomicAction(com.arjuna.ats.arjuna.recovery.RecoverAtomicAction) Field(java.lang.reflect.Field) RecoverAtomicAction(com.arjuna.ats.arjuna.recovery.RecoverAtomicAction) XidImple(com.arjuna.ats.jta.xa.XidImple) XAResourceRecord(com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord) BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) Method(java.lang.reflect.Method) RecordTypeMap(com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap) File(java.io.File) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Example 13 with XAResourceRecord

use of com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord in project narayana by jbosstm.

the class XATerminatorUnitTest method testRecovery.

@Test
public void testRecovery() throws Exception {
    Implementations.initialise();
    XATerminatorImple xa = new XATerminatorImple();
    Xid[] recover = xa.recover(XAResource.TMSTARTRSCAN);
    int initialLength = recover == null ? 0 : recover.length;
    xa.recover(XAResource.TMENDRSCAN);
    XidImple xid = new XidImple(new Uid());
    TransactionImporter imp = SubordinationManager.getTransactionImporter();
    SubordinateTransaction importTransaction = imp.importTransaction(xid);
    importTransaction.enlistResource(new XAResource() {

        @Override
        public void start(Xid xid, int flags) throws XAException {
        }

        @Override
        public void end(Xid xid, int flags) throws XAException {
        }

        @Override
        public int prepare(Xid xid) throws XAException {
            return 0;
        }

        @Override
        public void commit(Xid xid, boolean onePhase) throws XAException {
            throw new XAException(XAException.XA_RETRY);
        }

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

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

        @Override
        public Xid[] recover(int flag) throws XAException {
            return null;
        }

        @Override
        public boolean isSameRM(XAResource xaRes) throws XAException {
            return false;
        }

        @Override
        public int getTransactionTimeout() throws XAException {
            return 0;
        }

        @Override
        public boolean setTransactionTimeout(int seconds) throws XAException {
            return false;
        }
    });
    assertTrue(xa.beforeCompletion(xid));
    assertEquals(xa.prepare(xid), XAResource.XA_OK);
    try {
        xa.commit(xid, false);
        fail();
    } catch (XAException e) {
        assertTrue(e.errorCode == XAException.XAER_RMFAIL);
    }
    Xid[] recover2 = xa.recover(XAResource.TMSTARTRSCAN);
    assertTrue(recover2.length == initialLength + 1);
    try {
        xa.commit(xid, false);
        fail();
    } catch (XAException e) {
        assertTrue("Wrong errorcode" + e.errorCode, e.errorCode == XAException.XAER_RMFAIL);
    }
    xa.recover(XAResource.TMENDRSCAN);
    // Feed the recovery manager with something it can recover with
    RecoveryModule module = new XARecoveryModule() {

        @Override
        public XAResource getNewXAResource(final XAResourceRecord xaResourceRecord) {
            return new XAResource() {

                @Override
                public void start(Xid xid, int flags) throws XAException {
                }

                @Override
                public void end(Xid xid, int flags) throws XAException {
                }

                @Override
                public int prepare(Xid xid) throws XAException {
                    return 0;
                }

                @Override
                public void commit(Xid xid, boolean onePhase) throws XAException {
                }

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

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

                @Override
                public Xid[] recover(int flag) throws XAException {
                    return null;
                }

                @Override
                public boolean isSameRM(XAResource xaRes) throws XAException {
                    return false;
                }

                @Override
                public int getTransactionTimeout() throws XAException {
                    return 0;
                }

                @Override
                public boolean setTransactionTimeout(int seconds) throws XAException {
                    return false;
                }
            };
        }
    };
    RecoveryManager.manager().addModule(module);
    try {
        Xid[] recover3 = xa.recover(XAResource.TMSTARTRSCAN);
        assertTrue(recover3.length == recover2.length);
        xa.commit(xid, false);
        xa.recover(XAResource.TMENDRSCAN);
        Xid[] recover4 = xa.recover(XAResource.TMSTARTRSCAN);
        assertTrue(recover4 == null || recover4.length == initialLength);
        xa.recover(XAResource.TMENDRSCAN);
    } finally {
        RecoveryManager.manager().removeModule(module, false);
    }
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) XAException(javax.transaction.xa.XAException) XAResourceRecord(com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord) Uid(com.arjuna.ats.arjuna.common.Uid) Xid(javax.transaction.xa.Xid) FailureXAResource(com.hp.mwtests.ts.jta.common.FailureXAResource) XAResource(javax.transaction.xa.XAResource) TransactionImporter(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.TransactionImporter) XATerminatorImple(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.XATerminatorImple) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) SubordinateTransaction(com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Example 14 with XAResourceRecord

use of com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord in project narayana by jbosstm.

the class XAResourceRecordUnitTest method testValid2PC.

@Test
public void testValid2PC() throws Exception {
    TransactionImple tx = new TransactionImple(0);
    DummyXA res = new DummyXA(false);
    XAResourceRecord xares = new XAResourceRecord(tx, res, tx.getTxId(), null);
    assertEquals(xares.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(xares.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
}
Also used : DummyXA(com.hp.mwtests.ts.jta.common.DummyXA) XAResourceRecord(com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) Test(org.junit.Test)

Example 15 with XAResourceRecord

use of com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord in project narayana by jbosstm.

the class XAResourceRecordUnitTest method testRollbackFailure.

@Test
public void testRollbackFailure() throws Exception {
    FailureXAResource fxa = new FailureXAResource(FailureXAResource.FailLocation.rollback);
    TransactionImple tx = new TransactionImple(0);
    XAResourceRecord xares = new XAResourceRecord(tx, fxa, tx.getTxId(), null);
    assertEquals(xares.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(xares.topLevelAbort(), TwoPhaseOutcome.HEURISTIC_MIXED);
    assertTrue(xares.forgetHeuristic());
}
Also used : XAResourceRecord(com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord) FailureXAResource(com.hp.mwtests.ts.jta.common.FailureXAResource) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) Test(org.junit.Test)

Aggregations

XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)16 Test (org.junit.Test)15 XidImple (com.arjuna.ats.jta.xa.XidImple)9 TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple)7 Uid (com.arjuna.ats.arjuna.common.Uid)5 XAResource (javax.transaction.xa.XAResource)5 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)4 DummyXA (com.hp.mwtests.ts.jta.common.DummyXA)4 FailureXAResource (com.hp.mwtests.ts.jta.common.FailureXAResource)4 Xid (javax.transaction.xa.Xid)4 DummyRecoverableXAConnection (com.hp.mwtests.ts.jta.common.DummyRecoverableXAConnection)3 SubordinateAtomicAction (com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction)2 ArrayList (java.util.ArrayList)2 XAException (javax.transaction.xa.XAException)2 BasicAction (com.arjuna.ats.arjuna.coordinator.BasicAction)1 RecordTypeMap (com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap)1 RecoverAtomicAction (com.arjuna.ats.arjuna.recovery.RecoverAtomicAction)1 RecoveryManager (com.arjuna.ats.arjuna.recovery.RecoveryManager)1 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)1 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)1