1 22 package org.jboss.ejb3.test.cache.unit; 23 24 import javax.management.MBeanServerConnection ; 25 import javax.management.ObjectName ; 26 import org.jboss.ejb3.test.cache.SimpleStatefulRemote; 27 import org.jboss.ejb3.test.cache.StatefulRemote; 28 import org.jboss.test.JBossTestCase; 29 import junit.framework.Test; 30 31 37 38 public class StatefulUnitTestCase 39 extends JBossTestCase 40 { 41 org.jboss.logging.Logger log = getLog(); 42 43 static boolean deployed = false; 44 static int test = 0; 45 46 public StatefulUnitTestCase(String name) 47 { 48 49 super(name); 50 51 } 52 53 public void testStateful() throws Exception ![JavaDoc](../../../../../../../cmn/javadoc.gif) 54 { 55 StatefulRemote remote = (StatefulRemote) getInitialContext().lookup("StatefulBean/remote"); 56 remote.reset(); 57 remote.setState("hello"); 58 Thread.sleep(11000); 59 assertEquals("hello", remote.getState()); 60 assertTrue(remote.getPostActivate()); 61 assertTrue(remote.getPrePassivate()); 62 remote.done(); } 64 65 public void testStatefulLongRunning() throws Exception ![JavaDoc](../../../../../../../cmn/javadoc.gif) 66 { 67 StatefulRemote remote = (StatefulRemote) getInitialContext().lookup("StatefulBean/remote"); 68 remote.reset(); 69 remote.setState("hello"); 70 remote.longRunning(); 71 assertFalse(remote.getPrePassivate()); 73 Thread.sleep(11000); 74 assertEquals("hello", remote.getState()); 76 assertTrue(remote.getPostActivate()); 77 assertTrue(remote.getPrePassivate()); 78 remote.done(); } 80 81 public void testSimpleStatefulLongRunning() throws Exception ![JavaDoc](../../../../../../../cmn/javadoc.gif) 82 { 83 SimpleStatefulRemote remote = (SimpleStatefulRemote) getInitialContext().lookup("SimpleStatefulBean/remote"); 84 remote.reset(); 85 remote.setState("hello"); 86 remote.longRunning(); 87 assertEquals("hello", remote.getState()); 88 assertTrue(remote.getPostActivate()); 89 assertTrue(remote.getPrePassivate()); 90 } 91 92 public void testSimpleStateful() throws Exception ![JavaDoc](../../../../../../../cmn/javadoc.gif) 93 { 94 SimpleStatefulRemote remote = (SimpleStatefulRemote) getInitialContext().lookup("SimpleStatefulBean/remote"); 95 remote.reset(); 96 remote.setState("hello"); 97 Thread.sleep(5000); 98 assertEquals("hello", remote.getState()); 99 assertTrue(remote.getPostActivate()); 100 assertTrue(remote.getPrePassivate()); 101 } 102 103 public void testSimpleLocal() throws Exception ![JavaDoc](../../../../../../../cmn/javadoc.gif) 104 { 105 MBeanServerConnection server = getServer(); 106 ObjectName testerName = new ObjectName ("jboss.ejb3:service=Tester,test=cache"); 107 Object [] params = {}; 108 String [] sig = {}; 109 server.invoke(testerName, "testSimpleLocal", params, sig); 110 } 111 112 public void testBench() throws Exception ![JavaDoc](../../../../../../../cmn/javadoc.gif) 113 { 114 StatefulRemote remote = (StatefulRemote) getInitialContext().lookup("StatefulBean/remote"); 115 System.out.println("bench: " + remote.bench(1000)); 116 remote.done(); } 118 119 public void testBenchSimple() throws Exception ![JavaDoc](../../../../../../../cmn/javadoc.gif) 120 { 121 SimpleStatefulRemote remote = (SimpleStatefulRemote) getInitialContext().lookup("SimpleStatefulBean/remote"); 122 System.out.println("simple bench: " + remote.bench(1000)); 123 124 } 125 126 public static Test suite() throws Exception ![JavaDoc](../../../../../../../cmn/javadoc.gif) 127 { 128 return getDeploySetup(StatefulUnitTestCase.class, "testejb3-statefulcache-service.xml, cache-test.jar, cache-test.sar"); 129 } 130 131 } 132 | Popular Tags |