use of com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap in project narayana by jbosstm.
the class OrderedOnePhaseResourcesUnitTest method testOrderedOnePhase.
@Test
public void testOrderedOnePhase() throws Exception {
System.setProperty("com.arjuna.ats.arjuna.common.propertiesFile", "jbossts-properties.xml");
Uid firstToCommit = new Uid();
Uid secondToCommit = new Uid();
AtomicAction A = new AtomicAction();
// These user defined records could wrap anything such as 1PC JDBC or messages
OrderedOnePhaseAbstractRecord rec1 = new OrderedOnePhaseAbstractRecord(secondToCommit);
OrderedOnePhaseAbstractRecord rec2 = new OrderedOnePhaseAbstractRecord(firstToCommit);
A.begin();
// Doesn't matter of the order
A.add(rec1);
A.add(rec2);
// Do some work you could save some concept of the work in the abstract record save_state
// rec1.sendMessage
// rec2.doSQL
// This is just so we can see the opportunity for failure recovery
rec1.causeTransientFailure();
// Commit, this would make sure the database (rec2) was committed first
A.commit();
// This shows recovery working, we should see Uid2 called again, if you had encoded some information in rec2 you could
// maybe
// retry the sending of a message or similar
RecordTypeManager.manager().add(new RecordTypeMap() {
@Override
public int getType() {
return OrderedOnePhaseAbstractRecord.typeId();
}
@Override
public Class<? extends AbstractRecord> getRecordClass() {
return OrderedOnePhaseAbstractRecord.class;
}
});
recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(1);
RecoveryManager.manager(RecoveryManager.DIRECT_MANAGEMENT).addModule(new AtomicActionRecoveryModule());
RecoveryManager.manager().scan();
}
use of com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap in project narayana by jbosstm.
the class ObjStoreBrowserTest method aaTest.
public void aaTest(boolean replay) throws Exception {
ObjStoreBrowser osb = createObjStoreBrowser();
AtomicAction A = new AtomicAction();
CrashRecord[] recs = { new CrashRecord(CrashRecord.CrashLocation.NoCrash, CrashRecord.CrashType.Normal), new CrashRecord(CrashRecord.CrashLocation.CrashInCommit, CrashRecord.CrashType.HeuristicHazard) };
// register CrashRecord record type so that it is persisted in the object store correctly
RecordTypeManager.manager().add(new RecordTypeMap() {
public Class<? extends AbstractRecord> getRecordClass() {
return CrashRecord.class;
}
public int getType() {
return RecordType.USER_DEF_FIRST0;
}
});
// create an atomic action, register crash records with it and then commit
A.begin();
for (CrashRecord rec : recs) A.add(rec);
int outcome = A.commit();
// the second participant should have generated a heuristic during commit
assertEquals(ActionStatus.H_HAZARD, outcome);
// generate MBeans representing the atomic action that was just committed
osb.start();
osb.probe();
// there should be one MBean corresponding to the AtomicAction A
UidWrapper w = osb.findUid(A.get_uid());
assertNotNull(w);
OSEntryBean ai = w.getMBean();
assertNotNull(ai);
// the MBean should wrap an ActionBean
assertTrue(ai instanceof ActionBean);
ActionBean actionBean = (ActionBean) ai;
// and there should be one MBean corresponding to the CrashRecord that got the heuristic:
int recCount = 0;
for (CrashRecord rec : recs) {
LogRecordWrapper lw = actionBean.getParticipant(rec);
if (lw != null) {
recCount += 1;
assertTrue(lw.isHeuristic());
// put the participant back onto the pending list
lw.setStatus("PREPARED");
// and check that the record is no longer in a heuristic state
assertFalse(lw.isHeuristic());
}
}
assertEquals(1, recCount);
if (!replay) {
actionBean.remove();
} else {
/*
* prompt the recovery manager to replay the record that was
* moved off the heuristic list and back onto the prepared list
*/
rcm.scan();
}
/*
* Since the recovery scan (or explicit remove request) will have successfully removed the record from
* the object store another probe should cause the MBean representing the record to be unregistered
*/
osb.probe();
// look up the MBean and verify that it no longer exists
w = osb.findUid(A.get_uid());
assertNull(w);
osb.dump(new StringBuilder());
osb.stop();
}
use of com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap in project narayana by jbosstm.
the class HeuristicInformationTest method heuristicInformationTest.
@Test
public void heuristicInformationTest() throws Exception {
ArjunaTransactionImple A = new ArjunaTransactionImple(null);
int expectedHeuristic = TwoPhaseOutcome.HEURISTIC_ROLLBACK;
ThreadActionData.purgeActions();
UserExtendedCrashRecord[] recs = { new UserExtendedCrashRecord(UserExtendedCrashRecord.CrashLocation.NoCrash, UserExtendedCrashRecord.CrashType.Normal, null), new UserExtendedCrashRecord(UserExtendedCrashRecord.CrashLocation.CrashInCommit, UserExtendedCrashRecord.CrashType.HeuristicHazard, // this value will override HeuristicHazard
new UserExtendedCrashRecord.HeuristicInformationOverride(expectedHeuristic)) };
RecordTypeManager.manager().add(new RecordTypeMap() {
public Class<? extends AbstractRecord> getRecordClass() {
return UserExtendedCrashRecord.class;
}
public int getType() {
return RecordType.USER_DEF_FIRST1;
}
});
A.start();
for (UserExtendedCrashRecord rec : recs) A.add(rec);
try {
A.commit(true);
fail("transaction commit should have produced a heuristic hazard");
} catch (HeuristicHazard e) {
// expected
}
ObjStoreBrowser osb = getOSB();
osb.start();
osb.probe();
// there should now be an MBean entry corresponding to a JTS record, read it via JMX:
MBeanServer mbs = JMXServer.getAgent().getServer();
UidWrapper w = osb.findUid(A.get_uid());
ObjectName txnON = new ObjectName(w.getName());
Object aid = mbs.getAttribute(txnON, "Id");
assertNotNull(aid);
Set<ObjectName> participants = mbs.queryNames(new ObjectName(w.getName() + ",puid=*"), null);
for (ObjectName on : participants) {
AttributeList al = mbs.getAttributes(on, new String[] { "Id", "Status", "HeuristicStatus", "GlobalTransactionId" });
for (Attribute a : al.asList()) {
if ("HeuristicStatus".equals(a.getName())) {
HeuristicStatus ahs = HeuristicStatus.valueOf(a.getValue().toString());
HeuristicStatus ehs = HeuristicStatus.intToStatus(expectedHeuristic);
// assert that the instrumented heuristic status has the expected value
assertTrue(ahs.equals(ehs));
}
}
}
}
use of com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap 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.arjuna.coordinator.abstractrecord.RecordTypeMap in project narayana by jbosstm.
the class XATerminatorUnitTest method testCommitMid.
@Test
public void testCommitMid() throws Exception {
TransactionManagerImple tm = new TransactionManagerImple();
RecordTypeManager.manager().add(new RecordTypeMap() {
@SuppressWarnings("unchecked")
public Class getRecordClass() {
return XAResourceRecord.class;
}
public int getType() {
return RecordType.JTA_RECORD;
}
});
XATerminatorImple xaTerminator = new XATerminatorImple();
XidImple xid = new XidImple(new Uid());
XAResourceImple toCommit = new XAResourceImple(XAResource.XA_OK, XAResource.XA_OK);
{
SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().importTransaction(xid);
tm.resume(subordinateTransaction);
subordinateTransaction.enlistResource(new XAResourceImple(XAResource.XA_RDONLY, XAResource.XA_OK));
subordinateTransaction.enlistResource(toCommit);
Transaction suspend = tm.suspend();
}
{
SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
tm.resume(subordinateTransaction);
subordinateTransaction.doPrepare();
Transaction suspend = tm.suspend();
}
XARecoveryModule xaRecoveryModule = new XARecoveryModule();
xaRecoveryModule.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {
@Override
public boolean initialise(String p) throws Exception {
return false;
}
@Override
public XAResource[] getXAResources() throws Exception {
return new XAResource[] { toCommit };
}
});
RecoveryManager.manager().addModule(xaRecoveryModule);
xaTerminator.doRecover(null, null);
{
SubordinateTransaction subordinateTransaction = SubordinationManager.getTransactionImporter().getImportedTransaction(xid);
tm.resume(subordinateTransaction);
subordinateTransaction.doCommit();
tm.suspend();
}
RecoveryManager.manager().removeModule(xaRecoveryModule, false);
assertTrue(toCommit.wasCommitted());
SubordinationManager.getTransactionImporter().removeImportedTransaction(xid);
}
Aggregations