Search in sources :

Example 6 with RecoverableContainer

use of org.jboss.stm.internal.RecoverableContainer in project narayana by jbosstm.

the class ArrayIntegerUnitTest method testArrayType.

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

Example 7 with RecoverableContainer

use of org.jboss.stm.internal.RecoverableContainer in project narayana by jbosstm.

the class ContainerUnitTest method testOptimisticHammer.

public void testOptimisticHammer() {
    if (true)
        return;
    Container<Sample1> theContainer = new Container<Sample1>();
    Sample1 obj1 = theContainer.create(new Sample1Imple(10));
    Sample1 obj2 = theContainer.create(new Sample1Imple(10));
    Sample1 obj3 = theContainer.clone(new Sample1Imple(), obj1);
    Sample1 obj4 = theContainer.clone(new Sample1Imple(), obj2);
    int workers = 2;
    Worker[] worker = new Worker[workers];
    assertTrue(obj3 != null);
    assertTrue(obj4 != null);
    /*
         * TODO cannot share state until the state is written, and it isn't written
         * until an explicit set is called. What we want is for the state to be in the
         * store when create (clone) returns.
         * 
         * So currently you need to force the saving of the object states (we use increment
         * here for that purpose) and then force a read of the state through the clones
         * (we use value for that purpose). Not as opaque as we'd like and we should be able
         * to force the save and restore via the proxy classes.
         */
    AtomicAction A = new AtomicAction();
    A.begin();
    obj1.increment();
    obj2.increment();
    A.commit();
    assertEquals(obj1.value(), 11);
    assertEquals(obj2.value(), 11);
    A = new AtomicAction();
    A.begin();
    assertEquals(obj3.value(), 11);
    A.commit();
    worker[0] = new Worker(obj1, obj2);
    worker[1] = new Worker(obj3, obj4);
    for (int j = 0; j < workers; j++) worker[j].start();
    try {
        for (int k = 0; k < workers; k++) worker[k].join();
    } catch (final Throwable ex) {
    }
    assertEquals(obj1.value() + obj2.value(), 22);
    @SuppressWarnings("unchecked") RecoverableContainer<Sample1> cont = ((OptimisticLockManagerProxy<Sample1>) obj1).getContainer();
    assertTrue(cont != null);
    @SuppressWarnings("unchecked") Container<Sample1> duplicateContainer = (Container<Sample1>) Container.getContainer(obj1);
    assertTrue(duplicateContainer != null);
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) RecoverableContainer(org.jboss.stm.internal.RecoverableContainer) OptimisticLockManagerProxy(org.jboss.stm.internal.proxy.OptimisticLockManagerProxy)

Aggregations

RecoverableContainer (org.jboss.stm.internal.RecoverableContainer)7 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)6 OptimisticLockManagerProxy (org.jboss.stm.internal.proxy.OptimisticLockManagerProxy)2 PersistentContainer (org.jboss.stm.internal.PersistentContainer)1 LockManagerProxy (org.jboss.stm.internal.proxy.LockManagerProxy)1