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