use of com.hp.mwtests.ts.txoj.common.exceptions.TestException in project narayana by jbosstm.
the class AtomicObject method incr.
public void incr(int value) throws TestException {
AtomicAction A = new AtomicAction();
A.begin();
if (setlock(new Lock(LockMode.WRITE), retry) == 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.hp.mwtests.ts.txoj.common.exceptions.TestException in project narayana by jbosstm.
the class AtomicObjectLog method set.
public void set(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.hp.mwtests.ts.txoj.common.exceptions.TestException in project narayana by jbosstm.
the class HammerThreadedObject method run.
public void run() {
for (int i = 0; i < HammerThreadedObject.iter; i++) {
AtomicAction A = new AtomicAction();
float f = HammerThreadedObject.rand.nextFloat();
try {
Thread.yield();
A.begin();
int v = HammerThreadedObject.object.get();
if (f > 0.25)
System.out.println(_uid + ": atomic object value: " + v);
else {
int nv = v + _value;
HammerThreadedObject.object.set(nv);
System.out.println(_uid + ": atomic object value set to : " + nv);
}
A.commit();
try {
Thread.sleep((int) HammerThreadedObject.rand.nextFloat() * 1000);
} catch (InterruptedException e) {
}
} catch (TestException e) {
System.out.println(_uid + ": AtomicObject exception raised: " + e);
A.abort();
Thread.yield();
}
}
}
use of com.hp.mwtests.ts.txoj.common.exceptions.TestException in project narayana by jbosstm.
the class DestroyTest method test.
@Test
public void test() throws TestException {
AtomicObject atomicObject = new AtomicObject();
Uid u = atomicObject.get_uid();
AtomicAction a = new AtomicAction();
a.begin();
atomicObject.set(10);
assertTrue(atomicObject.destroy());
a.commit();
atomicObject = new AtomicObject(u);
int val;
try {
val = atomicObject.get();
} catch (final TestException ex) {
// activate should fail so setlock should fail
// differentiate between -1
val = -2;
}
assertEquals(-2, val);
}
use of com.hp.mwtests.ts.txoj.common.exceptions.TestException in project narayana by jbosstm.
the class AtomicObjectTest1 method get21.
private static void get21(char thr, int level) {
boolean res = true;
boolean res1 = true;
boolean res2 = true;
int value1 = 0;
int value2 = 0;
AtomicAction a = new AtomicAction();
a.begin();
indent(thr, level);
System.out.println("begin get21");
try {
value1 = atomicObject2.get();
} catch (TestException e) {
res = res1 = false;
}
indent(thr, level);
System.out.println("part1 get21 : " + res1);
if (res) {
try {
value2 = atomicObject1.get();
} catch (TestException e) {
res = res2 = false;
}
indent(thr, level);
System.out.println("part2 get21 : " + res2);
} else
res2 = false;
indent(thr, level);
if (res) {
System.out.print("commit ");
res = (boolean) (a.commit() == ActionStatus.COMMITTED);
} else {
System.out.print("abort ");
a.abort();
}
System.out.println(" get21 : " + res1 + " : " + res2 + " : " + res + " : " + value1 + " : " + value2);
}
Aggregations