Search in sources :

Example 21 with AtomicObject

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

the class CadaverUnitTest method testBasic.

@Test
public void testBasic() throws Exception {
    AtomicAction A = new AtomicAction();
    AtomicObject B = new AtomicObject();
    A.begin();
    CadaverLockRecord clr = new CadaverLockRecord(null, B, A);
    LockRecord lr = new LockRecord(B, A);
    assertTrue(clr.type() != null);
    clr.print(new PrintWriter(new ByteArrayOutputStream()));
    clr.replace(lr);
    A.abort();
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) CadaverLockRecord(com.arjuna.ats.internal.txoj.abstractrecords.CadaverLockRecord) CadaverLockRecord(com.arjuna.ats.internal.txoj.abstractrecords.CadaverLockRecord) LockRecord(com.arjuna.ats.internal.txoj.abstractrecords.LockRecord) AtomicObject(com.hp.mwtests.ts.txoj.common.resources.AtomicObject) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 22 with AtomicObject

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

the class CadaverUnitTest method testMultipleNestedAbort.

@Test
public void testMultipleNestedAbort() 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.abort();
    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)

Example 23 with AtomicObject

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

the class CadaverUnitTest method testMultipleNestedCommit.

@Test
public void testMultipleNestedCommit() 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)

Example 24 with AtomicObject

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

the class NestedTopLevelAction method test.

@Test
public void test() {
    AtomicAction A = new AtomicAction();
    TopLevelAction B = new TopLevelAction();
    AtomicAction C = new AtomicAction();
    AtomicObject foo1 = new AtomicObject();
    AtomicObject foo2 = new AtomicObject();
    try {
        A.begin();
        foo1.set(5);
        System.out.println("Current atomic object 1 state: " + foo1.get());
        System.out.println("\nStarting nested top-level action.");
        B.begin();
        System.out.println(B);
        foo2.set(7);
        System.out.println("Current atomic object 2 state: " + foo2.get());
        System.out.println("\nCommitting nested top-level action.");
        B.commit();
        System.out.println("\nAborting top-level action.");
        A.abort();
        C.begin();
        int val1 = foo1.get();
        int val2 = foo2.get();
        System.out.println("\nFinal atomic object 1 state: " + val1);
        assertEquals(0, val1);
        System.out.println("\nFinal atomic object 2 state: " + val2);
        assertEquals(7, val2);
        C.commit();
    } catch (TestException e) {
        A.abort();
        B.abort();
        C.abort();
        fail("AtomicObject exception raised.");
    }
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) TopLevelAction(com.arjuna.ats.arjuna.TopLevelAction) TestException(com.hp.mwtests.ts.txoj.common.exceptions.TestException) AtomicObject(com.hp.mwtests.ts.txoj.common.resources.AtomicObject) Test(org.junit.Test)

Example 25 with AtomicObject

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

the class PerformanceTest1 method persistentTest.

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

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