use of com.hp.mwtests.ts.txoj.common.exceptions.TestException in project narayana by jbosstm.
the class BasicThreadedObject method run.
public void run() {
if (startAction) {
BasicThreadedObject.A = new AtomicAction();
System.out.println("BasicThreadedObject " + uid + " created action " + BasicThreadedObject.A.get_uid());
BasicThreadedObject.A.begin();
Thread.yield();
} else {
System.out.println("BasicThreadedObject " + uid + " adding to action " + BasicThreadedObject.A.get_uid());
BasicThreadedObject.A.addThread();
Thread.yield();
}
BasicAction act = BasicAction.Current();
if (act != null)
System.out.println("BasicThreadedObject " + uid + " current action " + act.get_uid());
else
System.out.println("BasicThreadedObject " + uid + " current action null");
try {
BasicThreadedObject.O.incr(4);
Thread.yield();
} catch (TestException e) {
}
if (startAction) {
System.out.println("\nBasicThreadedObject " + uid + " committing action " + act.get_uid());
BasicThreadedObject.A.commit();
System.out.println("BasicThreadedObject " + uid + " action " + act.get_uid() + " committed\n");
} else {
System.out.println("\nBasicThreadedObject " + uid + " aborting action " + act.get_uid());
BasicThreadedObject.A.abort();
System.out.println("BasicThreadedObject " + uid + " action " + act.get_uid() + " aborted\n");
}
}
use of com.hp.mwtests.ts.txoj.common.exceptions.TestException in project narayana by jbosstm.
the class AtomicObjectTest2 method get12.
private static void get12(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 get12");
try {
value1 = atomicObject1.get();
} catch (TestException e) {
res = res1 = false;
}
indent(thr, level);
System.out.println("part1 get12 : " + res1);
lowProbYield();
if (res) {
try {
value2 = atomicObject2.get();
} catch (TestException e) {
res = res2 = false;
}
indent(thr, level);
System.out.println("part2 get12 : " + res2);
} else
res2 = false;
lowProbYield();
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(" get12 : " + res1 + " : " + res2 + " : " + res + " : " + value1 + " : " + value2);
}
use of com.hp.mwtests.ts.txoj.common.exceptions.TestException in project narayana by jbosstm.
the class AtomicObjectTest4 method incr12.
private static void incr12(int thr, int level) {
boolean res = true;
boolean res1 = true;
boolean res2 = true;
int ran;
AtomicAction a = new AtomicAction();
a.begin();
indent(thr, level);
System.out.println("begin incr12");
ran = Math.abs(rand.nextInt()) % 16;
try {
atomicObject1.incr(ran);
} catch (TestException e) {
res = res1 = false;
}
indent(thr, level);
System.out.println("part1 incr12 : " + res1 + " " + res);
lowProbYield();
if (res) {
try {
atomicObject2.incr(-ran);
} catch (TestException e) {
res = res2 = false;
}
indent(thr, level);
System.out.println("part2 incr12 : " + res2);
} else
res2 = false;
lowProbYield();
indent(thr, level);
if (res) {
System.out.flush();
System.out.print("commit ");
System.out.flush();
res = (boolean) (a.commit() == ActionStatus.COMMITTED);
} else {
System.out.flush();
System.out.print("abort ");
System.out.flush();
a.abort();
}
System.out.println(" incr12 : " + res1 + " : " + res2 + " : " + res + " : " + ran);
}
use of com.hp.mwtests.ts.txoj.common.exceptions.TestException in project narayana by jbosstm.
the class AtomicObjectTest4 method test.
@Test
public void test() throws TestException {
rand = new Random();
atomicObject1 = new AtomicObject(ObjectModel.MULTIPLE);
atomicObject2 = new AtomicObject(ObjectModel.MULTIPLE);
System.out.println(atomicObject1.get_uid());
System.out.println(atomicObject2.get_uid());
try {
atomicObject1.set(START_VALUE_1);
} catch (TestException e) {
System.out.println("0 set1 : failed");
}
try {
atomicObject2.set(START_VALUE_2);
} catch (TestException e) {
System.out.println("0 set2 : failed");
}
ThreadObject2[] thrs = new ThreadObject2[NUMBER_THREADS];
for (int i = 0; i < NUMBER_THREADS; i++) thrs[i] = new ThreadObject2(i + 1);
for (int j = 0; j < NUMBER_THREADS; j++) thrs[j].start();
try {
for (int k = 0; k < NUMBER_THREADS; k++) thrs[k].join();
} catch (InterruptedException e) {
}
get12(0, 0);
get21(0, 0);
assertEquals(EXPECTED_RESULT, (getValue1() + getValue2()));
}
use of com.hp.mwtests.ts.txoj.common.exceptions.TestException in project narayana by jbosstm.
the class AtomicObjectTest4 method get12.
private static void get12(int 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 get12");
try {
value1 = atomicObject1.get();
} catch (TestException e) {
res = res1 = false;
}
indent(thr, level);
System.out.println("part1 get12 : " + res1);
lowProbYield();
if (res) {
try {
value2 = atomicObject2.get();
} catch (TestException e) {
res = res2 = false;
}
indent(thr, level);
System.out.println("part2 get12 : " + res2);
} else
res2 = false;
lowProbYield();
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(" get12 : " + res1 + " : " + res2 + " : " + res + " : " + value1 + " : " + value2);
}
Aggregations