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