1 22 package org.jboss.test.session.test; 23 24 import java.rmi.RemoteException ; 25 26 import junit.framework.Test; 27 import junit.framework.TestSuite; 28 29 import org.jboss.test.JBossTestCase; 30 import org.jboss.test.session.interfaces.CountedSession; 31 import org.jboss.test.session.interfaces.CountedSessionHome; 32 import org.jboss.test.session.interfaces.CounterSession; 33 import org.jboss.test.session.interfaces.CounterSessionHome; 34 35 41 public class EjbRemoveUnitTestCase extends JBossTestCase 42 { 43 public static Test suite() throws Exception 44 { 45 TestSuite suite = new TestSuite(); 48 suite.addTest(new EjbRemoveUnitTestCase("testEjbRemoveCalledForEveryCall")); 49 suite.addTest(new EjbRemoveUnitTestCase("testEjbRemoveNotCalledForEveryCall")); 50 suite.addTest(new EjbRemoveUnitTestCase("testEjbRemoveMultiThread")); 51 52 return JBossTestCase.getDeploySetup(suite, "test-session-remove.jar"); 53 } 54 55 public EjbRemoveUnitTestCase(String name) 56 { 57 super(name); 58 } 59 60 67 public void testEjbRemoveCalledForEveryCall() throws Exception 68 { 69 CounterSessionHome counterHome = (CounterSessionHome)getInitialContext().lookup("CounterSession"); 70 CountedSessionHome countedHome = (CountedSessionHome)getInitialContext().lookup("CountedSession"); 71 72 CounterSession counter = counterHome.create(); 73 counter.clearCounters(); 74 75 CountedSession counted = countedHome.create(); 76 assertEquals("createCounter", 1, counter.getCreateCounter()); 77 assertEquals("removeCounter", 1, counter.getRemoveCounter()); 78 79 counted.doSomething(0); 80 assertEquals("createCounter", 2, counter.getCreateCounter()); 81 assertEquals("removeCounter", 2, counter.getRemoveCounter()); 82 83 counted.remove(); 84 assertEquals("createCounter", 3, counter.getCreateCounter()); 85 assertEquals("removeCounter", 3, counter.getRemoveCounter()); 86 } 87 88 94 public void testEjbRemoveNotCalledForEveryCall() throws Exception 95 { 96 CounterSessionHome counterHome = (CounterSessionHome)getInitialContext().lookup("CounterSession"); 97 CountedSessionHome countedHome = (CountedSessionHome)getInitialContext().lookup("CountedSession2"); 98 99 CounterSession counter = counterHome.create(); 100 counter.clearCounters(); 101 102 CountedSession counted = countedHome.create(); 103 assertEquals("createCounter", 1, counter.getCreateCounter()); 104 assertEquals("removeCounter", 0, counter.getRemoveCounter()); 105 106 counted.doSomething(0); 107 assertEquals("createCounter", 1, counter.getCreateCounter()); 108 assertEquals("removeCounter", 0, counter.getRemoveCounter()); 109 110 counted.remove(); 111 assertEquals("createCounter", 1, counter.getCreateCounter()); 112 assertEquals("removeCounter", 0, counter.getRemoveCounter()); 113 } 114 115 public void testEjbRemoveMultiThread() throws Exception 116 { 117 CounterSessionHome counterHome = (CounterSessionHome)getInitialContext().lookup("CounterSession"); 118 CountedSessionHome countedHome = (CountedSessionHome)getInitialContext().lookup("CountedSession2"); 119 120 CounterSession counter = counterHome.create(); 121 counter.clearCounters(); 122 123 final CountedSession counted = countedHome.create(); 124 125 Runnable runnable = new Runnable () { 126 public void run() 127 { 128 try 129 { 130 counted.doSomething(1000); 132 } 133 catch (RemoteException e) 134 { 135 } 137 } 138 }; 139 140 for (int i = 0; i < 10; i++) 141 { 142 new Thread (runnable).start(); 143 } 144 145 151 Thread.sleep(2000); 153 154 assertTrue("createCounter >= 5", counter.getCreateCounter() >= 5); 155 assertTrue("removeCounter == 5", counter.getRemoveCounter() == 5); 156 } 157 } 158 | Popular Tags |