Search in sources :

Example 26 with TestException

use of com.hp.mwtests.ts.txoj.common.exceptions.TestException in project narayana by jbosstm.

the class AtomicObjectTest2 method get21.

private static void get21(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   get21");
    try {
        value1 = atomicObject2.get();
    } catch (TestException e) {
        res = res1 = false;
    }
    indent(thr, level);
    System.out.println("part1   get21  : " + res1);
    lowProbYield();
    if (res) {
        try {
            value2 = atomicObject1.get();
        } catch (TestException e) {
            res = res2 = false;
        }
        indent(thr, level);
        System.out.println("part2   get21  : " + 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(" get21  : " + res1 + " : " + res2 + " : " + res + " : " + value1 + " : " + value2);
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException)

Example 27 with TestException

use of com.hp.mwtests.ts.txoj.common.exceptions.TestException in project narayana by jbosstm.

the class AtomicObjectTest2 method incr21.

private static void incr21(char 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   incr21");
    ran = Math.abs(rand.nextInt()) % 16;
    try {
        atomicObject2.incr(ran);
    } catch (TestException e) {
        res = res1 = false;
    }
    indent(thr, level);
    System.out.println("part1   incr21 : " + res1);
    lowProbYield();
    if (res) {
        try {
            atomicObject1.incr(-ran);
        } catch (TestException e) {
            res = res2 = false;
        }
        indent(thr, level);
        System.out.println("part2   incr21 : " + 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(" incr21 : " + res1 + " : " + res2 + " : " + res + " : " + ran);
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException)

Example 28 with TestException

use of com.hp.mwtests.ts.txoj.common.exceptions.TestException in project narayana by jbosstm.

the class AtomicObjectTest4 method get21.

private static void get21(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   get21");
    try {
        value1 = atomicObject2.get();
    } catch (TestException e) {
        res = res1 = false;
    }
    indent(thr, level);
    System.out.println("part1   get21  : " + res1);
    lowProbYield();
    if (res) {
        try {
            value2 = atomicObject1.get();
        } catch (TestException e) {
            res = res2 = false;
        }
        indent(thr, level);
        System.out.println("part2   get21  : " + 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(" get21  : " + res1 + " : " + res2 + " : " + res + " : " + value1 + " : " + value2);
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException)

Example 29 with TestException

use of com.hp.mwtests.ts.txoj.common.exceptions.TestException in project narayana by jbosstm.

the class AtomicObjectTest4 method incr21.

private static void incr21(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   incr21");
    ran = Math.abs(rand.nextInt()) % 16;
    try {
        atomicObject2.incr(ran);
    } catch (TestException e) {
        res = res1 = false;
    }
    indent(thr, level);
    System.out.println("part1   incr21 : " + res1);
    lowProbYield();
    if (res) {
        try {
            atomicObject1.incr(-ran);
        } catch (TestException e) {
            res = res2 = false;
        }
        indent(thr, level);
        System.out.println("part2   incr21 : " + 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(" incr21 : " + res1 + " : " + res2 + " : " + res + " : " + ran);
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException)

Example 30 with TestException

use of com.hp.mwtests.ts.txoj.common.exceptions.TestException in project narayana by jbosstm.

the class NestedTopLevelAction method test.

@Test
public void test() {
    AtomicAction A = new AtomicAction();
    TopLevelAction B = new TopLevelAction();
    AtomicAction C = new AtomicAction();
    AtomicObject foo1 = new AtomicObject();
    AtomicObject foo2 = new AtomicObject();
    try {
        A.begin();
        foo1.set(5);
        System.out.println("Current atomic object 1 state: " + foo1.get());
        System.out.println("\nStarting nested top-level action.");
        B.begin();
        System.out.println(B);
        foo2.set(7);
        System.out.println("Current atomic object 2 state: " + foo2.get());
        System.out.println("\nCommitting nested top-level action.");
        B.commit();
        System.out.println("\nAborting top-level action.");
        A.abort();
        C.begin();
        int val1 = foo1.get();
        int val2 = foo2.get();
        System.out.println("\nFinal atomic object 1 state: " + val1);
        assertEquals(0, val1);
        System.out.println("\nFinal atomic object 2 state: " + val2);
        assertEquals(7, val2);
        C.commit();
    } catch (TestException e) {
        A.abort();
        B.abort();
        C.abort();
        fail("AtomicObject exception raised.");
    }
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) TopLevelAction(com.arjuna.ats.arjuna.TopLevelAction) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException) AtomicObject(com.hp.mwtests.ts.txoj.common.resources.AtomicObject) Test(org.junit.Test)

Aggregations

TestException (com.hp.mwtests.ts.txoj.common.exceptions.TestException)32 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)30 AtomicObject (com.hp.mwtests.ts.txoj.common.resources.AtomicObject)8 Test (org.junit.Test)8 Lock (com.arjuna.ats.txoj.Lock)6 Uid (com.arjuna.ats.arjuna.common.Uid)3 Random (java.util.Random)2 TopLevelAction (com.arjuna.ats.arjuna.TopLevelAction)1 BasicAction (com.arjuna.ats.arjuna.coordinator.BasicAction)1