Search in sources :

Example 16 with AtomicObject

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

the class LockRecordUnitTest method test.

@Test
public void test() {
    LockRecord lr = new LockRecord();
    assertEquals(lr.lockType(), null);
    assertTrue(lr.save_state(new OutputObjectState(), ObjectType.ANDPERSISTENT));
    assertFalse(lr.restore_state(new InputObjectState(), ObjectType.ANDPERSISTENT));
    assertEquals(lr.value(), null);
    lr.setValue(null);
    assertEquals(lr.nestedAbort(), TwoPhaseOutcome.FINISH_ERROR);
    assertEquals(lr.nestedCommit(), TwoPhaseOutcome.FINISH_ERROR);
    assertEquals(lr.topLevelAbort(), TwoPhaseOutcome.FINISH_ERROR);
    assertEquals(lr.topLevelCommit(), TwoPhaseOutcome.FINISH_ERROR);
    lr = new LockRecord(new AtomicObject(), new AtomicAction());
    assertTrue(lr.toString() != null);
    lr.print(new PrintWriter(new ByteArrayOutputStream()));
    assertTrue(lr.type() != null);
    lr.merge(null);
    lr.alter(null);
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) LockRecord(com.arjuna.ats.internal.txoj.abstractrecords.LockRecord) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) AtomicObject(com.hp.mwtests.ts.txoj.common.resources.AtomicObject) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 17 with AtomicObject

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

the class AtomicObjectTest1 method test.

@Test
public void test() throws TestException {
    txojPropertyManager.getTxojEnvironmentBean().setLockStoreType(BasicPersistentLockStore.class.getName());
    rand = new Random();
    atomicObject1 = new AtomicObject(ObjectModel.MULTIPLE);
    atomicObject2 = new AtomicObject(ObjectModel.MULTIPLE);
    System.out.println(atomicObject1.get_uid());
    System.out.println(atomicObject2.get_uid());
    atomicObject1.set(START_VALUE_1);
    atomicObject2.set(START_VALUE_2);
    get12('m', 0);
    get21('m', 0);
    for (int i = 0; i < 100; i++) randomOperation('1', 0);
    get12('m', 0);
    get21('m', 0);
    assertEquals(EXPECTED_RESULT, (getValue1() + getValue2()));
}
Also used : Random(java.util.Random) BasicPersistentLockStore(com.arjuna.ats.internal.txoj.lockstore.BasicPersistentLockStore) AtomicObject(com.hp.mwtests.ts.txoj.common.resources.AtomicObject) Test(org.junit.Test)

Example 18 with AtomicObject

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

the class AtomicObjectTest3 method test.

@Test
public void test() throws TestException {
    rand = new Random();
    atomicObject1 = new AtomicObject();
    atomicObject2 = new AtomicObject();
    System.out.println(atomicObject1.get_uid());
    System.out.println(atomicObject2.get_uid());
    try {
        atomicObject1.set(START_VALUE_1);
    } catch (TestException e) {
        System.out.println("0 set1 : failed");
    }
    try {
        atomicObject2.set(START_VALUE_2);
    } catch (TestException e) {
        System.out.println("0 set2 : failed");
    }
    ThreadObject2 thr1 = new ThreadObject2(1);
    ThreadObject2 thr2 = new ThreadObject2(2);
    thr1.start();
    thr2.start();
    try {
        thr1.join();
        thr2.join();
    } catch (InterruptedException e) {
    }
    get12(0, 0);
    get21(0, 0);
    assertEquals(EXPECTED_RESULT, (getValue1() + getValue2()));
}
Also used : Random(java.util.Random) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException) AtomicObject(com.hp.mwtests.ts.txoj.common.resources.AtomicObject) Test(org.junit.Test)

Example 19 with AtomicObject

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

the class BasicActionTest method run.

@Test
public void run() throws TestException {
    AtomicObject foo = null;
    Uid u = null;
    if (u == null)
        foo = new AtomicObject();
    else
        foo = new AtomicObject(u);
    AtomicAction A = new AtomicAction();
    int value = foo.get();
    try {
        A.begin();
        foo.set(foo.get() + 2);
        A.commit();
        assertEquals(value + 2, foo.get());
    } catch (Exception e) {
        A.abort();
        fail("AtomicObject exception raised.");
    }
    System.out.println("\nWill now try some erroneous conditions.\n");
    AtomicAction B = new AtomicAction();
    u = new Uid();
    foo = new AtomicObject(u);
    B.begin();
    try {
        System.out.println("attempting to get value from non-existent object: " + foo.get());
    } catch (Exception e) {
    }
    System.out.println("trying to set value to 5");
    try {
        foo.set(5);
    } catch (Exception e) {
    }
    try {
        System.out.println("attempting to get value again: " + foo.get());
    } catch (Exception e) {
    }
    B.commit();
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) AtomicObject(com.hp.mwtests.ts.txoj.common.resources.AtomicObject) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException) Test(org.junit.Test)

Example 20 with AtomicObject

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

the class CadaverUnitTest method testCommit.

@Test
public void testCommit() throws Exception {
    AtomicAction A = new AtomicAction();
    AtomicObject B = new AtomicObject(ObjectModel.MULTIPLE);
    Uid u = B.get_uid();
    A.begin();
    B.set(1234);
    A.commit();
    A = new AtomicAction();
    B = new AtomicObject(u, ObjectModel.MULTIPLE);
    A.begin();
    AtomicAction C = new AtomicAction();
    C.begin();
    assertEquals(B.get(), 1234);
    B.set(5678);
    B.terminate();
    C.commit();
    assertEquals(A.commit(), ActionStatus.COMMITTED);
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) Uid(com.arjuna.ats.arjuna.common.Uid) AtomicObject(com.hp.mwtests.ts.txoj.common.resources.AtomicObject) Test(org.junit.Test)

Aggregations

AtomicObject (com.hp.mwtests.ts.txoj.common.resources.AtomicObject)27 Test (org.junit.Test)26 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)18 Uid (com.arjuna.ats.arjuna.common.Uid)13 TestException (com.hp.mwtests.ts.txoj.common.exceptions.TestException)8 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)4 Random (java.util.Random)4 HammerThreadedObject (com.hp.mwtests.ts.txoj.common.resources.HammerThreadedObject)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 PrintWriter (java.io.PrintWriter)3 LockRecord (com.arjuna.ats.internal.txoj.abstractrecords.LockRecord)2 TopLevelAction (com.arjuna.ats.arjuna.TopLevelAction)1 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)1 CadaverLockRecord (com.arjuna.ats.internal.txoj.abstractrecords.CadaverLockRecord)1 BasicPersistentLockStore (com.arjuna.ats.internal.txoj.lockstore.BasicPersistentLockStore)1