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 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("\nSTANDARD: 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=standard"); 49 String method = "methodInvocation"; 50 long start = 0, end = 0; 51 float avg = 0l; 52 53 server.registerMBean(new Standard(), 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 } 75 catch (Throwable t) 76 { 77 t.printStackTrace(); 78 fail("Unexpected error: " + t.toString()); 79 } 80 } 81 82 public void testVoidInvocation() 83 { 84 try 85 { 86 System.out.println("\nSTANDARD: void invocation"); 87 System.out.println(PerformanceSUITE.ITERATION_COUNT + " Invocations, Repeat: x" + PerformanceSUITE.REPEAT_COUNT); 88 System.out.println("(this may take a while...)\n"); 89 90 MBeanServer server = MBeanServerFactory.createMBeanServer(); 91 ObjectName name = new ObjectName("Domain:performanceTest=standard"); 92 String method = "methodInvocation"; 93 long start = 0, end = 0; 94 float avg = 0l; 95 96 server.registerMBean(new Standard(), name); 97 98 for (int testIterations = 0; testIterations < PerformanceSUITE.REPEAT_COUNT + 1; ++testIterations) 100 { 101 start = System.currentTimeMillis(); 102 for (int invocationIterations = 0; invocationIterations < PerformanceSUITE.ITERATION_COUNT; ++invocationIterations) 103 { 104 server.invoke(name, method, null, null); 105 } 106 end = System.currentTimeMillis(); 107 108 if (testIterations != 0) 109 { 110 long time = end - start; 111 System.out.print( time + " "); 112 avg += time; 113 } 114 } 115 116 System.out.println("\nAverage: " + (avg/PerformanceSUITE.REPEAT_COUNT)); 117 } 118 catch (Throwable t) 119 { 120 t.printStackTrace(); 121 fail("Unexpected error: " + t.toString()); 122 } 123 } 124 125 public void testCounterInvocation() 126 { 127 try 128 { 129 System.out.println("\nSTANDARD: counter invocation"); 130 System.out.println(PerformanceSUITE.ITERATION_COUNT + " Invocations, Repeat: x" + PerformanceSUITE.REPEAT_COUNT); 131 System.out.println("(this may take a while...)\n"); 132 133 MBeanServer server = MBeanServerFactory.createMBeanServer(); 134 ObjectName name = new ObjectName("Domain:performanceTest=standard"); 135 Standard mbean = new Standard(); 136 String method = "counter"; 137 long start = 0, end = 0; 138 float avg = 0l; 139 140 server.registerMBean(mbean, name); 141 142 for (int testIterations = 0; testIterations < PerformanceSUITE.REPEAT_COUNT + 1; ++testIterations) 144 { 145 start = System.currentTimeMillis(); 146 for (int invocationIterations = 0; invocationIterations < PerformanceSUITE.ITERATION_COUNT; ++invocationIterations) 147 { 148 server.invoke(name, method, null, null); 149 } 150 end = System.currentTimeMillis(); 151 152 if (testIterations != 0) 153 { 154 long time = end - start; 155 System.out.print( time + " "); 156 avg += time; 157 } 158 } 159 160 System.out.println("\nAverage: " + (avg/PerformanceSUITE.REPEAT_COUNT)); 161 162 assertTrue(mbean.getCount() == (PerformanceSUITE.REPEAT_COUNT + 1)*PerformanceSUITE.ITERATION_COUNT); 163 } 164 catch (Throwable t) 165 { 166 t.printStackTrace(); 167 fail("Unexpected error: " + t.toString()); 168 } 169 } 170 171 172 public void testMixedArgsInvocation() 173 { 174 try 175 { 176 System.out.println("\nSTANDARD: mixed arguments invocation"); 177 System.out.println(PerformanceSUITE.ITERATION_COUNT + " Invocations, Repeat: x" + PerformanceSUITE.REPEAT_COUNT); 178 System.out.println("(this may take a while...)\n"); 179 180 MBeanServer server = MBeanServerFactory.createMBeanServer(); 181 ObjectName name = new ObjectName("Domain:performanceTest=standard"); 182 Standard mbean = new Standard(); 183 184 String method = "mixedArguments"; 185 String [] signature = new String [] { 186 Integer .class.getName(), 187 int.class.getName(), 188 Object [][][].class.getName(), 189 Attribute.class.getName() 190 }; 191 192 Object [] args = new Object [] { 193 new Integer (1234), 194 new Integer (455617), 195 new Object [][][] { 196 { 197 { "1x1x1", "1x1x2", "1x1x3" }, 198 { "1x2x1", "1x2x2", "1x2x3" }, 199 { "1x3x1", "1x3x2", "1x3x3" } 200 }, 201 202 { 203 { "2x1x1", "2x1x2", "2x1x3" }, 204 { "2x2x1", "2x2x2", "2x2x3" }, 205 { "2x3x1", "2x3x2", "2x3x3" } 206 }, 207 208 { 209 { "3x1x1", "3x1x2", "3x1x3" }, 210 { "3x2x1", "3x2x2", "3x2x3" }, 211 { "3x3x1", "3x3x2", "3x3x3" } 212 } 213 }, 214 new Attribute("attribute", "value") 215 }; 216 217 long start = 0, end = 0; 218 float avg = 0l; 219 220 server.registerMBean(mbean, name); 221 222 for (int testIterations = 0; testIterations < PerformanceSUITE.REPEAT_COUNT + 1; ++testIterations) 224 { 225 start = System.currentTimeMillis(); 226 for (int invocationIterations = 0; invocationIterations < PerformanceSUITE.ITERATION_COUNT; ++invocationIterations) 227 { 228 server.invoke(name, method, args, signature); 229 } 230 end = System.currentTimeMillis(); 231 232 if (testIterations != 0) 233 { 234 long time = end - start; 235 System.out.print( time + " "); 236 avg += time; 237 } 238 } 239 240 System.out.println("\nAverage: " + (avg/PerformanceSUITE.REPEAT_COUNT)); 241 242 } 243 catch (Throwable t) 244 { 245 t.printStackTrace(); 246 fail("Unexpected error: " + t.toString()); 247 } 248 } 249 250 } 251 | Popular Tags |