Search in sources :

Example 61 with ORB

use of com.arjuna.orbportability.ORB in project narayana by jbosstm.

the class CheckedTransactions 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);
        Control tx = null;
        System.out.println("Thread " + Thread.currentThread() + " starting transaction.");
        OTSImpleManager.current().setCheckedAction(new MyCheckedAction());
        OTSImpleManager.current().begin();
        tx = OTSImpleManager.current().get_control();
        TXThread txThread = new TXThread(tx);
        txThread.start();
        txThread.join();
        System.out.println("Thread " + Thread.currentThread() + " committing transaction.");
        OTSImpleManager.current().commit(false);
        System.out.println("Transaction committed. Checked transactions enabled.");
    } catch (Exception e) {
        System.out.println("Caught exception: " + e);
        fail("Checked transactions disabled!");
    }
    myOA.destroy();
    myORB.shutdown();
}
Also used : Control(org.omg.CosTransactions.Control) RootOA(com.arjuna.orbportability.RootOA) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 62 with ORB

use of com.arjuna.orbportability.ORB 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 63 with ORB

use of com.arjuna.orbportability.ORB in project narayana by jbosstm.

the class TransactionTest1 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 theFactory = OTSManager.get_factory();
    Control topLevelControl = null;
    Control nestedControl = null;
    Terminator terminator = null;
    try {
        org.omg.CosTransactions.Current current = OTSManager.get_current();
        current.begin();
        topLevelControl = current.get_control();
        current.begin();
        nestedControl = current.get_control();
        /*
            * Try to commit top-level action without terminating nested
            * action.
            */
        terminator = topLevelControl.get_terminator();
        System.out.println("\nAttempting to terminate out of sequence 'current'. Should fail!");
        try {
            terminator.commit(true);
            fail();
        } catch (TRANSACTION_ROLLEDBACK e) {
            System.err.println("Commit failed! " + e);
        }
        System.out.println("\nNow attempting to terminate 'current' hierarchy. Should fail!");
        try {
            current.commit(true);
            fail();
        } catch (INVALID_TRANSACTION e1) {
            System.err.println("Nested commit failed! " + e1);
        } catch (TRANSACTION_ROLLEDBACK e1) {
            System.err.println("Nested commit failed! " + e1);
        } catch (Exception e2) {
            fail("Nested commit threw unexpected exception: " + e2);
        }
        try {
            current.commit(true);
            fail();
        } catch (TRANSACTION_ROLLEDBACK e1) {
            System.err.println("Top-level commit failed! " + e1);
        } catch (INVALID_TRANSACTION e2) {
            System.err.println("Top-level commit failed! " + e2);
        } catch (Exception e3) {
            fail("Top-level commit threw unexpected exception: " + e3);
        }
        /*
            * Now with the factory.
            */
        System.out.println("\nNow creating new top-level action.");
        topLevelControl = theFactory.create(0);
        nestedControl = topLevelControl.get_coordinator().create_subtransaction();
        terminator = topLevelControl.get_terminator();
        System.out.println("\nAttempting to terminate out of sequence 'factory' action. Should fail!");
        try {
            terminator.commit(true);
            fail();
        } catch (TRANSACTION_ROLLEDBACK e1) {
            System.err.println("Commit failed! " + e1);
        } catch (INVALID_TRANSACTION e2) {
            System.err.println("Commit failed! " + e2);
        }
        terminator = nestedControl.get_terminator();
        System.out.println("\nNow attempting to terminate 'factory' nested action. Should fail!");
        try {
            terminator.commit(true);
            fail();
        } catch (TRANSACTION_ROLLEDBACK e1) {
            System.err.println("Commit failed! " + e1);
        } catch (INVALID_TRANSACTION e2) {
            System.err.println("Commit failed! " + e2);
        }
        System.out.println("Test completed successfully.");
    } catch (Exception e) {
        fail("Test failed - received unexpected exception " + e);
    }
    myOA.destroy();
    myORB.shutdown();
}
Also used : Control(org.omg.CosTransactions.Control) INVALID_TRANSACTION(org.omg.CORBA.INVALID_TRANSACTION) TransactionFactory(org.omg.CosTransactions.TransactionFactory) RootOA(com.arjuna.orbportability.RootOA) Terminator(org.omg.CosTransactions.Terminator) TRANSACTION_ROLLEDBACK(org.omg.CORBA.TRANSACTION_ROLLEDBACK) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 64 with ORB

use of com.arjuna.orbportability.ORB in project narayana by jbosstm.

the class TransactionTest2 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);
    int count = 0;
    System.out.println("Testing memory allocation.");
    System.out.println("Creating as many transactions as possible.\n");
    try {
        for (; ; ) {
            OTSManager.get_current().begin();
            count++;
        }
    } catch (Exception e) {
        System.err.println("begin caught: " + e);
        System.gc();
    } catch (Error e) {
        System.err.println("begin caught: " + e);
        e.printStackTrace();
        System.gc();
    }
    System.out.println("\nbegan: " + count);
    try {
        int created = count;
        System.out.println("\nNow rolling back transactions.");
        for (int i = 0; i < created; i++) {
            try {
                System.out.println("" + count);
                OTSManager.get_current().rollback();
                count--;
            } catch (OutOfMemoryError em) {
                em.printStackTrace();
                System.gc();
            }
        }
    } catch (Exception e) {
        System.err.println("rollback caught: " + e);
        System.gc();
    } catch (Error e) {
        System.err.println("rollback caught: " + e);
        e.printStackTrace();
        System.gc();
    }
    System.out.println("\nStill to rollback: " + count);
    myOA.destroy();
    myORB.shutdown();
}
Also used : RootOA(com.arjuna.orbportability.RootOA) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 65 with ORB

use of com.arjuna.orbportability.ORB in project narayana by jbosstm.

the class ImplicitClient method main.

public static void main(String[] args) throws Exception {
    ServerORB orb = new ServerORB();
    ORB myORB = orb.getORB();
    RootOA myOA = orb.getOA();
    String refFile = args[0];
    CurrentImple current = OTSImpleManager.current();
    // pointer the grid object that will be used.
    TranGrid TranGridVar = null;
    short h = 0, w = 0, v = 0;
    try {
        current.begin();
        Services serv = new Services(myORB);
        TranGridVar = TranGridHelper.narrow(myORB.orb().string_to_object(TestUtility.getService(refFile)));
        try {
            h = TranGridVar.height();
            w = TranGridVar.width();
        } catch (Exception e) {
            TestUtility.fail("Invocation failed: " + e);
        }
        System.out.println("height is " + h);
        System.out.println("width  is " + w);
        try {
            System.out.println("calling set");
            TranGridVar.set((short) 2, (short) 4, (short) 123);
            System.out.println("calling get");
            v = TranGridVar.get((short) 2, (short) 4);
        } catch (Exception sysEx) {
            TestUtility.fail("Grid set/get failed: " + sysEx);
            sysEx.printStackTrace(System.err);
        }
        // no problem setting and getting the element:
        System.out.println("trangrid[2,4] is " + v);
        if (v != 123) {
            // oops - we didn't:
            current.rollback();
            TestUtility.fail("Result not as expected");
        } else {
            current.commit(true);
        }
    } catch (Exception e) {
        TestUtility.fail("Caught exception: " + e);
        e.printStackTrace(System.err);
    }
    myOA.destroy();
    myORB.shutdown();
    System.out.println("Passed");
}
Also used : ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) Services(com.arjuna.orbportability.Services) RootOA(com.arjuna.orbportability.RootOA) CurrentImple(com.arjuna.ats.internal.jts.orbspecific.CurrentImple) ServerORB(com.hp.mwtests.ts.jts.utils.ServerORB) ORB(com.arjuna.orbportability.ORB) TranGrid(com.hp.mwtests.ts.jts.TestModule.TranGrid)

Aggregations

ORB (com.arjuna.orbportability.ORB)93 RootOA (com.arjuna.orbportability.RootOA)71 Test (org.junit.Test)57 OA (com.arjuna.orbportability.OA)20 ServerORB (com.hp.mwtests.ts.jts.utils.ServerORB)20 Control (org.omg.CosTransactions.Control)20 Services (com.arjuna.orbportability.Services)19 CurrentImple (com.arjuna.ats.internal.jts.orbspecific.CurrentImple)9 PerfTestInterface (org.jboss.jbossts.qa.performance.PerfTestInterface)7 SystemException (org.omg.CORBA.SystemException)7 IntHolder (org.omg.CORBA.IntHolder)6 Coordinator (org.omg.CosTransactions.Coordinator)6 UserException (org.omg.CORBA.UserException)5 Properties (java.util.Properties)4 TRANSACTION_ROLLEDBACK (org.omg.CORBA.TRANSACTION_ROLLEDBACK)4 Terminator (org.omg.CosTransactions.Terminator)4 AtomicObject (com.hp.mwtests.ts.jts.orbspecific.resources.AtomicObject)3 Status (org.omg.CosTransactions.Status)3 TransactionFactory (org.omg.CosTransactions.TransactionFactory)3 TransactionFactoryImple (com.arjuna.ats.internal.jts.orbspecific.TransactionFactoryImple)2