@Test
public void testCountersWithInstrumentationManager() throws Exception {
// create Client with other bus
Bus bus = BusFactory.getDefaultBus();
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);
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=\"{http://apache.org/hello_world_soap_http}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");
assertEquals("The Counters are not create yet", 6, cr.getCounters().size());
counterNames = mbs.queryNames(name, null);
assertEquals("The Counters are not export to JMX ", 6 + 3, counterNames.size());
ObjectName greetMeOneWayCounter = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME
+ ":operation=\"{http://apache.org/hello_world_soap_http}greetMeOneWay\",*");