Search in sources :

Example 1 with TestException

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

the class AtomicObject method set.

public void set(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 2 with TestException

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

the class AtomicObject method get.

public int get() throws TestException {
    AtomicAction A = new AtomicAction();
    int value = -1;
    A.begin();
    if (setlock(new Lock(LockMode.READ), retry) == LockResult.GRANTED) {
        value = state;
        if (A.commit() == ActionStatus.COMMITTED)
            return value;
        else
            throw new TestException("Action commit error.");
    } else {
        if (printDebug)
            System.out.println("Error - could not set read lock.");
    }
    A.abort();
    throw new TestException("Read 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 3 with TestException

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

the class AtomicObjectLog method incr.

public void incr(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 4 with TestException

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

the class AtomicObjectLog method get.

public int get() throws TestException {
    AtomicAction A = new AtomicAction();
    int value = -1;
    A.begin();
    if (setlock(new Lock(LockMode.READ), 0) == LockResult.GRANTED) {
        value = state;
        if (A.commit() == ActionStatus.COMMITTED)
            return value;
        else
            throw new TestException("Action commit error.");
    } else {
        if (printDebug)
            System.out.println("Error - could not set read lock.");
    }
    A.abort();
    throw new TestException("Read 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 5 with TestException

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

the class PerformanceTest2 method persistentTest.

@Test
public void persistentTest() {
    long iters = 1000;
    AtomicObject foo = new AtomicObject();
    AtomicAction A = null;
    long t1 = System.currentTimeMillis();
    try {
        for (int c = 0; c < iters; c++) {
            A = new AtomicAction();
            A.begin();
            foo.set(2);
            A.commit();
        }
    } catch (TestException e) {
        if (A != null)
            A.abort();
        fail("AtomicObject exception raised.");
    }
    reportThroughput("persistentTest", iters, t1);
}
Also used : 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)

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