1 22 package org.jboss.test.txiiop.test; 23 24 import javax.naming.Context ; 25 import javax.rmi.PortableRemoteObject ; 26 import javax.transaction.UserTransaction ; 27 28 import junit.framework.Test; 29 import org.jboss.test.JBossIIOPTestCase; 30 import org.jboss.test.txiiop.interfaces.StatefulSession; 31 import org.jboss.test.txiiop.interfaces.StatefulSessionHome; 32 33 41 public class IIOPUserTransactionStressTestCase 42 extends JBossIIOPTestCase 43 { 44 public IIOPUserTransactionStressTestCase (String name) 46 { 47 super(name); 48 } 49 50 52 public void testUserTx() 53 throws Exception 54 { 55 getLog().debug("+++ testUsrTx"); 56 57 getLog().debug("Obtain home interface"); 58 Context ctx = getInitialContext(); 60 Object ref = ctx.lookup("txiiop/StatefulSessionBean"); 61 StatefulSessionHome home = 62 (StatefulSessionHome) PortableRemoteObject.narrow( 63 ref, StatefulSessionHome.class); 64 StatefulSession bean = home.create("testUserTx"); 65 66 bean.setCounter(100); 67 getLog().debug("Try to instantiate a UserTransaction"); 68 UserTransaction userTx = (UserTransaction )ctx.lookup("UserTransaction"); 69 userTx.begin(); 70 bean.incCounter(); 71 bean.incCounter(); 72 userTx.commit(); 73 int counter = bean.getCounter(); 74 assertTrue("counter == 102", counter == 102); 75 76 bean.setCounter(100); 77 userTx.begin(); 78 bean.incCounter(); 79 bean.incCounter(); 80 userTx.rollback(); 81 counter = bean.getCounter(); 82 assertTrue("counter == 100", counter == 100); 83 84 bean.remove(); 85 } 86 87 public void testTxMandatory() 88 throws Exception 89 { 90 getLog().debug("+++ testTxMandatory"); 91 92 getLog().debug("Obtain home interface"); 93 Context ctx = getInitialContext(); 95 Object ref = ctx.lookup("txiiop/StatefulSessionBean"); 96 StatefulSessionHome home = 97 (StatefulSessionHome) PortableRemoteObject.narrow( 98 ref, StatefulSessionHome.class); 99 StatefulSession bean = home.create("testTxMandatory"); 100 getLog().debug("Call txMandatoryMethod without a UserTransaction"); 101 try 102 { 103 bean.txMandatoryMethod("without a UserTransaction"); 104 getLog().debug("Should not get here!"); 105 fail("TransactionRequiredException should have been thrown"); 106 } 107 catch (javax.transaction.TransactionRequiredException e) 108 { 109 getLog().debug("Expected exception: " + e); 110 } 111 getLog().debug("Begin UserTransaction"); 112 UserTransaction userTx = (UserTransaction )ctx.lookup("UserTransaction"); 113 userTx.begin(); 114 bean.txMandatoryMethod("within a UserTransaction"); 115 getLog().debug("Commit UserTransaction"); 116 userTx.commit(); 117 bean.remove(); 118 } 119 120 public static Test suite() throws Exception 121 { 122 return getDeploySetup(IIOPUserTransactionStressTestCase.class, 123 "txiiop.jar"); 124 } 125 126 } 127 | Popular Tags |