use of com.arjuna.orbportability.RootOA in project narayana by jbosstm.
the class HeuristicTest method test.
@Test
public void test() throws Exception {
boolean shouldCommit = true;
boolean heuristicPrepare = false;
Coordinator coord = null;
ORB myORB = null;
RootOA myOA = null;
heuristic hImpl = null;
try {
myORB = ORB.getInstance("test");
myOA = OA.getRootOA(myORB);
myORB.initORB(new String[] {}, null);
myOA.initOA();
ORBManager.setORB(myORB);
ORBManager.setPOA(myOA);
Current current = OTSManager.get_current();
hImpl = new heuristic(heuristicPrepare);
Resource heuristicObject = hImpl.getReference();
AtomicResource aImpl = new AtomicResource(shouldCommit);
Resource atomicObject = aImpl.getReference();
System.out.println("beginning top-level transaction.");
current.begin();
Control myControl = current.get_control();
assertNotNull(myControl);
System.out.println("getting coordinator");
coord = myControl.get_coordinator();
myControl = null;
System.out.println("registering resources.");
try {
coord.register_resource(heuristicObject);
coord.register_resource(atomicObject);
} catch (Exception ex) {
fail("Failed to register resources: " + ex);
ex.printStackTrace(System.err);
}
System.out.println("committing top-level transaction.");
current.commit(true);
} catch (TRANSACTION_ROLLEDBACK e1) {
System.out.println("\nTransaction RolledBack exception");
} catch (HeuristicMixed e2) {
System.out.println("\nTransaction HeuristicMixed exception");
} catch (HeuristicHazard e3) {
System.out.println("\nTransaction HeuristicHazard exception");
} catch (Exception e4) {
fail("Caught unexpected exception: " + e4);
e4.printStackTrace(System.err);
}
System.out.println("Trying to determing final transaction outcome.");
org.omg.CosTransactions.Status status = Status.StatusUnknown;
try {
if (coord != null) {
status = coord.get_status();
coord = null;
} else {
fail("\nCould not determine action status.");
}
} catch (SystemException ex1) {
// assume invalid reference - tx may have been garbage collected
} catch (Exception e5) {
fail("Caught unexpected exception:" + e5);
e5.printStackTrace(System.err);
}
System.out.println("\nFinal action status: " + Utility.stringStatus(status));
System.out.println("Test completed successfully.");
ResourceTrace trace = hImpl.getTrace();
if ((!heuristicPrepare) && (shouldCommit) && (trace.getTrace() == ResourceTrace.ResourceTracePrepareCommitHeurisiticRollbackForget)) {
// assertSuccess();
} else {
if ((!heuristicPrepare) && (!shouldCommit) && (trace.getTrace() == ResourceTrace.ResourceTracePrepareRollback)) {
// assertSuccess();
} else {
if ((heuristicPrepare) && (shouldCommit) && (trace.getTrace() == ResourceTrace.ResourceTracePrepareHeuristicHazardForget)) {
// assertSuccess();
} else {
fail();
}
}
}
myOA.destroy();
myORB.shutdown();
}
use of com.arjuna.orbportability.RootOA in project narayana by jbosstm.
the class NestedTester method test.
@Test
public void test() {
boolean registerSubtran = false;
boolean doAbort = false;
DemoResource r = null;
DemoSubTranResource sr = null;
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);
org.omg.CosTransactions.Current current = OTSManager.get_current();
r = new DemoResource();
sr = new DemoSubTranResource();
current.begin();
current.begin();
current.begin();
sr.registerResource(registerSubtran);
r.registerResource();
System.out.println("committing first nested transaction");
current.commit(true);
System.out.println("committing second nested transaction");
current.commit(true);
if (!doAbort) {
System.out.println("committing top-level transaction");
current.commit(true);
} else {
System.out.println("aborting top-level transaction");
current.rollback();
}
System.out.println("Test completed successfully.");
if ((!doAbort) && (!registerSubtran) && (sr.getNumberOfSubtransactionsRolledBack() == 0) && (sr.getNumberOfSubtransactionsCommitted() == 1) && (sr.getResourceTrace().getTrace() == ResourceTrace.ResourceTracePrepareCommit) && (r.getResourceTrace().getTrace() == ResourceTrace.ResourceTracePrepareCommit)) {
// assertSuccess();
} else {
if ((doAbort) && (!registerSubtran) && (sr.getNumberOfSubtransactionsRolledBack() == 0) && (sr.getNumberOfSubtransactionsCommitted() == 1) && (sr.getResourceTrace().getTrace() == ResourceTrace.ResourceTraceRollback) && (r.getResourceTrace().getTrace() == ResourceTrace.ResourceTraceRollback)) {
// assertSuccess();
} else {
if ((!doAbort) && (registerSubtran) && (sr.getNumberOfSubtransactionsRolledBack() == 0) && (sr.getNumberOfSubtransactionsCommitted() == 1) && (sr.getResourceTrace().getTrace() == ResourceTrace.ResourceTraceNone) && (r.getResourceTrace().getTrace() == ResourceTrace.ResourceTraceCommitOnePhase)) {
// assertSuccess();
} else {
if ((doAbort) && (registerSubtran) && (sr.getNumberOfSubtransactionsRolledBack() == 0) && (sr.getNumberOfSubtransactionsCommitted() == 1) && (sr.getResourceTrace().getTrace() == ResourceTrace.ResourceTraceNone) && (r.getResourceTrace().getTrace() == ResourceTrace.ResourceTraceRollback)) {
// assertSuccess();
} else
fail();
}
}
}
} catch (UserException e) {
fail("Caught UserException: " + e);
e.printStackTrace(System.err);
} catch (SystemException e) {
fail("Caught SystemException: " + e);
e.printStackTrace(System.err);
}
myOA.shutdownObject(r);
myOA.shutdownObject(sr);
myOA.destroy();
myORB.shutdown();
}
use of com.arjuna.orbportability.RootOA in project narayana by jbosstm.
the class TransactionTest3 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);
try {
OTSManager.get_current().begin();
Control cont = OTSManager.get_current().get_control();
OTSManager.get_current().commit(true);
OTSManager.get_current().resume(cont);
System.out.println("\nPassed.");
} catch (Throwable e) {
fail("caught: " + e);
e.printStackTrace();
}
myOA.destroy();
myORB.shutdown();
}
use of com.arjuna.orbportability.RootOA in project narayana by jbosstm.
the class TransactionTest4 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);
try {
OTSManager.get_current().begin();
Control cont = OTSManager.get_current().get_control();
OTSManager.get_current().commit(true);
OTSManager.get_current().resume(cont);
cont = OTSManager.get_current().suspend();
System.out.println("\nPassed.");
} catch (Throwable e) {
fail("caught: " + e);
e.printStackTrace();
}
myOA.destroy();
myORB.shutdown();
}
use of com.arjuna.orbportability.RootOA in project narayana by jbosstm.
the class TransactionTest5 method test.
@Test
public void test() throws Exception {
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);
} catch (Exception e) {
System.err.println("Initialisation failed: " + e);
}
try {
OTSManager.get_current().begin();
Control cont = OTSManager.get_current().get_control();
OTSManager.get_current().commit(true);
OTSManager.get_current().resume(cont);
OTSManager.get_current().rollback_only();
System.out.println("\nFailed.");
} catch (org.omg.CosTransactions.NoTransaction ex) {
System.out.println("\nPassed.");
} catch (Throwable e) {
fail("caught: " + e);
e.printStackTrace();
}
myOA.destroy();
myORB.shutdown();
}
Aggregations