1 22 package test.performance.standard; 23 24 import junit.framework.TestCase; 25 import test.performance.PerformanceSUITE; 26 import test.performance.standard.support.Standard; 27 28 import javax.management.*; 29 30 import org.jboss.mx.server.ServerConstants; 31 32 39 public class OptimizedInvocationTEST extends TestCase 40 implements ServerConstants 41 { 42 43 public OptimizedInvocationTEST(String s) 44 { 45 super(s); 46 } 47 48 public void testVoidInvocationWithDefaultDomain() 49 { 50 try 51 { 52 System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "true"); 53 54 55 System.out.println("\nSTANDARD (OPTIMIZED): void invocation with DefaultDomain"); 56 System.out.println(PerformanceSUITE.ITERATION_COUNT + " Invocations, Repeat: x" + PerformanceSUITE.REPEAT_COUNT); 57 System.out.println("(this may take a while...)\n"); 58 59 MBeanServer server = MBeanServerFactory.createMBeanServer(); 60 ObjectName name = new ObjectName(":performanceTest=standard"); 61 String method = "methodInvocation"; 62 long start = 0, end = 0; 63 float avg = 0l; 64 65 server.registerMBean(new Standard(), name); 66 67 for (int testIterations = 0; testIterations < PerformanceSUITE.REPEAT_COUNT + 1; ++testIterations) 69 { 70 start = System.currentTimeMillis(); 71 for (int invocationIterations = 0; invocationIterations < PerformanceSUITE.ITERATION_COUNT; ++invocationIterations) 72 { 73 server.invoke(name, method, null, null); 74 } 75 end = System.currentTimeMillis(); 76 77 if (testIterations != 0) 78 { 79 long time = end - start; 80 System.out.print( time + " "); 81 avg += time; 82 } 83 } 84 85 System.out.println("\nAverage: " + (avg/PerformanceSUITE.REPEAT_COUNT)); 86 } 87 catch (Throwable t) 88 { 89 t.printStackTrace(); 90 fail("Unexpected error: " + t.toString()); 91 } 92 finally 93 { 94 System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "false"); 95 } 96 } 97 98 public void testVoidInvocation() 99 { 100 try 101 { 102 System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "true"); 103 104 105 System.out.println("\nSTANDARD (OPTIMIZED): void invocation"); 106 System.out.println(PerformanceSUITE.ITERATION_COUNT + " Invocations, Repeat: x" + PerformanceSUITE.REPEAT_COUNT); 107 System.out.println("(this may take a while...)\n"); 108 109 MBeanServer server = MBeanServerFactory.createMBeanServer(); 110 ObjectName name = new ObjectName("Domain:performanceTest=standard"); 111 String method = "methodInvocation"; 112 long start = 0, end = 0; 113 float avg = 0l; 114 115 server.registerMBean(new Standard(), name); 116 117 for (int testIterations = 0; testIterations < PerformanceSUITE.REPEAT_COUNT + 1; ++testIterations) 119 { 120 start = System.currentTimeMillis(); 121 for (int invocationIterations = 0; invocationIterations < PerformanceSUITE.ITERATION_COUNT; ++invocationIterations) 122 { 123 server.invoke(name, method, null, null); 124 } 125 end = System.currentTimeMillis(); 126 127 if (testIterations != 0) 128 { 129 long time = end - start; 130 System.out.print( time + " "); 131 avg += time; 132 } 133 } 134 135 System.out.println("\nAverage: " + (avg/PerformanceSUITE.REPEAT_COUNT)); 136 } 137 catch (Throwable t) 138 { 139 t.printStackTrace(); 140 fail("Unexpected error: " + t.toString()); 141 } 142 finally 143 { 144 System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "false"); 145 } 146 } 147 148 public void testCounterInvocation() 149 { 150 try 151 { 152 System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "true"); 153 154 155 System.out.println("\nSTANDARD (OPTIMIZED): counter invocation"); 156 System.out.println(PerformanceSUITE.ITERATION_COUNT + " Invocations, Repeat: x" + PerformanceSUITE.REPEAT_COUNT); 157 System.out.println("(this may take a while...)\n"); 158 159 MBeanServer server = MBeanServerFactory.createMBeanServer(); 160 ObjectName name = new ObjectName("Domain:performanceTest=standard"); 161 Standard mbean = new Standard(); 162 String method = "counter"; 163 long start = 0, end = 0; 164 float avg = 0l; 165 166 server.registerMBean(mbean, name); 167 168 for (int testIterations = 0; testIterations < PerformanceSUITE.REPEAT_COUNT + 1; ++testIterations) 170 { 171 start = System.currentTimeMillis(); 172 for (int invocationIterations = 0; invocationIterations < PerformanceSUITE.ITERATION_COUNT; ++invocationIterations) 173 { 174 server.invoke(name, method, null, null); 175 } 176 end = System.currentTimeMillis(); 177 178 if (testIterations != 0) 179 { 180 long time = end - start; 181 System.out.print( time + " "); 182 avg += time; 183 } 184 } 185 186 System.out.println("\nAverage: " + (avg/PerformanceSUITE.REPEAT_COUNT)); 187 188 assertTrue(mbean.getCount() == (PerformanceSUITE.REPEAT_COUNT + 1)*PerformanceSUITE.ITERATION_COUNT); 189 } 190 catch (Throwable t) 191 { 192 t.printStackTrace(); 193 fail("Unexpected error: " + t.toString()); 194 } 195 finally 196 { 197 System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "false"); 198 } 199 } 200 201 202 public void testMixedArgsInvocation() 203 { 204 try 205 { 206 System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "true"); 207 208 System.out.println("\nSTANDARD (OPTIMIZED): mixed arguments invocation"); 209 System.out.println(PerformanceSUITE.ITERATION_COUNT + " Invocations, Repeat: x" + PerformanceSUITE.REPEAT_COUNT); 210 System.out.println("(this may take a while...)\n"); 211 212 MBeanServer server = MBeanServerFactory.createMBeanServer(); 213 ObjectName name = new ObjectName("Domain:performanceTest=standard"); 214 Standard mbean = new Standard(); 215 216 String method = "mixedArguments"; 217 String [] signature = new String [] { 218 Integer .class.getName(), 219 int.class.getName(), 220 Object [][][].class.getName(), 221 Attribute.class.getName() 222 }; 223 224 Object [] args = new Object [] { 225 new Integer (1234), 226 new Integer (455617), 227 new Object [][][] { 228 { 229 { "1x1x1", "1x1x2", "1x1x3" }, 230 { "1x2x1", "1x2x2", "1x2x3" }, 231 { "1x3x1", "1x3x2", "1x3x3" } 232 }, 233 234 { 235 { "2x1x1", "2x1x2", "2x1x3" }, 236 { "2x2x1", "2x2x2", "2x2x3" }, 237 { "2x3x1", "2x3x2", "2x3x3" } 238 }, 239 240 { 241 { "3x1x1", "3x1x2", "3x1x3" }, 242 { "3x2x1", "3x2x2", "3x2x3" }, 243 { "3x3x1", "3x3x2", "3x3x3" } 244 } 245 }, 246 new Attribute("attribute", "value") 247 }; 248 249 long start = 0, end = 0; 250 float avg = 0l; 251 252 server.registerMBean(mbean, name); 253 254 for (int testIterations = 0; testIterations < PerformanceSUITE.REPEAT_COUNT + 1; ++testIterations) 256 { 257 start = System.currentTimeMillis(); 258 for (int invocationIterations = 0; invocationIterations < PerformanceSUITE.ITERATION_COUNT; ++invocationIterations) 259 { 260 server.invoke(name, method, args, signature); 261 } 262 end = System.currentTimeMillis(); 263 264 if (testIterations != 0) 265 { 266 long time = end - start; 267 System.out.print( time + " "); 268 avg += time; 269 } 270 } 271 272 System.out.println("\nAverage: " + (avg/PerformanceSUITE.REPEAT_COUNT)); 273 274 } 275 catch (Throwable t) 276 { 277 t.printStackTrace(); 278 fail("Unexpected error: " + t.toString()); 279 } 280 finally 281 { 282 System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "false"); 283 } 284 285 } 286 287 } 288 | Popular Tags |