1 22 package org.jboss.harness; 23 24 import EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArrayList; 25 26 29 public class EJBTestHarness 30 { 31 public static void main(String [] args) 32 { 33 int iterations = 10; 34 int numOfClients = 10; 35 boolean printLookupTime = false; 36 String jndiURL = ""; 37 if (args.length > 0) 38 { 39 iterations = Integer.parseInt(args[0]); 40 } 41 if (args.length > 1) 42 { 43 numOfClients = Integer.parseInt(args[1]); 44 } 45 if (args.length > 2) 46 { 47 printLookupTime = Boolean.valueOf(args[2]).booleanValue(); 48 } 49 if (args.length > 3) 50 { 51 jndiURL = args[3]; 52 } 53 54 EJBTestHarness test = new EJBTestHarness(); 55 test.runTest(iterations, numOfClients, jndiURL, printLookupTime); 56 } 57 58 private void runTest(final int iterations, int numOfClients, final String jndiURL, final boolean printTime) 59 { 60 final CopyOnWriteArrayList timesList = new CopyOnWriteArrayList(); 61 final Counter counter = new Counter(); 62 long start = System.currentTimeMillis(); 63 64 System.out.println("Starting run now with " + numOfClients + " clients and " + iterations + " iterations."); 65 66 for (int x = 0; x < numOfClients; x++) 67 { 68 new Thread () 69 { 70 public void run() 71 { 72 try 73 { 74 for (int i = 0; i < iterations; i++) 75 { 76 long startTime = System.currentTimeMillis(); 77 EJBTestClient client = new EJBTestClient(); 78 client.execute(jndiURL); 79 long endTime = System.currentTimeMillis(); 80 timesList.add(new Long (endTime - startTime)); 81 if (printTime) 82 System.out.println(endTime - startTime); 83 counter.increment(); 84 long value = counter.getValue(); 85 if (value % 10000 == 0) 86 { 87 System.out.println("Executed " + value + " times so far."); 88 } 89 90 } 91 } 92 catch (Exception e) 93 { 94 System.out.println("Error calling test client to do jndi lookup"); 95 e.printStackTrace(); 96 } 97 } 98 }.start(); 99 } 100 101 102 while (timesList.size() < (iterations * numOfClients)) 103 { 104 try 105 { 106 Thread.sleep(1000); 107 } 108 catch (InterruptedException e) 109 { 110 e.printStackTrace(); } 112 } 113 114 long end = System.currentTimeMillis(); 115 116 System.out.println("Ran test with total of " + timesList.size() + " (iterations: " + iterations + 117 ", number of clients: " + numOfClients + ") in " + (end - start) / 1000 + " seconds."); 118 119 long total = 0; 120 for (int i = 0; i < timesList.size(); i++) 121 { 122 total += ((Long ) timesList.get(i)).longValue(); 123 } 124 125 System.out.println("Average time to make lookup is " + (total / (iterations * numOfClients)) + " milliseconds."); 126 127 129 } 130 131 public class Counter 132 { 133 private long count = 0; 134 135 public void increment() 136 { 137 count++; 138 } 139 140 public void decrement() 141 { 142 count--; 143 } 144 145 public long getValue() 146 { 147 return count; 148 } 149 } 150 151 } 152 | Popular Tags |