use of org.omg.CosTransactions.Control in project narayana by jbosstm.
the class SuspendResume method test.
@Test
public void test() throws Exception {
ORB myORB = null;
RootOA myOA = null;
myORB = ORB.getInstance("test");
myOA = OA.getRootOA(myORB);
myORB.initORB(new String[] {}, null);
myOA.initOA();
ORBManager.setORB(myORB);
ORBManager.setPOA(myOA);
CurrentImple current = OTSImpleManager.current();
Control myControl = null;
System.out.println("Beginning transaction.");
try {
current.begin();
myControl = current.get_control();
assertNotNull(myControl);
} catch (Exception sysEx) {
sysEx.printStackTrace(System.err);
fail();
}
System.out.println("Committing transaction.");
try {
current.commit(true);
current.resume(myControl);
} catch (Exception e) {
fail("commit error: " + e);
e.printStackTrace(System.err);
}
myOA.destroy();
myORB.shutdown();
System.out.println("Test completed successfully.");
}
use of org.omg.CosTransactions.Control in project narayana by jbosstm.
the class GridClient method test.
@Test
public void test() throws Exception {
ORB myORB = null;
RootOA myOA = null;
myORB = ORB.getInstance("test");
myOA = OA.getRootOA(myORB);
myORB.initORB(new String[] {}, null);
myOA.initOA();
ORBManager.setORB(myORB);
ORBManager.setPOA(myOA);
TransactionFactory theOTS = null;
Control myControl = null;
grid gridVar = null;
int h = -1, w = -1, v = -1;
String gridReference = "/tmp/grid.ref";
String serverName = "Grid";
if (System.getProperty("os.name").startsWith("Windows")) {
gridReference = "C:\\temp\\grid.ref";
}
Services serv = new Services(myORB);
try {
String[] params = new String[1];
params[0] = Services.otsKind;
org.omg.CORBA.Object obj = serv.getService(Services.transactionService, params);
params = null;
theOTS = TransactionFactoryHelper.narrow(obj);
} catch (Exception e) {
fail("Unexpected bind exception: " + e);
}
System.out.println("Creating transaction.");
try {
myControl = theOTS.create(0);
} catch (Exception e) {
fail("Create call failed: " + e);
e.printStackTrace();
}
try {
gridVar = gridHelper.narrow(serv.getService(gridReference, null, Services.FILE));
} catch (Exception e) {
fail("Grid bind failed: " + e);
}
try {
h = gridVar.height();
w = gridVar.width();
} catch (Exception e) {
fail("Grid invocation failed: " + e);
}
System.out.println("height is " + h);
System.out.println("width is " + w);
try {
System.out.println("calling set");
gridVar.set(2, 4, 123, myControl);
System.out.println("calling get");
v = gridVar.get(2, 4, myControl);
} catch (Exception sysEx) {
fail("Grid set/get failed: " + sysEx);
}
// no problem setting and getting the elememt:
System.out.println("grid[2,4] is " + v);
// sanity check: make sure we got the value 123 back:
if (v != 123) {
// oops - we didn't:
fail("something went seriously wrong");
try {
myControl.get_terminator().rollback();
} catch (Exception e) {
}
} else {
System.out.println("Committing transaction.");
try {
Terminator handle = myControl.get_terminator();
handle.commit(true);
} catch (Exception sysEx) {
fail("Transaction commit error: " + sysEx);
}
}
try {
OTSManager.destroyControl(myControl);
} catch (Exception e) {
fail("Caught destroy exception: " + e);
}
myOA.destroy();
myORB.shutdown();
System.out.println("Test completed successfully.");
}
use of org.omg.CosTransactions.Control in project narayana by jbosstm.
the class ExplicitInterClient method main.
public static void main(String[] args) throws Exception {
ServerORB orb = new ServerORB();
ORB myORB = orb.getORB();
RootOA myOA = orb.getOA();
CurrentImple current = OTSImpleManager.current();
Control theControl = null;
String objectReference = args[0];
SetGet SetGetVar = null;
short h = 0;
try {
current.begin();
current.begin();
current.begin();
} catch (Exception e) {
TestUtility.fail("Caught exception during begin: " + e);
e.printStackTrace(System.err);
}
try {
Services serv = new Services(myORB);
SetGetVar = SetGetHelper.narrow(myORB.orb().string_to_object(TestUtility.getService(objectReference)));
} catch (Exception ex) {
TestUtility.fail("Failed to bind to setget server: " + ex);
ex.printStackTrace(System.err);
}
try {
theControl = current.get_control();
SetGetVar.set((short) 2, theControl);
// SetGetVar.set((short) 2, theControl);
theControl = null;
System.out.println("Set value.");
} catch (Exception ex1) {
TestUtility.fail("Unexpected system exception during set: " + ex1);
ex1.printStackTrace(System.err);
}
try {
System.out.println("committing first nested action");
current.commit(true);
// SetGetVar.set((short) 4, current.get_control());
System.out.println("committing second nested action");
current.commit(true);
} catch (Exception sysEx) {
TestUtility.fail("Caught unexpected exception during commit: " + sysEx);
sysEx.printStackTrace(System.err);
}
try {
theControl = current.get_control();
h = SetGetVar.get(theControl);
theControl = null;
System.out.println("Got value.");
} catch (Exception ex2) {
TestUtility.fail("Unexpected system exception during get: " + ex2);
ex2.printStackTrace(System.err);
}
try {
current.commit(true);
System.out.println("committed top-level action");
} catch (Exception ep) {
TestUtility.fail("Caught commit exception for top-level action: " + ep);
ep.printStackTrace(System.err);
}
myOA.destroy();
myORB.shutdown();
System.out.println("Passed");
}
use of org.omg.CosTransactions.Control in project narayana by jbosstm.
the class ServerNestedRestrictedUnitTest 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());
ServerRestrictedNestedAction act = new ServerRestrictedNestedAction(sc);
assertTrue(act.deepestControl() != null);
assertEquals(act.child(), null);
}
use of org.omg.CosTransactions.Control in project narayana by jbosstm.
the class ServerNestedStrictUnitTest 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());
ServerStrictNestedAction act = new ServerStrictNestedAction(sc, true);
assertFalse(act.interposeResource());
act.commit_subtransaction(null);
}
Aggregations