public void testCountersWithInstrumentationManager() throws Exception {
// create Client with other bus
Bus bus = BusFactory.getDefaultBus();
bus.getExtension(WorkQueueManager.class);
CounterRepository cr = bus.getExtension(CounterRepository.class);
InstrumentationManager im = bus.getExtension(InstrumentationManager.class);
assertNotNull(im);
InstrumentationManagerImpl impl = (InstrumentationManagerImpl)im;
assertTrue(impl.isEnabled());
assertNotNull(impl.getMBeanServer());
MBeanServer mbs = im.getMBeanServer();
ObjectName name = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME
+ ":" + ManagementConstants.BUS_ID_PROP + "=cxf" + bus.hashCode() + ",*");
SOAPService service = new SOAPService();
assertNotNull(service);
Greeter greeter = service.getPort(portName, Greeter.class);
updateAddressPort(greeter, PORT);
String response = new String("Bonjour");
String reply = greeter.sayHi();
//assertNotNull("no response received from service", reply);
//assertEquals(response, reply);
assertEquals("The Counters are not create yet", 4, cr.getCounters().size());
Set<?> counterNames = mbs.queryNames(name, null);
assertEquals("The Counters are not export to JMX: " + counterNames,
4 + 3 , counterNames.size());
ObjectName sayHiCounter = new ObjectName(
ManagementConstants.DEFAULT_DOMAIN_NAME + ":operation=\"sayHi\",*");
Set<?> s = mbs.queryNames(sayHiCounter, null);
Iterator<?> it = s.iterator();
while (it.hasNext()) {
ObjectName counterName = (ObjectName)it.next();
Object val = mbs.getAttribute(counterName, "NumInvocations");
assertEquals("Wrong Counters Number of Invocations", val, 1);
}
reply = greeter.sayHi();
assertNotNull("no response received from service", reply);
assertEquals(response, reply);
s = mbs.queryNames(sayHiCounter, null);
it = s.iterator();
while (it.hasNext()) {
ObjectName counterName = (ObjectName)it.next();
Object val = mbs.getAttribute(counterName, "NumInvocations");
assertEquals("Wrong Counters Number of Invocations", val, 2);
}
greeter.greetMeOneWay("hello");
for (int count = 0; count < 10; count++) {
if (6 != cr.getCounters().size()) {
Thread.sleep(100);
} else {
break;
}
}
assertEquals("The Counters are not create yet", 6, cr.getCounters().size());
for (int count = 0; count < 10; count++) {
if (10 > mbs.queryNames(name, null).size()) {
Thread.sleep(100);
} else {
break;