Search in sources :

Example 76 with AtomicAction

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();
}
Also used : OSEntryBean(com.arjuna.ats.arjuna.tools.osb.mbean.OSEntryBean) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord) ObjStoreBrowser(com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser) ActionBean(com.arjuna.ats.arjuna.tools.osb.mbean.ActionBean) CrashRecord(com.hp.mwtests.ts.arjuna.resources.CrashRecord) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) RecordTypeMap(com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap) UidWrapper(com.arjuna.ats.arjuna.tools.osb.mbean.UidWrapper) LogRecordWrapper(com.arjuna.ats.arjuna.tools.osb.mbean.LogRecordWrapper)

Example 77 with AtomicAction

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");
    }
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException)

Example 78 with AtomicAction

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;
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) Lock(com.arjuna.ats.txoj.Lock)

Example 79 with AtomicAction

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);
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) TransactionReaper(com.arjuna.ats.arjuna.coordinator.TransactionReaper) Test(org.junit.Test)

Example 80 with AtomicAction

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);
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) ExpiredTransactionScanner(com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionScanner) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore) Test(org.junit.Test)

Aggregations

AtomicAction (com.arjuna.ats.arjuna.AtomicAction)179 Test (org.junit.Test)73 Uid (com.arjuna.ats.arjuna.common.Uid)31 TestException (com.hp.mwtests.ts.txoj.common.exceptions.TestException)30 AtomicObject (com.hp.mwtests.ts.txoj.common.resources.AtomicObject)18 Lock (com.arjuna.ats.txoj.Lock)17 RecoverableContainer (org.jboss.stm.internal.RecoverableContainer)8 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)7 PrintWriter (java.io.PrintWriter)7 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)5 ExtendedObject (com.hp.mwtests.ts.arjuna.resources.ExtendedObject)5 Container (org.jboss.stm.Container)5 RecoverAtomicAction (com.arjuna.ats.arjuna.recovery.RecoverAtomicAction)4 BasicRecord (com.hp.mwtests.ts.arjuna.resources.BasicRecord)4 TopLevelAction (com.arjuna.ats.arjuna.TopLevelAction)3 AbstractRecord (com.arjuna.ats.arjuna.coordinator.AbstractRecord)3 BasicAction (com.arjuna.ats.arjuna.coordinator.BasicAction)3 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)3 LogStore (com.arjuna.ats.internal.arjuna.objectstore.LogStore)3 EditableAtomicAction (com.arjuna.ats.internal.arjuna.tools.log.EditableAtomicAction)3