Search in sources :

Example 6 with AtomicAction

use of com.arjuna.ats.arjuna.AtomicAction 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) Lock(com.arjuna.ats.txoj.Lock)

Example 7 with AtomicAction

use of com.arjuna.ats.arjuna.AtomicAction 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) Lock(com.arjuna.ats.txoj.Lock)

Example 8 with AtomicAction

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

the class SampleVerticle2 method start.

public void start() {
    LocalMap<String, String> map = vertx.sharedData().getLocalMap("demo.mymap");
    Container<Sample> theContainer = new Container<>("Demo", Container.TYPE.PERSISTENT, Container.MODEL.SHARED);
    String uidName = map.get(ClientVerticle.LEADER);
    Sample obj1 = theContainer.clone(new SampleLockable(10), new Uid(uidName));
    AtomicAction A = new AtomicAction();
    int value = -1;
    int initialValue = -1;
    boolean shouldCommit = true;
    A.begin();
    try {
        initialValue = obj1.value();
        obj1.increment();
    } catch (final Throwable ex) {
        ex.printStackTrace();
        shouldCommit = false;
    }
    try {
        if (shouldCommit) {
            obj1.increment();
            value = obj1.value();
        }
    } catch (final Throwable ex) {
        ex.printStackTrace();
        shouldCommit = false;
    }
    if (shouldCommit)
        A.commit();
    else {
        A.abort();
        value = -1;
    }
    System.err.println("SampleVerticle2 initialised state with: " + value);
    if (value == initialValue + 2)
        System.err.println("SampleVerticle2 SUCCEEDED!");
    else
        System.err.println("SampleVerticle2 FAILED!");
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) Container(org.jboss.stm.Container)

Example 9 with AtomicAction

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

the class ReactivateUnitTest method test.

@Test
public void test() {
    try {
        AtomicObject obj = new AtomicObject();
        Uid objRef = obj.get_uid();
        AtomicAction A = new AtomicAction();
        A.begin();
        obj.set(1234);
        A.commit();
        AtomicObject recObj = new AtomicObject(objRef);
        AtomicAction B = new AtomicAction();
        B.begin();
        assertEquals(1234, recObj.get());
        B.abort();
    } catch (Exception ex) {
        fail(ex.toString());
    }
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) AtomicObject(com.hp.mwtests.ts.txoj.common.resources.AtomicObject) Test(org.junit.Test)

Example 10 with AtomicAction

use of com.arjuna.ats.arjuna.AtomicAction 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)

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