Search in sources :

Example 11 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) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException) Lock(com.arjuna.ats.txoj.Lock)

Example 12 with AtomicAction

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

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

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

the class LockStoreUnitTest method main.

/*
     * This is not meant to be driven by the normal unit test process.
     * 
     * To run, fire up two shells and run the first one with this test and with no parameters. Take the Uid
     * that is printed out and use it in the second shell with the same test and the -uid option.
     * 
     * Optionally provide a value through the -val parameter on one or both of the shells.
     * 
     * If you are fast enough then you should see something like ...
     * 
     * Error recreating object 0:ffffc0a8001f:ec14:51571c30:0
     *   com.hp.mwtests.ts.txoj.common.exceptions.TestException: Write lock error.
     *   at com.hp.mwtests.ts.txoj.common.resources.AtomicObject.set(AtomicObject.java:182)
     *   at com.hp.mwtests.ts.txoj.concurrencycontrol.LockStoreUnitTest.main(LockStoreUnitTest.java:141)
     *   
     * This shows concurrency control being applied across two different instances of the same object running
     * in different address spaces.
     */
public static void main(String[] args) {
    Uid u = null;
    AtomicObjectLockStore obj = null;
    int value = 10;
    txojPropertyManager.getTxojEnvironmentBean().setLockStoreType(BasicPersistentLockStore.class.getName());
    for (int i = 0; i < args.length; i++) {
        if (args[i].equals("-help")) {
            System.out.println("LockStoreUnitTest [-help] [-uid <uid>] [-val <integer>]");
            return;
        }
        if (args[i].equals("-uid")) {
            try {
                u = new Uid(args[i + 1]);
            } catch (final Exception ex) {
                ex.printStackTrace();
                return;
            }
        }
        if (args[i].equals("-val")) {
            try {
                value = Integer.parseInt(args[i + 1]);
            } catch (final Exception ex) {
                ex.printStackTrace();
                return;
            }
        }
    }
    if (u == null) {
        obj = new AtomicObjectLockStore(ObjectModel.MULTIPLE);
        System.out.println("Object created: " + obj.get_uid());
        try {
            Thread.sleep(10000);
        } catch (final Exception ex) {
        }
    } else
        obj = new AtomicObjectLockStore(u, ObjectModel.MULTIPLE);
    try {
        AtomicAction A = new AtomicAction();
        A.begin();
        obj.set(value);
        try {
            Thread.sleep(10000);
        } catch (final Exception ex) {
        }
        A.commit();
        System.out.println("Value: " + obj.get());
    } catch (final Exception e) {
        e.printStackTrace();
    }
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) AtomicObjectLockStore(com.hp.mwtests.ts.txoj.common.resources.AtomicObjectLockStore) BasicPersistentLockStore(com.arjuna.ats.internal.txoj.lockstore.BasicPersistentLockStore)

Example 15 with AtomicAction

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

the class ObjectModelTest method testMULTIPLE.

@Test
public void testMULTIPLE() throws IOException, TestException {
    AtomicObject obj1 = new AtomicObject(ObjectModel.MULTIPLE);
    AtomicObject obj2 = new AtomicObject(obj1.get_uid(), ObjectModel.MULTIPLE);
    AtomicAction A = new AtomicAction();
    A.begin();
    obj1.set(1234);
    A.commit();
    assertEquals(1234, obj2.get());
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) AtomicObject(com.hp.mwtests.ts.txoj.common.resources.AtomicObject) Test(org.junit.Test)

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