1 7 package org.jboss.remoting.performance.standard; 8 9 import org.apache.log4j.Level; 10 import org.jboss.dtf.MultipleTestRunner; 11 import org.jboss.remoting.oneway.OnewayInvokerClientTest; 12 import org.jboss.remoting.performance.PerformanceReporter; 13 import org.jboss.remoting.performance.PerformanceTest; 14 15 import java.util.HashMap ; 16 import java.util.Map ; 17 18 23 public class StandardTest extends OnewayInvokerClientTest 24 { 25 26 private final Object waitObj = new Object (); 27 private int callCount = 0; 28 29 public StandardTest(String name) 30 { 31 super(name); 32 } 33 34 public StandardTest(int numberOfInstances) 35 { 36 super(numberOfInstances); 37 } 38 39 public StandardTest(String transport, int port) 40 { 41 super(transport, port); 42 } 43 44 public StandardTest(String transport, int port, int numberOfInstances) 45 { 46 super(transport, port, numberOfInstances); 47 } 48 49 protected int incrementCallCount() 50 { 51 int currentCount = callCount++; 52 if((currentCount % 100) == 0) 53 { 54 System.out.println("call count: " + currentCount); 55 } 56 if(callCount == (PerformanceTest.NUM_OF_THREADS * PerformanceTest.NUM_OF_CALLS)) 57 { 58 synchronized(waitObj) 59 { 60 waitObj.notify(); 61 } 62 } 63 return currentCount; 64 } 65 66 protected void setCallCount(int count) 67 { 68 this.callCount = count; 69 } 70 71 91 protected Object superMakeClientInvocation(String method, String param) throws Throwable 92 { 93 return super.makeInvocation(method, param); 94 } 95 96 protected Object makeClientInvocation(String method, String param) throws Throwable 98 { 99 callCount = 0; 100 101 sendTotalCount(); 102 103 printStartMessage(); 104 105 long startTime = System.currentTimeMillis(); 106 107 System.out.println("Start time: " + startTime); 108 109 for(int x = 0; x < PerformanceTest.NUM_OF_THREADS; x++) 110 { 111 if((PerformanceTest.NUM_OF_THREADS % 10) == 0) 112 { 113 System.out.println("started " + x + " threads"); 114 } 115 new Thread (getRunner(method)).start(); 116 } 117 118 synchronized(waitObj) 119 { 120 try 121 { 122 waitObj.wait(5 * 60 * 1000); } 124 catch(InterruptedException e) 125 { 126 127 } 128 } 129 130 long endTime = System.currentTimeMillis(); 131 132 System.out.println("End time: " + endTime); 133 System.out.println("Total number of calls: " + callCount); 134 long totalTime = endTime - startTime; 135 System.out.println("Total time: " + totalTime); 136 137 int svrTotalCount = getServerTotalCount(); 138 139 System.out.println("Server total count: " + svrTotalCount); 140 assertEquals(callCount, svrTotalCount); 141 142 Map metadata = new HashMap (); 143 metadata.put("transport", getTransport()); 144 metadata.put("server total count", String.valueOf(svrTotalCount)); 145 metadata.put("number of client threads", String.valueOf(PerformanceTest.NUM_OF_THREADS)); 146 metadata.put("number of client calls per thread", String.valueOf(PerformanceTest.NUM_OF_CALLS)); 147 148 149 PerformanceReporter.writeReport(this.getClass().getName() + "::" + method, 150 totalTime, callCount, metadata); 151 152 return null; 153 } 154 155 protected void checkAssertion(String param, Object obj) 156 { 157 } 159 160 161 private int getServerTotalCount() 162 { 163 int svrCount = 0; 164 165 try 166 { 167 Object ret = makeInvocation("serverTotalCallCount", null); 168 if(ret != null && ret instanceof String ) 169 { 170 svrCount = Integer.parseInt((String ) ret); 171 } 172 } 173 catch(Throwable throwable) 174 { 175 throwable.printStackTrace(); 176 } 177 return svrCount; 178 } 179 180 protected void printStartMessage() 181 { 182 System.out.println("\n*****************************************************\n" + 183 "Starting standard preformance test with client.\n" + 184 "*****************************************************\n"); 185 } 186 187 190 private void sendTotalCount() throws Throwable 191 { 192 makeInvocation("totalCallCount", String.valueOf(PerformanceTest.NUM_OF_CALLS * PerformanceTest.NUM_OF_THREADS)); 193 } 194 195 protected Runnable getRunner(String method) 196 { 197 return new ClientRunner(method); 198 } 199 200 public void testOnewayServerInvocation() throws Throwable 201 { 202 } 204 205 public void testOnewayClientInvocation() throws Throwable 206 { 207 } 209 210 211 public class ClientRunner implements Runnable 212 { 213 private String method; 214 215 public ClientRunner(String method) 216 { 217 this.method = method; 218 } 219 220 public void run() 221 { 222 for(int i = 0; i < PerformanceTest.NUM_OF_CALLS; i++) 223 { 224 try 225 { 226 superMakeClientInvocation(this.method, String.valueOf(incrementCallCount())); 227 } 228 catch(Throwable throwable) 229 { 230 throwable.printStackTrace(); 231 } 232 } 233 } 234 235 } 236 237 public static void main(String [] args) 238 { 239 240 org.apache.log4j.BasicConfigurator.configure(); 241 org.apache.log4j.Category.getRoot().setLevel(Level.INFO); 242 org.apache.log4j.Category.getInstance("org.jgroups").setLevel(Level.INFO); 243 246 StandardTest client = null; 247 if(args.length == 1) 248 { 249 int instances = Integer.parseInt(args[0]); 250 client = new StandardTest(instances); 251 } 252 else if(args.length == 2) 253 { 254 String transport = args[0]; 255 int port = Integer.parseInt(args[1]); 256 client = new StandardTest(transport, port); 257 } 258 else if(args.length == 3) 259 { 260 String transport = args[0]; 261 int port = Integer.parseInt(args[1]); 262 int instances = Integer.parseInt(args[2]); 263 client = new StandardTest(transport, port, instances); 264 } 265 else 266 { 267 client = new StandardTest(OnewayInvokerClientTest.class.getName()); 268 System.out.println("Using default transport (" + client.getTransport() + 269 ") and default port (" + client.getPort() + ") and " + 270 "default number of instances (" + client.getNumberOfInstances() + ")" + 271 "\nCan enter transport, port, and instances via command line."); 272 } 273 274 try 275 { 276 MultipleTestRunner runner = new MultipleTestRunner(); 279 runner.doRun(client, true); 280 } 281 catch(Throwable e) 282 { 283 e.printStackTrace(); 284 System.exit(1); 285 } 286 System.exit(0); 287 } 288 289 290 } | Popular Tags |