1 25 26 package org.objectweb.jonas.jtests.clients.jca15; 27 28 import java.rmi.RemoteException ; 29 30 import javax.naming.NamingException ; 31 import javax.rmi.PortableRemoteObject ; 32 33 import junit.framework.Test; 34 import junit.framework.TestSuite; 35 36 import org.objectweb.jonas.jtests.beans.worker.Worker; 37 import org.objectweb.jonas.jtests.beans.worker.WorkerHome; 38 import org.objectweb.jonas.jtests.util.JTestCase; 39 40 41 public class F_Worker extends JTestCase { 42 43 private static String BEAN_HOME = "workerHome"; 44 private static WorkerHome home = null; 45 46 public F_Worker(String name) { 47 super(name); 48 } 49 50 public WorkerHome getHome() { 51 if (home == null) { 52 try { 53 home = (WorkerHome) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME), WorkerHome.class); 54 } catch (NamingException e) { 55 fail("Cannot get bean home"); 56 } 57 } 58 return home; 59 } 60 61 protected void setUp() { 62 super.setUp(); 63 useBeans("worker", false); 64 } 65 66 public void testDoWorkTx() throws Exception { 67 Worker w = getHome().create(); 68 int count = 1; 69 w.doWorkInTx(); 70 assertEquals("count", count, w.getwcount()); 71 w.remove(); 72 } 73 74 public void testStartWorkTx() throws Exception { 75 Worker w = getHome().create(); 76 int count = 1; 77 w.startWorkInTx(); 78 assertEquals("count", count, w.getwcount()); 79 w.remove(); 80 } 81 82 public void testScheduleWorkTx() throws Exception { 83 Worker w = getHome().create(); 84 int count = 1; 85 w.scheduleWorkInTx(); 86 assertEquals("count", count, w.getwcount()); 87 w.remove(); 88 } 89 90 public void testDoWorkBasic() throws Exception { 91 Worker w = getHome().create(); 92 int count = 1; 93 w.doWorks(count); 94 assertEquals("count", count, w.getwcount()); 95 w.remove(); 96 } 97 98 public void testDo20Works() throws Exception { 99 Worker w = getHome().create(); 100 int count = 20; 101 w.doWorks(count); 102 assertEquals("count", count, w.getwcount()); 103 w.remove(); 104 } 105 106 public void testStartWorkBasic() throws Exception { 107 Worker w = getHome().create(); 108 int count = 1; 109 w.startWorks(count); 110 sleep(500); 111 assertEquals("count", count, w.getwcount()); 112 w.remove(); 113 } 114 115 public void testStart20Works() throws Exception { 116 Worker w = getHome().create(); 117 int count = 20; 118 w.startWorks(count); 119 sleep(2000); 120 assertEquals("count", count, w.getwcount()); 121 w.remove(); 122 } 123 124 public void testScheduleWorkBasic() throws Exception { 125 Worker w = getHome().create(); 126 int count = 1; 127 w.scheduleWorks(count, 20000); 128 sleep(500); 129 assertEquals("count", count, w.getwcount()); 130 assertEquals("accepted", count, w.getNotifyAccepted()); 131 assertEquals("started", count, w.getNotifyStarted()); 132 assertEquals("rejected", 0, w.getNotifyRejected()); 133 assertEquals("completed", count, w.getNotifyCompleted()); 134 w.remove(); 135 } 136 137 public void testScheduleWorkTimedout() throws Exception { 138 Worker w = getHome().create(); 139 int count = 1; 140 w.scheduleWorks(count, 1L); 141 sleep(500); 142 assertEquals("count", 0, w.getwcount()); 143 assertEquals("accepted", count, w.getNotifyAccepted()); 144 assertEquals("started", 0, w.getNotifyStarted()); 145 assertEquals("rejected", count, w.getNotifyRejected()); 146 assertEquals("completed", 0, w.getNotifyCompleted()); 147 w.remove(); 148 } 149 150 public void testSchedule20Works() throws Exception { 151 Worker w = getHome().create(); 152 int count = 20; 153 w.scheduleWorks(count, 20000); 154 sleep(2000); 155 assertEquals("count", count, w.getwcount()); 156 assertEquals("accepted", count, w.getNotifyAccepted()); 157 assertEquals("started", count, w.getNotifyStarted()); 158 assertEquals("rejected", 0, w.getNotifyRejected()); 159 assertEquals("completed", count, w.getNotifyCompleted()); 160 w.remove(); 161 } 162 163 public static Test suite() { 164 return new TestSuite(F_Worker.class); 165 } 166 167 public static void main (String args[]) { 168 String testtorun = null; 169 for (int argn = 0; argn < args.length; argn++) { 171 String s_arg = args[argn]; 172 Integer i_arg; 173 if (s_arg.equals("-n")) { 174 testtorun = args[++argn]; 175 } 176 } 177 if (testtorun == null) { 178 junit.textui.TestRunner.run(suite()); 179 } else { 180 junit.textui.TestRunner.run(new F_Worker(testtorun)); 181 } 182 } 183 } 184 185 | Popular Tags |