public void testReset() throws Exception {
// get the stats for the route
MBeanServer mbeanServer = getMBeanServer();
QueryExp queryExp = Query.match(new AttributeValueExp("RouteId"), new StringValueExp("first"));
Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), queryExp);
assertEquals(1, set.size());
ObjectName on = set.iterator().next();
// send in 5 messages
template.sendBody("direct:start", "A");
template.sendBody("direct:start", "B");
template.sendBody("direct:start", "C");
template.sendBody("direct:start", "D");
template.sendBody("direct:start", "E");
// and 1 for the 2nd route
template.sendBody("direct:baz", "F");
assertMockEndpointsSatisfied();
// should be 5 on the route
Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(5, completed.longValue());
// and on the processors as well
set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), queryExp);
assertEquals(3, set.size());
for (ObjectName name : set) {
completed = (Long) mbeanServer.getAttribute(name, "ExchangesCompleted");
assertEquals(5, completed.longValue());
}
// reset which should reset all routes also
ObjectName ctx = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=context,name=\"camel-1\"");
mbeanServer.invoke(ctx, "reset", new Object[]{true}, new String[]{"boolean"});
// should be 0 on the route
completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(0, completed.longValue());
// and on the processors as well
set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), queryExp);
assertEquals(3, set.size());
for (ObjectName name : set) {
completed = (Long) mbeanServer.getAttribute(name, "ExchangesCompleted");
assertEquals(0, completed.longValue());
}
// test that the 2nd route is also reset
queryExp = Query.match(new AttributeValueExp("RouteId"), new StringValueExp("second"));
set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), queryExp);
assertEquals(1, set.size());
on = set.iterator().next();
completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");