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