1 22 package org.jboss.harness; 23 24 import java.io.InputStream ; 25 import java.util.Properties ; 26 27 import EDU.oswego.cs.dl.util.concurrent.CopyOnWriteArrayList; 28 import com.cluster.simple.sessionbeans.SimpleSessionHome; 29 30 38 public class JNDITestHarness 39 { 40 41 public static void main(String [] args) 42 { 43 int iterations = 10; 44 int numOfClients = 10; 45 boolean printLookupTime = false; 46 47 if (args.length > 0) 48 { 49 iterations = Integer.parseInt(args[0]); 50 } 51 if (args.length > 1) 52 { 53 numOfClients = Integer.parseInt(args[1]); 54 } 55 if (args.length > 2) 56 { 57 printLookupTime = Boolean.valueOf(args[2]).booleanValue(); 58 } 59 60 JNDITestHarness test = new JNDITestHarness(); 61 try 62 { 63 System.out.println("JNDITestHarness properties"); 64 Properties props = test.getPropAsResource(TestClient.SIMPLE_CONFIG_SERVER_PROP); 65 props.list(System.out); 66 } 67 catch (Exception e) 68 { 69 System.out.println(e); 70 } 71 test.runTest(iterations, numOfClients, printLookupTime); 72 } 73 74 private void runTest(final int iterations, int numOfClients, final boolean printTime) 75 { 76 final CopyOnWriteArrayList timesList = new CopyOnWriteArrayList(); 77 final Counter counter = new Counter(); 78 long start = System.currentTimeMillis(); 79 80 System.out.println("Starting run now with " + numOfClients + " clients and " + iterations + " iterations."); 81 82 for (int x = 0; x < numOfClients; x++) 83 { 84 new Thread () 85 { 86 public void run() 87 { 88 try 89 { 90 for (int i = 0; i < iterations; i++) 91 { 92 long startTime = System.currentTimeMillis(); 93 TestClient client = new TestClient(); 94 client.lookup("SimpleSession", SimpleSessionHome.class); 95 long endTime = System.currentTimeMillis(); 96 timesList.add(new Long (endTime - startTime)); 97 if (printTime) 98 System.out.println(endTime - startTime); 99 counter.increment(); 100 long value = counter.getValue(); 101 if (value % 10000 == 0) 102 { 103 System.out.println("Executed " + value + " times so far."); 104 } 105 106 } 107 } 108 catch (Exception e) 109 { 110 System.out.println("Error calling test client to do jndi lookup"); 111 e.printStackTrace(); 112 } 113 } 114 }.start(); 115 } 116 117 118 while (timesList.size() < (iterations * numOfClients)) 119 { 120 try 121 { 122 Thread.sleep(1000); 123 } 124 catch (InterruptedException e) 125 { 126 e.printStackTrace(); } 128 } 129 130 long end = System.currentTimeMillis(); 131 132 System.out.println("Ran test with total of " + timesList.size() + " (iterations: " + iterations + 133 ", number of clients: " + numOfClients + ") in " + (end - start) / 1000 + " seconds."); 134 135 long total = 0; 136 for (int i = 0; i < timesList.size(); i++) 137 { 138 total += ((Long ) timesList.get(i)).longValue(); 139 } 140 141 System.out.println("Average time to make lookup is " + (total / (iterations * numOfClients)) + " milliseconds."); 142 143 145 } 146 147 public Properties getPropAsResource(String name) throws Exception 148 { 149 InputStream is = getClass().getResourceAsStream("/META-INF/" + name); 150 if (is == null) 151 { 152 throw new Exception ("Unable to locate resource: " + name); 153 } 154 Properties confProp = new Properties (); 155 confProp.load(is); 156 return confProp; 157 } 158 159 public class Counter 160 { 161 private long count = 0; 162 163 public void increment() 164 { 165 count++; 166 } 167 168 public void decrement() 169 { 170 count--; 171 } 172 173 public long getValue() 174 { 175 return count; 176 } 177 } 178 179 } 180 | Popular Tags |