Search in sources :

Example 1 with AtomicObjectLockStore

use of com.hp.mwtests.ts.txoj.common.resources.AtomicObjectLockStore 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 2 with AtomicObjectLockStore

use of com.hp.mwtests.ts.txoj.common.resources.AtomicObjectLockStore in project narayana by jbosstm.

the class LockStoreUnitTest method testBasic.

@Test
public void testBasic() throws Throwable {
    txojPropertyManager.getTxojEnvironmentBean().setLockStoreType(BasicPersistentLockStore.class.getName());
    AtomicObjectLockStore obj = new AtomicObjectLockStore(ObjectModel.MULTIPLE);
    obj.set(0);
    obj.incr(1);
    assertEquals(obj.get(), 1);
    assertTrue(obj.getLockStore().getClass().getName().equals(BasicPersistentLockStore.class.getName()));
}
Also used : AtomicObjectLockStore(com.hp.mwtests.ts.txoj.common.resources.AtomicObjectLockStore) BasicPersistentLockStore(com.arjuna.ats.internal.txoj.lockstore.BasicPersistentLockStore) Test(org.junit.Test)

Aggregations

BasicPersistentLockStore (com.arjuna.ats.internal.txoj.lockstore.BasicPersistentLockStore)2 AtomicObjectLockStore (com.hp.mwtests.ts.txoj.common.resources.AtomicObjectLockStore)2 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)1 Uid (com.arjuna.ats.arjuna.common.Uid)1 Test (org.junit.Test)1