Search in sources :

Example 1 with CrashRecord

use of com.hp.mwtests.ts.arjuna.resources.CrashRecord in project narayana by jbosstm.

the class CrashAction method test.

@Test
public void test() {
    AtomicAction A = new AtomicAction();
    A.begin();
    A.add(new CrashRecord(CrashLocation.NoCrash, CrashType.Normal));
    A.add(new CrashRecord(CrashLocation.CrashInCommit, CrashType.HeuristicHazard));
    int outcome = A.commit();
    System.out.println("Transaction " + A + " committed with " + ActionStatus.stringForm(outcome));
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) CrashRecord(com.hp.mwtests.ts.arjuna.resources.CrashRecord) Test(org.junit.Test)

Example 2 with CrashRecord

use of com.hp.mwtests.ts.arjuna.resources.CrashRecord 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 3 with CrashRecord

use of com.hp.mwtests.ts.arjuna.resources.CrashRecord in project narayana by jbosstm.

the class LogEditorUnitTest method test.

@Test
public void test() throws Exception {
    String localOSRoot = "foobar";
    String objectStoreDir = System.getProperty("java.io.tmpdir") + "/bar";
    arjPropertyManager.getObjectStoreEnvironmentBean().setLocalOSRoot(localOSRoot);
    arjPropertyManager.getObjectStoreEnvironmentBean().setObjectStoreDir(objectStoreDir);
    // dummy to set up ObjectStore
    AtomicAction A = new AtomicAction();
    A.begin();
    A.add(new CrashRecord(CrashRecord.CrashLocation.NoCrash, CrashRecord.CrashType.Normal));
    A.add(new CrashRecord(CrashRecord.CrashLocation.CrashInCommit, CrashRecord.CrashType.HeuristicHazard));
    A.add(new CrashRecord(CrashRecord.CrashLocation.CrashInCommit, CrashRecord.CrashType.HeuristicHazard));
    A.add(new CrashRecord(CrashRecord.CrashLocation.CrashInCommit, CrashRecord.CrashType.HeuristicHazard));
    int outcome = A.commit();
    System.out.println("Transaction " + A + " committed with " + ActionStatus.stringForm(outcome));
    AtomicAction B = new AtomicAction();
    B.begin();
    B.add(new CrashRecord(CrashRecord.CrashLocation.NoCrash, CrashRecord.CrashType.Normal));
    B.add(new CrashRecord(CrashRecord.CrashLocation.CrashInCommit, CrashRecord.CrashType.HeuristicHazard));
    B.add(new CrashRecord(CrashRecord.CrashLocation.CrashInCommit, CrashRecord.CrashType.Normal));
    B.add(new CrashRecord(CrashRecord.CrashLocation.CrashInCommit, CrashRecord.CrashType.HeuristicHazard));
    outcome = B.commit();
    System.out.println("Transaction " + B + " committed with " + ActionStatus.stringForm(outcome));
    RecordTypeManager.manager().add(new DummyMap2());
    EditableAtomicAction eaa = new EditableAtomicAction(B.get_uid());
    assertTrue(eaa.toString() != null);
    eaa.moveHeuristicToPrepared(1);
    try {
        eaa.moveHeuristicToPrepared(-1);
        fail();
    } catch (final Exception ex) {
    }
    eaa = new EditableAtomicAction(A.get_uid());
    eaa.deleteHeuristicParticipant(0);
    try {
        eaa.deleteHeuristicParticipant(-1);
        fail();
    } catch (final Exception ex) {
    }
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) EditableAtomicAction(com.arjuna.ats.internal.arjuna.tools.log.EditableAtomicAction) EditableAtomicAction(com.arjuna.ats.internal.arjuna.tools.log.EditableAtomicAction) CrashRecord(com.hp.mwtests.ts.arjuna.resources.CrashRecord) Test(org.junit.Test)

Aggregations

AtomicAction (com.arjuna.ats.arjuna.AtomicAction)3 CrashRecord (com.hp.mwtests.ts.arjuna.resources.CrashRecord)3 Test (org.junit.Test)2 AbstractRecord (com.arjuna.ats.arjuna.coordinator.AbstractRecord)1 RecordTypeMap (com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap)1 ActionBean (com.arjuna.ats.arjuna.tools.osb.mbean.ActionBean)1 LogRecordWrapper (com.arjuna.ats.arjuna.tools.osb.mbean.LogRecordWrapper)1 OSEntryBean (com.arjuna.ats.arjuna.tools.osb.mbean.OSEntryBean)1 ObjStoreBrowser (com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser)1 UidWrapper (com.arjuna.ats.arjuna.tools.osb.mbean.UidWrapper)1 EditableAtomicAction (com.arjuna.ats.internal.arjuna.tools.log.EditableAtomicAction)1