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);
}
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);
}
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();
}
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());
}
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);
}
Aggregations