use of com.arjuna.ats.jta.recovery.XAResourceOrphanFilter in project narayana by jbosstm.
the class XAResourceOrphanFilterTest method testJTAActionStatusServiceXAResourceOrphanFilter.
@Test
public void testJTAActionStatusServiceXAResourceOrphanFilter() {
XAResourceOrphanFilter orphanFilter = new JTAActionStatusServiceXAResourceOrphanFilter();
List<String> xaRecoveryNodes = jtaPropertyManager.getJTAEnvironmentBean().getXaRecoveryNodes();
List<String> recoveryNodes = new LinkedList<String>();
recoveryNodes.add("1");
jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(recoveryNodes);
try {
Uid uid = new Uid();
Xid xid = XATxConverter.getXid(uid, false, XATxConverter.FORMAT_ID);
assertEquals(XAResourceOrphanFilter.Vote.ROLLBACK, orphanFilter.checkXid(xid));
TwoPhaseCoordinator tpc = new TwoPhaseCoordinator(uid);
try {
tpc.start();
assertEquals(XAResourceOrphanFilter.Vote.LEAVE_ALONE, orphanFilter.checkXid(xid));
} finally {
tpc.cancel();
}
assertEquals(XAResourceOrphanFilter.Vote.ROLLBACK, orphanFilter.checkXid(xid));
jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(null);
TwoPhaseCoordinator tpc2 = new TwoPhaseCoordinator(uid);
tpc2.start();
assertEquals(XAResourceOrphanFilter.Vote.ABSTAIN, orphanFilter.checkXid(xid));
tpc2.cancel();
} finally {
jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(xaRecoveryNodes);
}
}
use of com.arjuna.ats.jta.recovery.XAResourceOrphanFilter in project narayana by jbosstm.
the class XAResourceOrphanFilterTest method testJTAActionStatusServiceXAResourceOrphanFilterSubordinate.
@Test
public void testJTAActionStatusServiceXAResourceOrphanFilterSubordinate() throws HeuristicRollbackException, HeuristicMixedException, HeuristicCommitException, SystemException, RollbackException, XAException {
XAResourceOrphanFilter orphanFilter = new SubordinationManagerXAResourceOrphanFilter();
List<String> xaRecoveryNodes = jtaPropertyManager.getJTAEnvironmentBean().getXaRecoveryNodes();
List<String> recoveryNodes = new LinkedList<String>();
recoveryNodes.add("1");
jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(recoveryNodes);
final List<String> recoveryExtensions = new ArrayList<String>();
recoveryExtensions.add(com.arjuna.ats.internal.jta.recovery.arjunacore.SubordinateAtomicActionRecoveryModule.class.getName());
recoveryExtensions.add(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule.class.getName());
recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryModuleClassNames(recoveryExtensions);
int recoveryBackoffPeriod = recoveryPropertyManager.getRecoveryEnvironmentBean().getRecoveryBackoffPeriod();
recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(1);
RecoveryManager.manager().scan();
recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(recoveryBackoffPeriod);
try {
Xid xid = XATxConverter.getXid(Uid.nullUid(), false, XATxConverter.FORMAT_ID);
assertEquals(XAResourceOrphanFilter.Vote.ABSTAIN, orphanFilter.checkXid(xid));
SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().importTransaction(xid);
final List<Xid> xids = new ArrayList<Xid>();
XAResource xar = new SimpleXAResource() {
@Override
public void start(Xid xid, int flags) throws XAException {
super.start(xid, flags);
xids.add(xid);
}
};
subordinateTransaction.enlistResource(xar);
try {
assertEquals(XAResourceOrphanFilter.Vote.LEAVE_ALONE, orphanFilter.checkXid(xids.get(0)));
} finally {
subordinateTransaction.doRollback();
}
assertEquals(XAResourceOrphanFilter.Vote.LEAVE_ALONE, orphanFilter.checkXid(xids.get(0)));
SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
assertEquals(XAResourceOrphanFilter.Vote.ROLLBACK, orphanFilter.checkXid(xids.get(0)));
} finally {
jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(xaRecoveryNodes);
recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryModuleClassNames(null);
}
}
use of com.arjuna.ats.jta.recovery.XAResourceOrphanFilter in project narayana by jbosstm.
the class XARecoveryModule method handleOrphan.
/**
* Apply use configurable filtering to determine how to handle the in-doubt resource.
*
* @param xares
* @param xid
* @return true if forget should be called, false otherwise.
*/
private boolean handleOrphan(XAResource xares, Xid xid) {
// be default we play it safe and leave resources alone unless a filter explicitly recognizes them.
// getting presumed abort behaviour therefore requires appropriate filters to be registered.
XAResourceOrphanFilter.Vote votingOutcome = XAResourceOrphanFilter.Vote.LEAVE_ALONE;
for (XAResourceOrphanFilter filter : _xaResourceOrphanFilters) {
XAResourceOrphanFilter.Vote vote = filter.checkXid(xid);
if (jtaLogger.logger.isDebugEnabled()) {
jtaLogger.logger.debug("XAResourceOrphanFilter " + filter.getClass().getName() + " voted " + vote);
}
if (vote == XAResourceOrphanFilter.Vote.LEAVE_ALONE) {
return false;
} else if (vote == XAResourceOrphanFilter.Vote.ROLLBACK) {
votingOutcome = vote;
}
}
try {
if (votingOutcome == XAResourceOrphanFilter.Vote.ROLLBACK) {
jtaLogger.i18NLogger.info_recovery_rollingback(XAHelper.xidToString(xid));
xares.rollback(xid);
}
} catch (XAException e1) {
if (e1.errorCode == XAException.XAER_NOTA) {
if (jtaLogger.logger.isDebugEnabled()) {
jtaLogger.logger.debug(_logName + ".xaRecovery: XAER_NOTA received while rolling back " + XAHelper.xidToString(xid));
}
} else {
jtaLogger.i18NLogger.warn_recovery_xarecovery1(_logName + ".xaRecovery", XAHelper.printXAErrorCode(e1), e1);
}
switch(e1.errorCode) {
case XAException.XAER_RMERR:
break;
case XAException.XA_HEURHAZ:
case XAException.XA_HEURCOM:
case XAException.XA_HEURMIX:
case XAException.XA_HEURRB:
case XAException.XA_RBROLLBACK:
{
return true;
}
default:
break;
}
} catch (Exception e2) {
jtaLogger.i18NLogger.warn_recovery_xarecovery2(_logName + ".xaRecovery", e2);
}
return false;
}
use of com.arjuna.ats.jta.recovery.XAResourceOrphanFilter in project narayana by jbosstm.
the class XARecoveryModuleUnitTest method testXAResourceOrphanFilterRegistration.
@Test
public void testXAResourceOrphanFilterRegistration() {
XARecoveryModule xaRecoveryModule = new XARecoveryModule();
XAResourceOrphanFilter xaResourceOrphanFilter = new DummyXAResourceOrphanFilter();
xaRecoveryModule.addXAResourceOrphanFilter(xaResourceOrphanFilter);
xaRecoveryModule.removeXAResourceOrphanFilter(xaResourceOrphanFilter);
}
use of com.arjuna.ats.jta.recovery.XAResourceOrphanFilter in project narayana by jbosstm.
the class XARecoveryModuleUnitTest method testXAResourceOrphanFilter.
@Test
public void testXAResourceOrphanFilter() throws Exception {
XAResourceOrphanFilter xaResourceOrphanFilter = new DummyXAResourceOrphanFilter(XAResourceOrphanFilter.Vote.ROLLBACK);
XARecoveryModule xarm = new XARecoveryModule();
xarm.addXAResourceOrphanFilter(xaResourceOrphanFilter);
Class[] parameterTypes = new Class[2];
parameterTypes[0] = XAResource.class;
parameterTypes[1] = Xid.class;
Method m = xarm.getClass().getDeclaredMethod("handleOrphan", parameterTypes);
m.setAccessible(true);
Object[] parameters = new Object[2];
parameters[0] = new RecoveryXAResource();
parameters[1] = new XidImple();
m.invoke(xarm, parameters);
}
Aggregations