1 25 26 package org.objectweb.jonas.jtests.clients.distribution; 27 28 29 import javax.naming.NamingException ; 30 import javax.rmi.PortableRemoteObject ; 31 32 import junit.framework.Test; 33 import junit.framework.TestSuite; 34 35 import org.objectweb.jonas.jtests.beans.sequence.WoSes; 36 import org.objectweb.jonas.jtests.beans.sequence.WoSesHome; 37 import org.objectweb.jonas.jtests.beans.sequence.SequenceSesHome; 38 import org.objectweb.jonas.jtests.util.JTestCase; 39 40 41 42 46 47 50 class B_thread extends Thread { 51 WoSesHome home; 52 int loops; 53 54 public B_thread(WoSesHome home, int loops) { 55 this.home = home; 56 this.loops = loops; 57 } 58 59 public void run() { 60 try { 61 WoSes wos = home.create(); 62 for (int i = 0; i < loops; i++) { 63 wos.schedule(Thread.currentThread().getName(),i); 64 } 65 wos.remove(); 66 } catch(Exception e) { 67 e.printStackTrace(); 68 } 69 } 70 71 } 72 73 public class F_Sequence extends JTestCase { 74 75 protected static WoSesHome woseshome = null; 76 77 78 public F_Sequence(String name) { 79 super(name); 80 } 81 82 protected void setUp() { 83 super.setUp(); 84 if (woseshome == null) { 85 useBeans("sequence", true); 88 try { 89 woseshome= (WoSesHome ) PortableRemoteObject.narrow(ictx.lookup("WoSesHome"), WoSesHome.class); 90 assertNotNull("home of clusterId_1 is null", woseshome); 91 } catch (NamingException e) { 92 fail("Cannot get bean home: " + e.getMessage()); 93 } 94 } 95 } 96 97 protected void tearDown() throws Exception { 98 super.tearDown(); 99 } 100 101 107 public void multiThreadTest(int threads, int loops) throws Exception { 108 109 B_thread[] t_thr = new B_thread[threads]; 111 for (int i = 0; i < threads; i++) { 112 t_thr[i] = new B_thread(woseshome, loops); 113 } 114 for (int i = 0; i < threads; i++) { 115 t_thr[i].start(); 116 } 117 for (int p = 0; p < threads; p++) { 119 t_thr[p].join(); 120 } 121 122 } 123 124 public void testTh20L10() throws Exception { 125 multiThreadTest(20, 10); 126 } 127 128 public void testTh2L100() throws Exception { 129 multiThreadTest(2, 100); 130 } 131 132 public void testTh3L1() throws Exception { 133 multiThreadTest(3, 1); 134 } 135 136 137 public void testTh5L10() throws Exception { 138 multiThreadTest(5, 10); 139 } 140 141 public void testTh1L2() throws Exception { 142 multiThreadTest(1, 2); 143 } 144 145 146 public void testTh10L10() throws Exception { 147 multiThreadTest(10, 10); 148 } 149 150 151 152 public void testTh50L1() throws Exception { 153 multiThreadTest(50, 1); 154 } 155 156 157 public static Test suite() { 158 return new TestSuite(F_Sequence.class); 159 } 160 161 public static void main (String args[]) { 162 String testtorun = null; 163 for (int argn = 0; argn < args.length; argn++) { 165 String s_arg = args[argn]; 166 Integer i_arg; 167 if (s_arg.equals("-n")) { 168 testtorun = args[++argn]; 169 } 170 } 171 if (testtorun == null) { 172 junit.textui.TestRunner.run(suite()); 173 } else { 174 junit.textui.TestRunner.run(new F_Sequence(testtorun)); 175 } 176 } 177 } 178 | Popular Tags |