Search in sources :

Example 46 with AtomicAction

use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.

the class DestroyTest method test.

@Test
public void test() {
    for (int i = 0; i < 100; i++) {
        AtomicAction A = new AtomicAction();
        A.begin();
        BasicObject bo = new BasicObject();
        bo.set(2);
        A.commit();
        AtomicAction B = new AtomicAction();
        AtomicAction C = new AtomicAction();
        B.begin();
        C.begin();
        bo.destroy();
        C.commit();
        B.abort();
        C = new AtomicAction();
        C.begin();
        bo.destroy();
        C.commit();
    }
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) BasicObject(com.hp.mwtests.ts.arjuna.resources.BasicObject) Test(org.junit.Test)

Example 47 with AtomicAction

use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.

the class LogStoreReactivationTest method test.

@Test
public void test() {
    arjPropertyManager.getCoordinatorEnvironmentBean().setCommitOnePhase(false);
    arjPropertyManager.getObjectStoreEnvironmentBean().setObjectStoreType(LogStore.class.getName());
    arjPropertyManager.getObjectStoreEnvironmentBean().setSynchronousRemoval(false);
    // the byteman script will enforce this
    // System.setProperty(Environment.TRANSACTION_LOG_PURGE_TIME, "1000000");  // essentially infinite
    AtomicAction A = new AtomicAction();
    Uid txId = A.get_uid();
    System.err.println("IMPORTANT: ignore warnings about USER_DEF_FIRST0 as they are expected due to BasicRecord usage!");
    A.begin();
    A.add(new BasicRecord());
    A.commit();
    RecoverAtomicAction rAA = new RecoverAtomicAction(txId, ActionStatus.COMMITTED);
    rAA.replayPhase2();
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) RecoverAtomicAction(com.arjuna.ats.arjuna.recovery.RecoverAtomicAction) Uid(com.arjuna.ats.arjuna.common.Uid) LogStore(com.arjuna.ats.internal.arjuna.objectstore.LogStore) BasicRecord(com.hp.mwtests.ts.arjuna.resources.BasicRecord) RecoverAtomicAction(com.arjuna.ats.arjuna.recovery.RecoverAtomicAction) Test(org.junit.Test)

Example 48 with AtomicAction

use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.

the class AtomicActionTestBase method testCompletionWithException.

/**
 * Tests for correct behaviour of synchronisations (in the abnormal case)
 * @throws Exception
 */
protected void testCompletionWithException() throws Exception {
    SyncRecord[] syncs = { new SyncRecord(false, SyncRecord.FailureMode.NONE), new SyncRecord(true, SyncRecord.FailureMode.NONE) };
    RuntimeException exception = new RuntimeException("testCompletionWithException");
    syncs[0].setBeforeThrowable(exception);
    AtomicAction a = executeTest(true, ActionStatus.ABORTED, syncs, new BasicRecord(), new BasicRecord());
    /*
         * since the first synch failed during the beforeCompletion callback:
         * - beforeCompletion should  be called on the first one
         * - beforeCompletion should not be called on the second one
         * - afterCompletion should be called on all synchronisations
         * - the synchronization should have throw the runtime exception
         * - the final status of the action should be aborted
         */
    Assert.assertTrue(syncs[0].getBeforeTimeStamp() != 0);
    Assert.assertTrue(syncs[1].getBeforeTimeStamp() == 0);
    Assert.assertTrue(syncs[0].getAfterTimeStamp() != 0);
    Assert.assertTrue(syncs[1].getAfterTimeStamp() != 0);
    Assert.assertEquals(exception, a.getDeferredThrowable());
    Assert.assertTrue(syncs[1].getStatus() == ActionStatus.ABORTED);
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction)

Example 49 with AtomicAction

use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.

the class AtomicActionTestBase method testHeuristicNotification.

protected void testHeuristicNotification(boolean reportHeuristics) throws Exception {
    AtomicAction A = new AtomicAction();
    DummyHeuristic[] dha = { new DummyHeuristic(), new DummyHeuristic() };
    A.begin();
    A.add(new BasicRecord());
    A.add(new BasicRecord());
    A.add(new HeuristicRecord());
    for (DummyHeuristic dh : dha) A.addSynchronization(dh);
    int status = A.commit(reportHeuristics);
    if (reportHeuristics)
        Assert.assertEquals(ActionStatus.H_MIXED, status);
    else if (!arjPropertyManager.getCoordinatorEnvironmentBean().isAsyncCommit())
        Assert.assertEquals(ActionStatus.COMMITTED, status);
    else
        Assert.assertTrue(status == ActionStatus.COMMITTED || status == ActionStatus.COMMITTING);
    // we only inform synchronisations of the outcome if report_heuristics is false
    int expect = reportHeuristics ? -1 : TwoPhaseOutcome.HEURISTIC_MIXED;
    for (DummyHeuristic dh : dha) Assert.assertEquals(expect, dh.getStatus());
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction)

Example 50 with AtomicAction

use of com.arjuna.ats.arjuna.AtomicAction 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)

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