1 22 package org.jboss.test.load.test; 23 24 import java.util.Properties ; 25 import java.util.StringTokenizer ; 26 import java.util.Hashtable ; 27 28 import org.jboss.test.JBossTestCase; 29 30 48 public class Client extends JBossTestCase 49 { 50 Properties param = new Properties ();; 51 int exitCode = 0; 52 53 public Client(String name) 54 { 55 super(name); 56 } 57 58 public Client (String [] _args) throws Exception 59 { 60 super("main"); 61 int i = 0; 63 while (i < _args.length) 64 { 65 StringTokenizer st = new StringTokenizer (_args[i++], "="); 66 param.put (st.nextToken (), 67 st.hasMoreTokens () ? st.nextToken () : ""); 68 } 69 70 System.out.println("_____________________________________________"); 71 System.out.println("jBoss, the EJB Open Source Server"); 73 System.out.println("Copyright (C), The jBoss Organization, 2000"); 74 System.out.println("_____________________________________________"); 75 System.out.println("Welcome to the Load Test v0.1"); 77 System.out.println("_____________________________________________"); 78 System.out.println("the following optional parameters are supported:"); 80 System.out.println(" loops=<number> number of test loops per thread"); 81 System.out.println(" beans=<number> number of beans used per thread"); 82 System.out.println(" threads=<number> number of threads getting started"); 83 System.out.println(" delay=<millisec> delay between the thread start"); 84 System.out.println(" verbose - gives infos about bean creation/removing"); 85 System.out.println(" noremove - keeps the created beans after finish"); 86 System.out.println(" nodeploy - does not deploy anything"); 87 System.out.println(" (by default the testbeans.jar from this testsuite"); 88 System.out.println(" is deployed (the test needs the nextgen.EnterpriseEntity)"); 89 System.out.println(" name=<string> name of the threads"); 90 System.out.println("for batch use: in case of any failure it returns != 0"); 91 System.out.println (); 92 93 if (param.get ("nodeploy") == null) 94 { 95 System.out.print("Deploying test beans..."); 96 System.out.flush(); 97 deploy("../deploy/testbean.jar"); 98 System.out.println("done!"); 99 } 100 101 exitCode = test1 (); 102 103 107 System.out.println("Test completed."); 109 System.out.println("Please take the time to report us your results to the " + 110 "jboss-dev@working-dogs.com or jboss-user@working-dogs.com mailing list"); 111 System.out.println(" "); 112 System.out.println(" jBoss version : "); 113 System.out.println(" jBoss configuration : "); 114 System.out.println(" (conf/jboss.jcml) "); 115 System.out.println(" your OS : "); 116 System.out.println(" JDK (vm vendor/version) : "); 117 System.out.println(" DB (product/version) : "); 118 System.out.println(" Database driver (version): "); 119 System.out.println(" "); 120 System.out.println("Thanks in advance!"); 121 System.out.println("note: I guess the testbeans are still deployed."); 123 124 System.exit (exitCode); 125 } 126 127 private int test1 () 128 { 129 Hashtable config = new Hashtable (); 130 131 132 config.put ("verbose", new Boolean (param.getProperty ("verbose") != null)); 133 config.put ("noremove", new Boolean (param.getProperty ("noremove") != null)); 134 135 int beans = 5; 136 try { 137 beans = Integer.parseInt (param.getProperty ("beans")); 138 } catch (Exception _e) { 139 System.out.println("no (or wrong) number of beans (per thread) specified. using default: " + beans); 140 } 141 config.put ("beans", new Integer (beans)); 142 143 int loops = 100; 144 try { 145 loops = Integer.parseInt (param.getProperty ("loops")); 146 } catch (Exception _e){ 147 System.out.println("no (or wrong) number of loops specified. using default: " + loops); 148 } 149 config.put ("loops", new Integer (loops)); 150 151 config.put ("name", param.getProperty ("name", "daniel") ); 152 153 int threads = 50; 154 try { 155 threads = Integer.parseInt (param.getProperty ("threads")); 156 } catch (Exception _e){ 157 System.out.println("no (or wrong) thread number specified. using default: " + threads); 158 } 159 int delay = 1000; 160 try { 161 delay = Integer.parseInt (param.getProperty ("delay")); 162 } catch (Exception _e){ 163 System.out.println("no (or wrong) delay (millisec between each thread start) specified. using default: " + delay); 164 } 165 System.out.println ("start test1 with "+threads+" threads, "+beans+" beans per thread in "+loops+" loops."); 166 System.out.println("------------------------------------------------------"); 167 168 169 ThreadGroup threadGroup = new ThreadGroup ("workers"); 170 Worker[] workers = new Worker[threads]; 171 172 long start = System.currentTimeMillis(); 173 for (int i = 0; i < threads; ++i) 175 { 176 Hashtable cfg = (Hashtable )config.clone (); 177 cfg.put ("number", new Integer (i)); 178 workers[i] = new Worker (threadGroup, cfg); 179 workers[i].start (); 180 try 185 { 186 Thread.currentThread ().sleep (delay); 187 } catch (InterruptedException _ie) 188 { } 190 } 191 192 try 194 { 195 Thread me = Thread.currentThread (); 196 while (threadGroup.activeCount () > 0) 197 me.sleep (5000L); 198 } 199 catch (InterruptedException _ie){ 200 System.out.print ("Main thread interrupted?!"); 201 } 202 long timeSum = (System.currentTimeMillis() - start)/1000L; 203 204 int failed = 0; 206 int tx = 0; 207 for (int i = 0; i < threads; ++i) 208 { 209 Hashtable cfg = workers[i].getConfig (); 210 if (((Boolean )cfg.get("failed")).booleanValue ()) 211 ++failed; 212 213 tx += ((Integer )cfg.get("transactions")).intValue (); 214 } 216 long txps = tx/timeSum; 217 218 219 System.out.println("------------------------------------------------------"); 220 if (failed > 0) 221 { 222 System.out.println("The Test didnt succeed completly :-("); 223 System.out.println("in " + failed + " threads occurred an error."); 224 } 225 else 226 { 227 System.out.println("Congratulations the test succeeded! :-)"); 228 System.out.println("All threads finished clean."); 229 } 230 231 232 long h = timeSum/3600L; 233 long m = (timeSum-h*3600L)/60L; 234 long s = timeSum-h*3600L-m*60L; 235 System.out.println(""); 236 System.out.println("statistic: "+tx+" transactions in "+h+" h "+m+" min "+s+" s."); 237 System.out.println(" transactions per second (average): "+txps); 238 return failed; 239 } 240 241 242 243 public static void main (String [] _args) throws Exception 244 { 245 new Client (_args); 246 } 247 248 249 } 250 | Popular Tags |