Search in sources :

Example 21 with TestException

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

the class AtomicObjectTest1 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);
    if (res) {
        try {
            value2 = atomicObject2.get();
        } catch (TestException e) {
            res = res2 = false;
        }
        indent(thr, level);
        System.out.println("part2   get12  : " + res2);
    } else
        res2 = false;
    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 22 with TestException

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

the class AtomicObjectTest3 method test.

@Test
public void test() throws TestException {
    rand = new Random();
    atomicObject1 = new AtomicObject();
    atomicObject2 = new AtomicObject();
    System.out.println(atomicObject1.get_uid());
    System.out.println(atomicObject2.get_uid());
    try {
        atomicObject1.set(START_VALUE_1);
    } catch (TestException e) {
        System.out.println("0 set1 : failed");
    }
    try {
        atomicObject2.set(START_VALUE_2);
    } catch (TestException e) {
        System.out.println("0 set2 : failed");
    }
    ThreadObject2 thr1 = new ThreadObject2(1);
    ThreadObject2 thr2 = new ThreadObject2(2);
    thr1.start();
    thr2.start();
    try {
        thr1.join();
        thr2.join();
    } catch (InterruptedException e) {
    }
    get12(0, 0);
    get21(0, 0);
    assertEquals(EXPECTED_RESULT, (getValue1() + getValue2()));
}
Also used : Random(java.util.Random) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException) AtomicObject(com.hp.mwtests.ts.txoj.common.resources.AtomicObject) Test(org.junit.Test)

Example 23 with TestException

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

the class AtomicObjectTest3 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 24 with TestException

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

the class BasicActionTest method run.

@Test
public void run() throws TestException {
    AtomicObject foo = null;
    Uid u = null;
    if (u == null)
        foo = new AtomicObject();
    else
        foo = new AtomicObject(u);
    AtomicAction A = new AtomicAction();
    int value = foo.get();
    try {
        A.begin();
        foo.set(foo.get() + 2);
        A.commit();
        assertEquals(value + 2, foo.get());
    } catch (Exception e) {
        A.abort();
        fail("AtomicObject exception raised.");
    }
    System.out.println("\nWill now try some erroneous conditions.\n");
    AtomicAction B = new AtomicAction();
    u = new Uid();
    foo = new AtomicObject(u);
    B.begin();
    try {
        System.out.println("attempting to get value from non-existent object: " + foo.get());
    } catch (Exception e) {
    }
    System.out.println("trying to set value to 5");
    try {
        foo.set(5);
    } catch (Exception e) {
    }
    try {
        System.out.println("attempting to get value again: " + foo.get());
    } catch (Exception e) {
    }
    B.commit();
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) AtomicObject(com.hp.mwtests.ts.txoj.common.resources.AtomicObject) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException) Test(org.junit.Test)

Example 25 with TestException

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

the class AtomicObjectTest2 method incr12.

private static void incr12(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   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);
    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.print("commit ");
        res = (boolean) (a.commit() == ActionStatus.COMMITTED);
    } else {
        System.out.print("abort  ");
        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)

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