Search in sources :

Example 16 with TestException

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

the class AtomicObject method incr.

public void incr(int value) throws TestException {
    AtomicAction A = new AtomicAction();
    A.begin();
    if (setlock(new Lock(LockMode.WRITE), retry) == LockResult.GRANTED) {
        state += value;
        if (A.commit() != ActionStatus.COMMITTED)
            throw new TestException("Action commit error.");
        else
            return;
    } else {
        if (printDebug)
            System.out.println("Error - could not set write lock.");
    }
    A.abort();
    throw new TestException("Write lock error.");
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException) Lock(com.arjuna.ats.txoj.Lock)

Example 17 with TestException

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

the class AtomicObjectLog method set.

public void set(int value) throws TestException {
    AtomicAction A = new AtomicAction();
    A.begin();
    if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
        state = value;
        if (A.commit() != ActionStatus.COMMITTED)
            throw new TestException("Action commit error.");
        else
            return;
    } else {
        if (printDebug)
            System.out.println("Error - could not set write lock.");
    }
    A.abort();
    throw new TestException("Write lock error.");
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException) Lock(com.arjuna.ats.txoj.Lock)

Example 18 with TestException

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

the class HammerThreadedObject method run.

public void run() {
    for (int i = 0; i < HammerThreadedObject.iter; i++) {
        AtomicAction A = new AtomicAction();
        float f = HammerThreadedObject.rand.nextFloat();
        try {
            Thread.yield();
            A.begin();
            int v = HammerThreadedObject.object.get();
            if (f > 0.25)
                System.out.println(_uid + ": atomic object value: " + v);
            else {
                int nv = v + _value;
                HammerThreadedObject.object.set(nv);
                System.out.println(_uid + ": atomic object value set to : " + nv);
            }
            A.commit();
            try {
                Thread.sleep((int) HammerThreadedObject.rand.nextFloat() * 1000);
            } catch (InterruptedException e) {
            }
        } catch (TestException e) {
            System.out.println(_uid + ": AtomicObject exception raised: " + e);
            A.abort();
            Thread.yield();
        }
    }
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException)

Example 19 with TestException

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

the class DestroyTest method test.

@Test
public void test() throws TestException {
    AtomicObject atomicObject = new AtomicObject();
    Uid u = atomicObject.get_uid();
    AtomicAction a = new AtomicAction();
    a.begin();
    atomicObject.set(10);
    assertTrue(atomicObject.destroy());
    a.commit();
    atomicObject = new AtomicObject(u);
    int val;
    try {
        val = atomicObject.get();
    } catch (final TestException ex) {
        // activate should fail so setlock should fail
        // differentiate between -1
        val = -2;
    }
    assertEquals(-2, val);
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException) AtomicObject(com.hp.mwtests.ts.txoj.common.resources.AtomicObject) Test(org.junit.Test)

Example 20 with TestException

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

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