use of org.omg.CosTransactions.Control in project narayana by jbosstm.
the class ServerTopLevelRestrictedUnitTest method testCommit.
@Test
public void testCommit() throws Exception {
ControlImple cont = new ControlImple(null, null);
Control theControl = cont.getControl();
ArjunaTransactionImple tx = cont.getImplHandle();
ServerControl sc = new ServerControl(tx.get_uid(), theControl, tx, theControl.get_coordinator(), theControl.get_terminator());
ServerRestrictedTopLevelAction act = new ServerRestrictedTopLevelAction(sc);
assertTrue(act.type() != null);
assertTrue(act.child() == null);
assertTrue(act.deepestControl() != null);
}
use of org.omg.CosTransactions.Control in project narayana by jbosstm.
the class ServerTopLevelStrictUnitTest method test.
@Test
public void test() throws Exception {
ControlImple cont = new ControlImple(null, null);
Control theControl = cont.getControl();
ArjunaTransactionImple tx = cont.getImplHandle();
ServerControl sc = new ServerControl(tx.get_uid(), theControl, tx, theControl.get_coordinator(), theControl.get_terminator());
ServerStrictTopLevelAction act = new ServerStrictTopLevelAction(sc, true);
assertTrue(act.interposeResource());
assertTrue(act.type() != null);
}
use of org.omg.CosTransactions.Control in project narayana by jbosstm.
the class GridTest method test.
@Test
public void test() {
ORB myORB = null;
RootOA myOA = null;
try {
myORB = ORB.getInstance("test");
myOA = OA.getRootOA(myORB);
myORB.initORB(new String[] {}, null);
myOA.initOA();
ORBManager.setORB(myORB);
ORBManager.setPOA(myOA);
TransactionFactoryImple theOTS = new TransactionFactoryImple();
Control myControl;
grid_i localGrid = new grid_i(100, 100);
int h, w, v;
myControl = theOTS.create(0);
assertNotNull(myControl);
h = localGrid.height();
w = localGrid.width();
localGrid.set(2, 4, 123, myControl);
v = localGrid.get(2, 4, myControl);
// no problem setting and getting the elememt:
System.out.println("grid[2,4] is " + v);
assertEquals(123, v);
Terminator handle = myControl.get_terminator();
try {
if (handle != null) {
handle.commit(false);
} else
System.err.println("Error - no transaction terminator!");
} catch (Exception ex) {
System.out.println("Test error! Caught: " + ex);
}
ORBManager.getPOA().shutdownObject(theOTS);
ORBManager.getPOA().shutdownObject(localGrid);
} catch (UserException e) {
fail("Caught UserException: " + e);
e.printStackTrace();
} catch (SystemException e) {
fail("Caught SystemException: " + e);
e.printStackTrace();
}
System.out.println("\nWill now try different thread terminating transaction.\n");
try {
org.omg.CosTransactions.Current current = OTSManager.get_current();
System.out.println("Starting new transaction.");
current.begin();
Control tc = current.get_control();
if (tc != null) {
System.out.println("Creating new thread.");
TransactionalThread tranThread = new TransactionalThread(tc);
System.out.println("Waiting for thread to terminate transaction.\n");
tranThread.start();
while (!tranThread.finished()) Thread.yield();
System.out.println("\nCreator will now attempt to rollback transaction. Should fail.");
try {
current.rollback();
fail("Error - managed to rollback transaction!");
} catch (NoTransaction e1) {
System.out.println("Correct termination - caught: " + e1);
} catch (INVALID_TRANSACTION e2) {
System.out.println("Correct termination - caught: " + e2);
} catch (Exception e3) {
fail("Wrong termination - caught unexpected exception: " + e3);
e3.printStackTrace();
}
System.out.println("Test completed successfully.");
} else
System.err.println("Error - null transaction control!");
} catch (Exception e) {
System.out.println("Caught unexpected exception: " + e);
}
myOA.destroy();
myORB.shutdown();
}
use of org.omg.CosTransactions.Control in project narayana by jbosstm.
the class DistributedHammerWorker2 method get21.
public static void get21(char thr, int level) {
boolean res = false;
boolean res1 = false;
boolean res2 = false;
IntHolder value1 = new IntHolder(0);
IntHolder value2 = new IntHolder(0);
try {
OTSImpleManager.current().begin();
Control control = OTSImpleManager.current().get_control();
Util.indent(thr, level);
System.out.println("begin get21");
res1 = hammerObject_2.get(value1, control);
res = res1;
Util.indent(thr, level);
System.out.println("part1 get21 : " + res1);
Util.lowProbYield();
if (res) {
res2 = hammerObject_1.get(value2, control);
res = res2;
Util.indent(thr, level);
System.out.println("part2 get21 : " + res2);
}
Util.lowProbYield();
control = null;
Util.indent(thr, level);
if (res) {
System.out.print("end ");
OTSImpleManager.current().commit(true);
} else {
System.out.print("abort ");
OTSImpleManager.current().rollback();
}
} catch (Exception e) {
System.err.println("DistributedHammerWorker2.get21: " + e);
res1 = res2 = res = false;
}
Util.indent(thr, level);
System.out.println(" get21 : " + res1 + " : " + res2 + " : " + res + " : " + value1.value + " : " + value2.value);
}
use of org.omg.CosTransactions.Control in project narayana by jbosstm.
the class DistributedHammerWorker2 method get12.
public static void get12(char thr, int level) {
boolean res = false;
boolean res1 = false;
boolean res2 = false;
IntHolder value1 = new IntHolder(0);
IntHolder value2 = new IntHolder(0);
try {
OTSImpleManager.current().begin();
Control control = OTSImpleManager.current().get_control();
Util.indent(thr, level);
System.out.println("begin get12");
res1 = hammerObject_1.get(value1, control);
res = res1;
Util.indent(thr, level);
System.out.println("part1 get12 : " + res1);
Util.lowProbYield();
if (res) {
res2 = hammerObject_2.get(value2, control);
res = res2;
Util.indent(thr, level);
System.out.println("part2 get12 : " + res2);
}
Util.lowProbYield();
control = null;
Util.indent(thr, level);
if (res) {
System.out.print("end ");
OTSImpleManager.current().commit(true);
} else {
System.out.print("abort ");
OTSImpleManager.current().rollback();
}
} catch (Exception e) {
System.err.println("DistributedHammerWorker2.get12: " + e);
res1 = res2 = res = false;
}
Util.indent(thr, level);
System.out.println(" get12 : " + res1 + " : " + res2 + " : " + res + " : " + value1.value + " : " + value2.value);
}
Aggregations