use of org.omg.CosTransactions.Control in project narayana by jbosstm.
the class ServerRecoveryTopLevelUnitTest 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());
DummyServerRecovery act = new DummyServerRecovery(sc);
act.destroyResource();
}
use of org.omg.CosTransactions.Control in project narayana by jbosstm.
the class ServerTopLevelActionUnitTest 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());
ServerTopLevelAction act = new ServerTopLevelAction(sc);
assertEquals(act.prepare(), Vote.VoteReadOnly);
try {
act.commit();
fail();
} catch (final INVALID_TRANSACTION ex) {
}
assertTrue(act.getReference() != null);
}
use of org.omg.CosTransactions.Control in project narayana by jbosstm.
the class ServerTopLevelActionUnitTest method testCommitOnePhase.
@Test
public void testCommitOnePhase() 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());
ServerTopLevelAction act = new ServerTopLevelAction(sc);
act.commit_one_phase();
assertTrue(act.type() != null);
}
use of org.omg.CosTransactions.Control in project narayana by jbosstm.
the class ServerTopLevelActionUnitTest method testRollback.
@Test
public void testRollback() 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());
ServerTopLevelAction act = new ServerTopLevelAction(sc);
assertEquals(act.prepare(), Vote.VoteReadOnly);
try {
act.rollback();
fail();
} catch (final INVALID_TRANSACTION ex) {
}
act.forget();
}
use of org.omg.CosTransactions.Control in project narayana by jbosstm.
the class RCTest method test.
@Test
public void test() {
boolean shouldCommit = true;
boolean passed = false;
Coordinator coord = 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);
CurrentImple current = OTSImpleManager.current();
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.");
RecoveryCoordinator rc = null;
try {
rc = coord.register_resource(atomicObject);
} catch (Exception ex) {
fail("Failed to register resources: " + ex);
ex.printStackTrace();
}
if (rc == null)
System.out.println("No recovery coordinator reference.");
else {
Status s = Status.StatusUnknown;
try {
System.out.println("Attempting to use recovery coordinator.");
s = rc.replay_completion(atomicObject);
} catch (NotPrepared e) {
s = Status.StatusActive;
} catch (Exception ex) {
fail("Caught: " + ex);
ex.printStackTrace();
}
System.out.println("Got: " + com.arjuna.ats.jts.utils.Utility.stringStatus(s));
if (s == Status.StatusActive)
passed = true;
}
System.out.println("committing top-level transaction.");
if (shouldCommit)
current.commit(true);
else
current.rollback();
if (rc == null)
System.out.println("No recovery coordinator reference.");
else {
Status s = Status.StatusUnknown;
try {
System.out.println("Attempting to use recovery coordinator.");
s = rc.replay_completion(atomicObject);
} catch (NotPrepared e) {
s = Status.StatusActive;
} catch (Exception ex) {
fail("Caught: " + ex);
}
System.out.println("Got: " + com.arjuna.ats.jts.utils.Utility.stringStatus(s));
if (passed && (s == Status.StatusRolledBack))
passed = true;
else
passed = false;
}
} 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) {
System.out.println("Caught unexpected exception: " + e4);
}
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
System.out.println("\nCould not determine action status.");
} catch (SystemException ex1) {
// assume invalid reference - tx may have been garbage collected
} catch (Exception e5) {
System.out.println("Caught unexpected exception:" + e5);
}
System.out.println("\nFinal action status: " + com.arjuna.ats.jts.utils.Utility.stringStatus(status));
assertTrue(passed);
myOA.destroy();
myORB.shutdown();
}
Aggregations