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)));
}
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();
}
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);
}
}
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);
}
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());
}
Aggregations