use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.
the class AtomicObject method get.
public int get() throws TestException {
AtomicAction A = new AtomicAction();
int value = -1;
A.begin();
if (setlock(new Lock(LockMode.READ), retry) == LockResult.GRANTED) {
value = state;
if (A.commit() == ActionStatus.COMMITTED)
return value;
else
throw new TestException("Action commit error.");
} else {
if (printDebug)
System.out.println("Error - could not set read lock.");
}
A.abort();
throw new TestException("Read lock error.");
}
use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.
the class AtomicObjectLog method incr.
public void incr(int value) throws TestException {
AtomicAction A = new AtomicAction();
A.begin();
if (setlock(new Lock(LockMode.WRITE), 0) == LockResult.GRANTED) {
state += value;
if (A.commit() != ActionStatus.COMMITTED)
throw new TestException("Action commit error.");
else
return;
} else {
if (printDebug)
System.out.println("Error - could not set write lock.");
}
A.abort();
throw new TestException("Write lock error.");
}
use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.
the class AtomicObjectLog method get.
public int get() throws TestException {
AtomicAction A = new AtomicAction();
int value = -1;
A.begin();
if (setlock(new Lock(LockMode.READ), 0) == LockResult.GRANTED) {
value = state;
if (A.commit() == ActionStatus.COMMITTED)
return value;
else
throw new TestException("Action commit error.");
} else {
if (printDebug)
System.out.println("Error - could not set read lock.");
}
A.abort();
throw new TestException("Read lock error.");
}
use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.
the class LockStoreUnitTest method main.
/*
* This is not meant to be driven by the normal unit test process.
*
* To run, fire up two shells and run the first one with this test and with no parameters. Take the Uid
* that is printed out and use it in the second shell with the same test and the -uid option.
*
* Optionally provide a value through the -val parameter on one or both of the shells.
*
* If you are fast enough then you should see something like ...
*
* Error recreating object 0:ffffc0a8001f:ec14:51571c30:0
* com.hp.mwtests.ts.txoj.common.exceptions.TestException: Write lock error.
* at com.hp.mwtests.ts.txoj.common.resources.AtomicObject.set(AtomicObject.java:182)
* at com.hp.mwtests.ts.txoj.concurrencycontrol.LockStoreUnitTest.main(LockStoreUnitTest.java:141)
*
* This shows concurrency control being applied across two different instances of the same object running
* in different address spaces.
*/
public static void main(String[] args) {
Uid u = null;
AtomicObjectLockStore obj = null;
int value = 10;
txojPropertyManager.getTxojEnvironmentBean().setLockStoreType(BasicPersistentLockStore.class.getName());
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-help")) {
System.out.println("LockStoreUnitTest [-help] [-uid <uid>] [-val <integer>]");
return;
}
if (args[i].equals("-uid")) {
try {
u = new Uid(args[i + 1]);
} catch (final Exception ex) {
ex.printStackTrace();
return;
}
}
if (args[i].equals("-val")) {
try {
value = Integer.parseInt(args[i + 1]);
} catch (final Exception ex) {
ex.printStackTrace();
return;
}
}
}
if (u == null) {
obj = new AtomicObjectLockStore(ObjectModel.MULTIPLE);
System.out.println("Object created: " + obj.get_uid());
try {
Thread.sleep(10000);
} catch (final Exception ex) {
}
} else
obj = new AtomicObjectLockStore(u, ObjectModel.MULTIPLE);
try {
AtomicAction A = new AtomicAction();
A.begin();
obj.set(value);
try {
Thread.sleep(10000);
} catch (final Exception ex) {
}
A.commit();
System.out.println("Value: " + obj.get());
} catch (final Exception e) {
e.printStackTrace();
}
}
use of com.arjuna.ats.arjuna.AtomicAction in project narayana by jbosstm.
the class ObjectModelTest method testMULTIPLE.
@Test
public void testMULTIPLE() throws IOException, TestException {
AtomicObject obj1 = new AtomicObject(ObjectModel.MULTIPLE);
AtomicObject obj2 = new AtomicObject(obj1.get_uid(), ObjectModel.MULTIPLE);
AtomicAction A = new AtomicAction();
A.begin();
obj1.set(1234);
A.commit();
assertEquals(1234, obj2.get());
}
Aggregations