1 7 package org.jboss.remoting.performance.oneway; 8 9 import org.jboss.remoting.oneway.OnewayInvokerClientTest; 10 import org.jboss.remoting.performance.PerformanceReporter; 11 import org.jboss.remoting.performance.PerformanceTest; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 21 public abstract class OnewayTest extends OnewayInvokerClientTest 22 { 23 private final Object waitObj = new Object (); 24 private int callCount = 0; 25 26 public OnewayTest(String name) 27 { 28 super(name); 29 } 30 31 public OnewayTest(int numberOfInstances) 32 { 33 super(numberOfInstances); 34 } 35 36 public OnewayTest(String transport, int port) 37 { 38 super(transport, port); 39 } 40 41 public OnewayTest(String transport, int port, int numberOfInstances) 42 { 43 super(transport, port, numberOfInstances); 44 } 45 46 protected int incrementCallCount() 47 { 48 int currentCount = callCount++; 49 if((currentCount % 100) == 0) 50 { 51 System.out.println("call count: " + currentCount); 52 } 53 if(callCount == (PerformanceTest.NUM_OF_THREADS * PerformanceTest.NUM_OF_CALLS)) 54 { 55 synchronized(waitObj) 56 { 57 waitObj.notify(); 58 } 59 } 60 return currentCount; 61 } 62 63 protected void setCallCount(int count) 64 { 65 this.callCount = count; 66 } 67 68 protected void makeClientOnewayInvocation(String method, String param) throws Throwable 69 { 70 makeOnewayInvocation(method, param); 71 } 72 73 protected void makeServerOnewayInvocation(String method, String param) throws Throwable 74 { 75 makeOnewayInvocation(method, param); 76 } 77 78 protected void superMakeClientOnewayInvocation(String method, String param) throws Throwable 79 { 80 super.makeClientOnewayInvocation(method, param); 81 } 82 83 protected void superMakeServerOnewayInvocation(String method, String param) throws Throwable 84 { 85 super.makeServerOnewayInvocation(method, param); 86 } 87 88 protected void makeOnewayInvocation(String method, String param) throws Throwable 89 { 90 callCount = 0; 91 92 sendTotalCount(); 93 94 printStartMessage(); 95 96 long startTime = System.currentTimeMillis(); 97 98 System.out.println("Start time: " + startTime); 99 100 for(int x = 0; x < PerformanceTest.NUM_OF_THREADS; x++) 101 { 102 if((PerformanceTest.NUM_OF_THREADS % 10) == 0) 103 { 104 System.out.println("started " + x + " threads"); 105 } 106 new Thread (getRunner(method), "Test thread " + x).start(); 107 } 108 109 synchronized(waitObj) 110 { 111 try 112 { 113 waitObj.wait(5 * 60 * 1000); } 115 catch(InterruptedException e) 116 { 117 118 } 119 } 120 121 long endTime = System.currentTimeMillis(); 122 123 System.out.println("End time: " + endTime); 124 System.out.println("Total number of calls: " + callCount); 125 long totalTime = endTime - startTime; 126 System.out.println("Total time: " + totalTime); 127 128 Thread.currentThread().sleep(5000); 129 130 int svrTotalCount = getServerTotalCount(); 131 132 System.out.println("Server total count: " + svrTotalCount); 133 assertEquals(callCount, svrTotalCount); 134 135 Map metadata = new HashMap (); 136 metadata.put("transport", getTransport()); 137 metadata.put("server total count", String.valueOf(svrTotalCount)); 138 metadata.put("number of client threads", String.valueOf(PerformanceTest.NUM_OF_THREADS)); 139 metadata.put("number of client calls per thread", String.valueOf(PerformanceTest.NUM_OF_CALLS)); 140 141 PerformanceReporter.writeReport(this.getClass().getName() + "::" + method, 142 totalTime, callCount, metadata); 143 } 144 145 protected void checkAssertion(String param, Object obj) 146 { 147 } 149 150 151 private int getServerTotalCount() 152 { 153 int svrCount = 0; 154 155 try 156 { 157 Object ret = makeInvocation("serverTotalCallCount", null); 158 if(ret != null && ret instanceof String ) 159 { 160 svrCount = Integer.parseInt((String ) ret); 161 } 162 } 163 catch(Throwable throwable) 164 { 165 throwable.printStackTrace(); 166 } 167 return svrCount; 168 } 169 170 protected abstract Runnable getRunner(String method); 171 172 protected abstract void printStartMessage(); 173 174 177 private void sendTotalCount() throws Throwable 178 { 179 makeInvocation("totalCallCount", String.valueOf(PerformanceTest.NUM_OF_CALLS * PerformanceTest.NUM_OF_THREADS)); 180 } 181 182 } | Popular Tags |