use of com.arjuna.ats.arjuna.AtomicAction 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.AtomicAction in project narayana by jbosstm.
the class BasicThreadedObject method run.
public void run() {
if (startAction) {
BasicThreadedObject.A = new AtomicAction();
System.out.println("BasicThreadedObject " + uid + " created action " + BasicThreadedObject.A.get_uid());
BasicThreadedObject.A.begin();
Thread.yield();
} else {
System.out.println("BasicThreadedObject " + uid + " adding to action " + BasicThreadedObject.A.get_uid());
BasicThreadedObject.A.addThread();
Thread.yield();
}
BasicAction act = BasicAction.Current();
if (act != null)
System.out.println("BasicThreadedObject " + uid + " current action " + act.get_uid());
else
System.out.println("BasicThreadedObject " + uid + " current action null");
try {
BasicThreadedObject.O.incr(4);
Thread.yield();
} catch (TestException e) {
}
if (startAction) {
System.out.println("\nBasicThreadedObject " + uid + " committing action " + act.get_uid());
BasicThreadedObject.A.commit();
System.out.println("BasicThreadedObject " + uid + " action " + act.get_uid() + " committed\n");
} else {
System.out.println("\nBasicThreadedObject " + uid + " aborting action " + act.get_uid());
BasicThreadedObject.A.abort();
System.out.println("BasicThreadedObject " + uid + " action " + act.get_uid() + " aborted\n");
}
}
use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.
the class RecoverableObject method set.
public boolean set(int value) {
AtomicAction A = new AtomicAction();
A.begin();
if (setlock(new Lock(LockMode.WRITE)) == LockResult.GRANTED) {
state = value;
if (A.commit() == ActionStatus.COMMITTED)
return true;
else
return false;
}
A.abort();
return false;
}
use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.
the class ReaperMonitorTest method test.
@Test
public void test() {
TransactionReaper reaper = TransactionReaper.transactionReaper();
DummyMonitor listener = new DummyMonitor();
reaper.addListener(listener);
AtomicAction A = new AtomicAction();
A.begin();
/*
* the reaper byteman script will make sure we synchronize with the reaper after this call
* just before it schedules the reapable for processing. the timout in the check method is
* there in case something is really wrong and the reapable does not get cancelled
*/
reaper.insert(A, 1);
assertTrue(listener.checkSucceeded(30 * 1000));
assertTrue(reaper.removeListener(listener));
// insert a new transaction with a longer timeout and check that we can find the remaining time
A = new AtomicAction();
reaper.insert(A, 1000);
long remaining = reaper.getRemainingTimeoutMills(A);
assertTrue(remaining != 0);
// ok now remove it
reaper.remove(A);
}
use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.
the class LogMoveTest method test.
@Test
public void test() {
RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
OutputObjectState fluff = new OutputObjectState();
Uid kungfuTx = new Uid();
boolean passed = false;
final String tn = new AtomicAction().type();
try {
UidHelper.packInto(kungfuTx, fluff);
System.err.println("Creating dummy log");
recoveryStore.write_committed(kungfuTx, tn, fluff);
if (recoveryStore.currentState(kungfuTx, tn) == StateStatus.OS_COMMITTED) {
System.err.println("Wrote dummy transaction " + kungfuTx);
// quicker to deal with scanner directly
ExpiredTransactionScanner scanner = new ExpiredTransactionScanner(tn, "/StateManager/ExpiredEntries");
scanner.scan();
scanner.scan();
if (recoveryStore.currentState(kungfuTx, tn) == StateStatus.OS_COMMITTED)
System.err.println("Transaction log not moved!");
else {
System.err.println("Transaction log moved!");
passed = true;
}
} else
System.err.println("State is not committed!");
} catch (final Exception ex) {
ex.printStackTrace();
}
assertTrue(passed);
}
Aggregations