Search in sources :

Example 26 with AtomicAction

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

the class ComparisonUnitTest method testExampleSTM.

public void testExampleSTM() throws Exception {
    RecoverableContainer<Atomic> theContainer = new RecoverableContainer<Atomic>();
    ExampleSTM basic = new ExampleSTM();
    boolean success = true;
    Atomic obj = null;
    try {
        obj = theContainer.enlist(basic);
    } catch (final Throwable ex) {
        ex.printStackTrace();
        success = false;
    }
    assertTrue(success);
    AtomicAction a = new AtomicAction();
    a.begin();
    obj.set(1234);
    a.commit();
    assertEquals(obj.get(), 1234);
    a = new AtomicAction();
    a.begin();
    obj.incr(1);
    a.abort();
    assertEquals(obj.get(), 1234);
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) RecoverableContainer(org.jboss.stm.internal.RecoverableContainer)

Example 27 with AtomicAction

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

the class ComparisonUnitTest method testAtomicObject.

public void testAtomicObject() throws Exception {
    AtomicObject obj = new AtomicObject();
    AtomicAction a = new AtomicAction();
    a.begin();
    obj.set(1234);
    a.commit();
    assertEquals(obj.get(), 1234);
    a = new AtomicAction();
    a.begin();
    obj.incr(1);
    a.abort();
    assertEquals(obj.get(), 1234);
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction)

Example 28 with AtomicAction

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

the class ContainerRecreatePessimisticUnitTest method testPessimisticRecreate.

public void testPessimisticRecreate() {
    Container<Sample2> theContainer = new Container<Sample2>(Container.TYPE.PERSISTENT, Container.MODEL.SHARED);
    Sample2 obj1 = theContainer.create(new Sample2Imple(10));
    assertTrue(obj1 != null);
    /*
         * Do some basic checks and ensure state is in store prior to sharing.
         */
    AtomicAction A = new AtomicAction();
    A.begin();
    obj1.increment();
    obj1.decrement();
    A.commit();
    assertEquals(obj1.value(), 10);
    assertTrue(theContainer.getIdentifier(obj1).notEquals(Uid.nullUid()));
    Sample2 obj2 = theContainer.clone(new Sample2Imple(), theContainer.getIdentifier(obj1));
    assertTrue(obj2 != null);
    A = new AtomicAction();
    A.begin();
    obj2.increment();
    A.commit();
    assertEquals(obj2.value(), 11);
    A = new AtomicAction();
    A.begin();
    assertEquals(obj1.value(), obj2.value());
    A.commit();
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction)

Example 29 with AtomicAction

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

the class LinkedListUnitTest method testLinkedList.

public void testLinkedList() throws Exception {
    NodeImple ni1 = new NodeImple("one");
    NodeImple ni2 = new NodeImple("two");
    NodeImple ni3 = new NodeImple("three");
    AtomicAction A = new AtomicAction();
    Node h1 = theContainer.enlist(ni1);
    Node h2 = theContainer.enlist(ni2);
    Node h3 = theContainer.enlist(ni3);
    h1.setNext(h2);
    h2.setPrev(h1);
    assertEquals(h1.getPrev(), null);
    assertEquals(h2.getPrev().nodeName(), h1.nodeName());
    A.begin();
    h1.setNext(h3);
    h2.setPrev(null);
    h3.setPrev(h1);
    A.abort();
    assertEquals(h1.getNext().nodeName(), h2.nodeName());
    assertEquals(h1.getPrev(), null);
    assertEquals(h2.getPrev().nodeName(), h1.nodeName());
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction)

Example 30 with AtomicAction

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

the class NestedHammerUnitTest method testPersistentHammerMULTIPLE.

public void testPersistentHammerMULTIPLE() {
    PersistentContainer<Sample> theContainer = new PersistentContainer<Sample>(ObjectModel.MULTIPLE);
    Sample obj1 = theContainer.enlist(new SampleLockable(10));
    Sample obj2 = theContainer.enlist(new SampleLockable(10));
    Worker worker1 = new Worker(obj1, obj2);
    Worker worker2 = new Worker(obj1, obj2);
    AtomicAction A = new AtomicAction();
    /*
         * Make sure the state is saved to disk before proceeding. Important
         * for the MULTIPLE option.
         */
    A.begin();
    obj1.increment();
    obj1.decrement();
    obj2.increment();
    obj2.decrement();
    A.commit();
    worker1.start();
    worker2.start();
    try {
        worker1.join();
        worker2.join();
    } catch (final Throwable ex) {
    }
    assertEquals(obj1.value() + obj2.value(), 20);
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) PersistentContainer(org.jboss.stm.internal.PersistentContainer)

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