Search in sources :

Example 11 with TransactionFactoryImple

use of com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple in project narayana by jbosstm.

the class TerminationTest method test.

@Test
public void test() {
    boolean commit = true;
    Control myControl = 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);
        TransactionFactoryImple theOTS = new TransactionFactoryImple();
        System.out.println("Creating transaction with 2 second timeout.");
        myControl = theOTS.create(2);
        assertNotNull(myControl);
        Terminator handle = myControl.get_terminator();
        try {
            System.out.println("Sleeping for 5 seconds.");
            Thread.sleep(5000);
        } catch (Exception e) {
        }
        if (handle != null) {
            System.out.print("Attempting to ");
            if (commit)
                System.out.println("commit transaction. Should fail!");
            else
                System.out.println("rollback transaction. Should fail!.");
            if (commit)
                handle.commit(true);
            else
                handle.rollback();
            assertFalse(commit);
            System.out.println("\nNow attempting to destroy transaction. Should fail!");
            OTSManager.destroyControl(myControl);
        } else
            System.err.println("No transaction terminator!");
    } catch (UserException e) {
        System.err.println("Caught UserException: " + e);
    } catch (SystemException e) {
        System.err.println("Caught SystemException: " + e);
        try {
            Coordinator coord = myControl.get_coordinator();
            Status s = coord.get_status();
            System.err.println("Transaction status: " + com.arjuna.ats.jts.utils.Utility.stringStatus(s));
            coord = null;
        } catch (Exception ex) {
        }
    }
    try {
        CurrentImple current = OTSImpleManager.current();
        FakeCheckedAction act = new FakeCheckedAction();
        current.set_timeout(2);
        current.setCheckedAction(act);
        assertEquals(act, current.getCheckedAction());
        System.out.println("\nNow creating current transaction with 2 second timeout.");
        current.begin();
        myControl = current.get_control();
        try {
            System.out.println("Sleeping for 5 seconds.");
            Thread.sleep(5000);
        } catch (Exception e) {
        }
        System.out.print("Attempting to ");
        if (commit)
            System.out.println("commit transaction. Should fail!");
        else
            System.out.println("rollback transaction. Should fail!.");
        if (commit)
            current.commit(true);
        else
            current.rollback();
        assertFalse(commit);
        assertTrue(act.called);
    } catch (UserException e) {
        System.err.println("Caught UserException: " + e);
        System.out.println("Test did not completed successfully.");
    } catch (SystemException e) {
        System.err.println("Caught SystemException: " + e);
        try {
            Coordinator coord = myControl.get_coordinator();
            Status s = coord.get_status();
            System.err.println("Transaction status: " + com.arjuna.ats.jts.utils.Utility.stringStatus(s));
            myControl = null;
            coord = null;
        } catch (Exception ex) {
        }
        System.out.println("Test completed successfully.");
    }
    myOA.destroy();
    myORB.shutdown();
}
Also used : Status(org.omg.CosTransactions.Status) RootOA(com.arjuna.orbportability.RootOA) Terminator(org.omg.CosTransactions.Terminator) Coordinator(org.omg.CosTransactions.Coordinator) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) SystemException(org.omg.CORBA.SystemException) UserException(org.omg.CORBA.UserException) Control(org.omg.CosTransactions.Control) SystemException(org.omg.CORBA.SystemException) TransactionFactoryImple(com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple) UserException(org.omg.CORBA.UserException) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 12 with TransactionFactoryImple

use of com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple in project narayana by jbosstm.

the class TransactionFactoryUnitTest method testBasic.

@Test
public void testBasic() throws Exception {
    TransactionFactoryImple factory = new TransactionFactoryImple("test");
    arjPropertyManager.getCoordinatorEnvironmentBean().setEnableStatistics(true);
    try {
        factory.numberOfTransactions(TransactionType.TransactionTypeActive);
    // fail();
    } catch (final Inactive ex) {
    } catch (final NoTransaction ex) {
    }
    ControlImple tx = factory.createLocal(1000);
    assertTrue(tx != null);
    org.omg.CosTransactions.otid_t[] txId = null;
    try {
        txId = factory.numberOfTransactions(TransactionType.TransactionTypeActive);
    } catch (final Throwable ex) {
        fail();
    }
    try {
        if (factory.getChildTransactions(txId[0]) != null)
            fail();
    } catch (final Throwable ex) {
        fail();
    }
    org.omg.CosTransactions.Status status = factory.getCurrentStatus(txId[0]);
    assertTrue(status == org.omg.CosTransactions.Status.StatusActive);
    assertTrue(factory.getStatus(txId[0]) == org.omg.CosTransactions.Status.StatusActive);
    Control proxy = factory.createProxy(tx.get_coordinator(), tx.get_terminator());
    assertTrue(proxy != null);
    Control propagated = factory.createPropagatedControl(tx.get_coordinator());
    assertTrue(propagated != null);
    assertTrue(Utility.getUid(proxy).equals(Utility.getUid(propagated)));
    GlobalTransactionInfo info = factory.getGlobalInfo();
    assertTrue(info != null);
    assertEquals(info.totalNumberOfTransactions, 1);
    assertEquals(info.numberOfHeuristics, 0);
    factory.numberOfTransactions(TransactionType.TransactionTypeUnresolved);
    try {
        tx.getImplHandle().rollback();
    } catch (final Throwable ex) {
    }
}
Also used : NoTransaction(org.omg.CosTransactions.NoTransaction) CosTransactions.otid_t(org.omg.CosTransactions.otid_t) GlobalTransactionInfo(com.arjuna.ArjunaOTS.GlobalTransactionInfo) Control(org.omg.CosTransactions.Control) TransactionFactoryImple(com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple) Status(org.omg.CosTransactions.Status) Inactive(org.omg.CosTransactions.Inactive) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) Test(org.junit.Test)

Example 13 with TransactionFactoryImple

use of com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple in project narayana by jbosstm.

the class TransactionFactoryUnitTest method testInfo.

@Test
public void testInfo() throws Exception {
    TransactionFactoryImple factory = new TransactionFactoryImple("test");
    ControlImple tx = factory.createLocal(1000);
    TransactionInfo info = factory.getTransactionInfo(Utility.uidToOtid(tx.get_uid()));
    assertEquals(info.currentDepth, 1);
    assertEquals(info.timeout, 0);
    assertEquals(info.numberOfThreads, 0);
    try {
        tx.getImplHandle().rollback();
    } catch (final Throwable ex) {
    }
}
Also used : TransactionFactoryImple(com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple) TransactionInfo(com.arjuna.ArjunaOTS.TransactionInfo) GlobalTransactionInfo(com.arjuna.ArjunaOTS.GlobalTransactionInfo) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) Test(org.junit.Test)

Example 14 with TransactionFactoryImple

use of com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple in project narayana by jbosstm.

the class TransactionFactoryUnitTest method testCompare.

@Test
public void testCompare() throws Exception {
    TransactionFactoryImple factory = new TransactionFactoryImple("test");
    ControlImple tx = factory.createLocal(1000);
    Control proxy = factory.getTransaction(Utility.uidToOtid(tx.get_uid()));
    assertTrue(Utility.getUid(proxy).equals(tx.get_uid()));
    try {
        tx.getImplHandle().rollback();
    } catch (final Throwable ex) {
    }
}
Also used : Control(org.omg.CosTransactions.Control) TransactionFactoryImple(com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) Test(org.junit.Test)

Example 15 with TransactionFactoryImple

use of com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple in project narayana by jbosstm.

the class HelperUnitTest method test.

@Test
public void test() throws Exception {
    Helper help = new Helper();
    TransactionFactoryImple factory = new TransactionFactoryImple("test");
    ControlImple tx = factory.createLocal(1000);
    assertTrue(Helper.localAction(tx.getControl()) != null);
    assertEquals(Helper.localControl(tx.getControl()), tx);
    assertTrue(Helper.getUidCoordinator(tx.get_coordinator()) != null);
    assertTrue(Helper.getUidCoordinator(tx.getControl()) != null);
    assertTrue(Helper.isUidCoordinator(tx.get_coordinator()));
}
Also used : Helper(com.arjuna.ats.internal.jts.utils.Helper) TransactionFactoryImple(com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple) ControlImple(com.arjuna.ats.internal.jts.orbspecific.ControlImple) Test(org.junit.Test)

Aggregations

TransactionFactoryImple (com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple)15 Test (org.junit.Test)12 ControlImple (com.arjuna.ats.internal.jts.orbspecific.ControlImple)10 Control (org.omg.CosTransactions.Control)6 SystemException (org.omg.CORBA.SystemException)4 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)3 INVALID_TRANSACTION (org.omg.CORBA.INVALID_TRANSACTION)3 UserException (org.omg.CORBA.UserException)3 GlobalTransactionInfo (com.arjuna.ArjunaOTS.GlobalTransactionInfo)2 Uid (com.arjuna.ats.arjuna.common.Uid)2 ServerControlWrapper (com.arjuna.ats.internal.jts.interposition.ServerControlWrapper)2 ORB (com.arjuna.orbportability.ORB)2 RootOA (com.arjuna.orbportability.RootOA)2 NoTransaction (org.omg.CosTransactions.NoTransaction)2 PropagationContext (org.omg.CosTransactions.PropagationContext)2 Status (org.omg.CosTransactions.Status)2 Terminator (org.omg.CosTransactions.Terminator)2 CosTransactions.otid_t (org.omg.CosTransactions.otid_t)2 InterpositionFailed (com.arjuna.ArjunaOTS.InterpositionFailed)1 TransactionInfo (com.arjuna.ArjunaOTS.TransactionInfo)1