use of com.arjuna.ats.arjuna.recovery.ActionStatusService in project narayana by jbosstm.
the class ActionStatusServiceTest method runTest.
public void runTest(int crashType, String[] expectedStatus, boolean doAbort) {
ActionStatusService _test_service = new ActionStatusService();
AtomicAction _transaction_1 = new AtomicAction();
String _test_tran_type_1 = _transaction_1.type();
Uid _test_uid_1 = _transaction_1.getSavingUid();
String test_uid = _test_uid_1.toString();
String test_type = _test_tran_type_1;
assertEquals(expectedStatus[0], ActionStatus.stringForm(_test_service.getTransactionStatus(test_type, test_uid)));
assertEquals(expectedStatus[0], ActionStatus.stringForm(_test_service.getTransactionStatus("", test_uid)));
_transaction_1.begin();
CrashAbstractRecordImpl cr1 = new CrashAbstractRecordImpl(crashType);
CrashAbstractRecordImpl cr2 = new CrashAbstractRecordImpl(crashType);
assertEquals(AddOutcome.AR_ADDED, _transaction_1.add(cr1));
assertEquals(AddOutcome.AR_ADDED, _transaction_1.add(cr2));
assertEquals(expectedStatus[1], ActionStatus.stringForm(_test_service.getTransactionStatus(test_type, test_uid)));
assertEquals(expectedStatus[1], ActionStatus.stringForm(_test_service.getTransactionStatus("", test_uid)));
if (doAbort) {
_transaction_1.abort();
} else {
_transaction_1.commit();
}
assertEquals(expectedStatus[2], ActionStatus.stringForm(_test_service.getTransactionStatus(test_type, test_uid)));
assertEquals(expectedStatus[2], ActionStatus.stringForm(_test_service.getTransactionStatus("", test_uid)));
}
use of com.arjuna.ats.arjuna.recovery.ActionStatusService in project narayana by jbosstm.
the class JTAActionStatusServiceXAResourceOrphanFilter method checkXid.
@Override
public Vote checkXid(Xid xid) {
if (xid.getFormatId() != XATxConverter.FORMAT_ID) {
// we only care about Xids created by the JTA
return Vote.ABSTAIN;
}
XidImple theXid = new XidImple(xid);
Uid u = theXid.getTransactionUid();
List<String> xaRecoveryNodes = jtaPropertyManager.getJTAEnvironmentBean().getXaRecoveryNodes();
String nodeName = XAUtils.getXANodeName(xid);
if (jtaLogger.logger.isDebugEnabled()) {
jtaLogger.logger.debug("node name of " + xid + " is " + nodeName);
}
if (xaRecoveryNodes == null || xaRecoveryNodes.size() == 0 || (!xaRecoveryNodes.contains(nodeName) && !xaRecoveryNodes.contains(NodeNameXAResourceOrphanFilter.RECOVER_ALL_NODES))) {
return Vote.ABSTAIN;
}
String process_id = u.getHexPid();
if (process_id.equals(LOCAL_UID.getHexPid())) {
ActionStatusService ass = new ActionStatusService();
int transactionStatus = ass.getTransactionStatus("", u.stringForm());
if (transactionStatus == ActionStatus.ABORTED) {
// Known about and completed
return Vote.ROLLBACK;
} else if (transactionStatus == ActionStatus.NO_ACTION) {
// Not used by current implementation but possible in protocol
return Vote.ABSTAIN;
} else {
// Local transaction in-flight
return Vote.LEAVE_ALONE;
}
} else {
// For a different JVM
return Vote.ABSTAIN;
}
}
use of com.arjuna.ats.arjuna.recovery.ActionStatusService in project narayana by jbosstm.
the class CrashRecoveryCommitReturnsXA_RETRYHeuristicRollback method testHeuristicRollback.
@Test
public void testHeuristicRollback() throws Exception {
// this test is supposed to leave a record around in the log store
// during a commit long enough
// that the periodic recovery thread runs and detects it. rather than
// rely on delays to make
// this happen (placing us at the mercy of the scheduler) we use a
// byteman script to enforce
// the thread sequence we need
RecoveryEnvironmentBean recoveryEnvironmentBean = BeanPopulator.getDefaultInstance(RecoveryEnvironmentBean.class);
// JBTM-1354 we need to make sure that a full scan has gone off
recoveryEnvironmentBean.setRecoveryBackoffPeriod(1);
recoveryEnvironmentBean.setPeriodicRecoveryPeriod(Integer.MAX_VALUE);
List<String> recoveryModuleClassNames = new ArrayList<String>();
recoveryModuleClassNames.add("com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule");
recoveryModuleClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule");
recoveryEnvironmentBean.setRecoveryModuleClassNames(recoveryModuleClassNames);
List<String> expiryScannerClassNames = new ArrayList<String>();
expiryScannerClassNames.add("com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionStatusManagerScanner");
recoveryEnvironmentBean.setExpiryScannerClassNames(expiryScannerClassNames);
recoveryEnvironmentBean.setRecoveryActivators(null);
// start the recovery manager
RecoveryManager.manager().initialize();
XARecoveryModule xaRecoveryModule = null;
for (RecoveryModule recoveryModule : ((Vector<RecoveryModule>) RecoveryManager.manager().getModules())) {
if (recoveryModule instanceof XARecoveryModule) {
xaRecoveryModule = (XARecoveryModule) recoveryModule;
break;
}
}
if (xaRecoveryModule == null) {
throw new Exception("No XARM");
}
// JBTM-1354 Run a scan to make sure that the recovery thread has completed a full run before starting the test
// The important thing is that replayCompletion is allowed to do a scan of the transactions
RecoveryManager.manager().scan();
XAResource firstResource = new SimpleResource();
Object toWakeUp = new Object();
final SimpleResourceXA_RETRYHeuristicRollback secondResource = new SimpleResourceXA_RETRYHeuristicRollback();
xaRecoveryModule.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {
@Override
public boolean initialise(String p) throws Exception {
// TODO Auto-generated method stub
return true;
}
@Override
public XAResource[] getXAResources() throws Exception {
// TODO Auto-generated method stub
return new XAResource[] { secondResource };
}
});
// ok, now drive a TX to completion. the script should ensure that the
// recovery
javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
tm.begin();
javax.transaction.Transaction theTransaction = tm.getTransaction();
Uid txUid = ((TransactionImple) theTransaction).get_uid();
theTransaction.enlistResource(firstResource);
theTransaction.enlistResource(secondResource);
assertFalse(secondResource.wasCommitted());
tm.commit();
InputObjectState uids = new InputObjectState();
String type = new AtomicAction().type();
StoreManager.getRecoveryStore().allObjUids(type, uids);
boolean moreUids = true;
boolean found = false;
while (moreUids) {
Uid theUid = UidHelper.unpackFrom(uids);
if (theUid.equals(txUid)) {
found = true;
Field heuristicListField = BasicAction.class.getDeclaredField("heuristicList");
heuristicListField.setAccessible(true);
ActionStatusService ass = new ActionStatusService();
{
int theStatus = ass.getTransactionStatus(type, theUid.stringForm());
assertTrue(theStatus == ActionStatus.COMMITTED);
RecoverAtomicAction rcvAtomicAction = new RecoverAtomicAction(theUid, theStatus);
theStatus = rcvAtomicAction.status();
rcvAtomicAction.replayPhase2();
assertTrue(theStatus == ActionStatus.COMMITTED);
assertTrue(secondResource.wasCommitted());
RecordList heuristicList = (RecordList) heuristicListField.get(rcvAtomicAction);
assertTrue("Expected 1 heuristics: " + heuristicList.size(), heuristicList.size() == 1);
}
{
int theStatus = ass.getTransactionStatus(type, theUid.stringForm());
assertTrue(theStatus == ActionStatus.COMMITTED);
RecoverAtomicAction rcvAtomicAction = new RecoverAtomicAction(theUid, theStatus);
theStatus = rcvAtomicAction.status();
assertTrue(theStatus == ActionStatus.COMMITTED);
RecordList heuristicList = (RecordList) heuristicListField.get(rcvAtomicAction);
assertTrue("Expected 1 heuristics: " + heuristicList.size(), heuristicList.size() == 1);
assertTrue(secondResource.wasCommitted());
}
} else if (theUid.equals(Uid.nullUid())) {
moreUids = false;
}
}
if (!found) {
throw new Exception("Could not locate the Uid");
}
}
Aggregations