Search in sources :

Example 86 with AtomicAction

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

the class AtomicObjectTest2 method get12.

private static void get12(char thr, int level) {
    boolean res = true;
    boolean res1 = true;
    boolean res2 = true;
    int value1 = 0;
    int value2 = 0;
    AtomicAction a = new AtomicAction();
    a.begin();
    indent(thr, level);
    System.out.println("begin   get12");
    try {
        value1 = atomicObject1.get();
    } catch (TestException e) {
        res = res1 = false;
    }
    indent(thr, level);
    System.out.println("part1   get12  : " + res1);
    lowProbYield();
    if (res) {
        try {
            value2 = atomicObject2.get();
        } catch (TestException e) {
            res = res2 = false;
        }
        indent(thr, level);
        System.out.println("part2   get12  : " + res2);
    } else
        res2 = false;
    lowProbYield();
    indent(thr, level);
    if (res) {
        System.out.print("commit ");
        res = (boolean) (a.commit() == ActionStatus.COMMITTED);
    } else {
        System.out.print("abort  ");
        a.abort();
    }
    System.out.println(" get12  : " + res1 + " : " + res2 + " : " + res + " : " + value1 + " : " + value2);
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException)

Example 87 with AtomicAction

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

the class AtomicObjectTest4 method incr12.

private static void incr12(int thr, int level) {
    boolean res = true;
    boolean res1 = true;
    boolean res2 = true;
    int ran;
    AtomicAction a = new AtomicAction();
    a.begin();
    indent(thr, level);
    System.out.println("begin   incr12");
    ran = Math.abs(rand.nextInt()) % 16;
    try {
        atomicObject1.incr(ran);
    } catch (TestException e) {
        res = res1 = false;
    }
    indent(thr, level);
    System.out.println("part1   incr12 : " + res1 + " " + res);
    lowProbYield();
    if (res) {
        try {
            atomicObject2.incr(-ran);
        } catch (TestException e) {
            res = res2 = false;
        }
        indent(thr, level);
        System.out.println("part2   incr12 : " + res2);
    } else
        res2 = false;
    lowProbYield();
    indent(thr, level);
    if (res) {
        System.out.flush();
        System.out.print("commit ");
        System.out.flush();
        res = (boolean) (a.commit() == ActionStatus.COMMITTED);
    } else {
        System.out.flush();
        System.out.print("abort  ");
        System.out.flush();
        a.abort();
    }
    System.out.println(" incr12 : " + res1 + " : " + res2 + " : " + res + " : " + ran);
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException)

Example 88 with AtomicAction

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

the class AtomicObjectTest4 method get12.

private static void get12(int thr, int level) {
    boolean res = true;
    boolean res1 = true;
    boolean res2 = true;
    int value1 = 0;
    int value2 = 0;
    AtomicAction a = new AtomicAction();
    a.begin();
    indent(thr, level);
    System.out.println("begin   get12");
    try {
        value1 = atomicObject1.get();
    } catch (TestException e) {
        res = res1 = false;
    }
    indent(thr, level);
    System.out.println("part1   get12  : " + res1);
    lowProbYield();
    if (res) {
        try {
            value2 = atomicObject2.get();
        } catch (TestException e) {
            res = res2 = false;
        }
        indent(thr, level);
        System.out.println("part2   get12  : " + res2);
    } else
        res2 = false;
    lowProbYield();
    indent(thr, level);
    if (res) {
        System.out.print("commit ");
        res = (boolean) (a.commit() == ActionStatus.COMMITTED);
    } else {
        System.out.print("abort  ");
        a.abort();
    }
    System.out.println(" get12  : " + res1 + " : " + res2 + " : " + res + " : " + value1 + " : " + value2);
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException)

Example 89 with AtomicAction

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

the class AtomicActionTestBase method executeTest.

protected AtomicAction executeTest(boolean isCommit, int expectedResult, SyncRecord[] syncs, AbstractRecord... records) {
    AtomicAction A = new AtomicAction();
    A.begin();
    for (AbstractRecord record : records) {
        A.add(record);
    }
    if (syncs != null) {
        for (SyncRecord sync : syncs) Assert.assertEquals(AddOutcome.AR_ADDED, A.addSynchronization(sync));
        Assert.assertEquals(syncs.length, A.getSynchronizations().size());
    }
    if (isCommit) {
        Assert.assertEquals(expectedResult, A.commit());
    } else {
        Assert.assertEquals(expectedResult, A.abort());
    }
    return A;
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) AbstractRecord(com.arjuna.ats.arjuna.coordinator.AbstractRecord)

Example 90 with AtomicAction

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

the class BadAction method test.

@Test
public void test() {
    AtomicAction A = new AtomicAction();
    AtomicAction B = new AtomicAction();
    A.begin();
    B.begin();
    A.commit();
    B.commit();
    BasicAction current = BasicAction.Current();
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) 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