use of javax.management.MBeanServer in project camel by apache.
the class ManagedTransformerRegistryTest method testManageTransformerRegistry.
public void testManageTransformerRegistry() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
// get the stats for the route
MBeanServer mbeanServer = getMBeanServer();
Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=services,*"), null);
List<ObjectName> list = new ArrayList<ObjectName>(set);
ObjectName on = null;
for (ObjectName name : list) {
if (name.getCanonicalName().contains("DefaultTransformerRegistry")) {
on = name;
break;
}
}
assertNotNull("Should have found TransformerRegistry", on);
Integer max = (Integer) mbeanServer.getAttribute(on, "MaximumCacheSize");
assertEquals(1000, max.intValue());
Integer current = (Integer) mbeanServer.getAttribute(on, "Size");
assertEquals(3, current.intValue());
current = (Integer) mbeanServer.getAttribute(on, "StaticSize");
assertEquals(0, current.intValue());
current = (Integer) mbeanServer.getAttribute(on, "DynamicSize");
assertEquals(3, current.intValue());
String source = (String) mbeanServer.getAttribute(on, "Source");
assertTrue(source.startsWith("TransformerRegistry"));
assertTrue(source.endsWith("capacity: 1000"));
TabularData data = (TabularData) mbeanServer.invoke(on, "listTransformers", null, null);
for (Object row : data.values()) {
CompositeData composite = (CompositeData) row;
String scheme = (String) composite.get("scheme");
String from = (String) composite.get("from");
String to = (String) composite.get("to");
String description = (String) composite.get("description");
boolean isStatic = (boolean) composite.get("static");
boolean isDynamic = (boolean) composite.get("dynamic");
LOG.info("[{}][{}][{}][{}][{}][{}]", scheme, from, to, isStatic, isDynamic, description);
if (description.startsWith("ProcessorTransformer")) {
assertEquals(null, scheme);
assertEquals("xml:foo", from);
assertEquals("json:bar", to);
} else if (description.startsWith("DataFormatTransformer")) {
assertEquals(null, scheme);
assertEquals("java:" + ManagedTransformerRegistryTest.class.getName(), from);
assertEquals("xml:test", to);
} else if (description.startsWith("MyTransformer")) {
assertEquals("custom", scheme);
assertEquals(null, from);
assertEquals(null, to);
} else {
fail("Unexpected transformer:" + description);
}
}
assertEquals(3, data.size());
}
use of javax.management.MBeanServer in project camel by apache.
the class ManagedTypeConverterRegistryTest method testTypeConverterRegistry.
public void testTypeConverterRegistry() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
getMockEndpoint("mock:a").expectedMessageCount(2);
template.sendBody("direct:start", "3");
template.sendBody("direct:start", "7");
assertMockEndpointsSatisfied();
MBeanServer mbeanServer = getMBeanServer();
ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=services,*");
// number of services
Set<ObjectName> names = mbeanServer.queryNames(on, null);
ObjectName name = null;
for (ObjectName service : names) {
if (service.toString().contains("DefaultTypeConverter")) {
name = service;
break;
}
}
assertNotNull("Cannot find DefaultTypeConverter", name);
// is disabled by default
Boolean enabled = (Boolean) mbeanServer.getAttribute(name, "StatisticsEnabled");
assertEquals(Boolean.FALSE, enabled);
// need to enable statistics
mbeanServer.setAttribute(name, new Attribute("StatisticsEnabled", Boolean.TRUE));
Long failed = (Long) mbeanServer.getAttribute(name, "FailedCounter");
assertEquals(0, failed.intValue());
Long miss = (Long) mbeanServer.getAttribute(name, "MissCounter");
assertEquals(0, miss.intValue());
try {
template.sendBody("direct:start", "foo");
fail("Should have thrown exception");
} catch (Exception e) {
// expected
}
// should now have a failed
failed = (Long) mbeanServer.getAttribute(name, "FailedCounter");
assertEquals(1, failed.intValue());
miss = (Long) mbeanServer.getAttribute(name, "MissCounter");
assertEquals(0, miss.intValue());
// reset
mbeanServer.invoke(name, "resetTypeConversionCounters", null, null);
failed = (Long) mbeanServer.getAttribute(name, "FailedCounter");
assertEquals(0, failed.intValue());
miss = (Long) mbeanServer.getAttribute(name, "MissCounter");
assertEquals(0, miss.intValue());
// we have more than 150 converters out of the box
Integer converters = (Integer) mbeanServer.getAttribute(name, "NumberOfTypeConverters");
assertTrue("Should be more than 150 converters, was: " + converters, converters >= 150);
Boolean has = (Boolean) mbeanServer.invoke(name, "hasTypeConverter", new Object[] { "String", "java.io.InputStream" }, new String[] { "java.lang.String", "java.lang.String" });
assertTrue("Should have type converter", has.booleanValue());
has = (Boolean) mbeanServer.invoke(name, "hasTypeConverter", new Object[] { "java.math.BigInteger", "int" }, new String[] { "java.lang.String", "java.lang.String" });
assertFalse("Should not have type converter", has.booleanValue());
// we have more than 150 converters out of the box
TabularData data = (TabularData) mbeanServer.invoke(name, "listTypeConverters", null, null);
assertTrue("Should be more than 150 converters, was: " + data.size(), data.size() >= 150);
}
use of javax.management.MBeanServer in project camel by apache.
the class ManagedRouteStopAndStartCleanupTest method testStopAndStartRoute.
public void testStopAndStartRoute() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MBeanServer mbeanServer = getMBeanServer();
ObjectName on = getRouteObjectName(mbeanServer);
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
template.sendBodyAndHeader("file://target/managed", "Hello World", Exchange.FILE_NAME, "hello.txt");
assertMockEndpointsSatisfied();
// should be started
String state = (String) mbeanServer.getAttribute(on, "State");
assertEquals("Should be started", ServiceStatus.Started.name(), state);
// need a bit time to let JMX update
Thread.sleep(1000);
// should have 1 completed exchange
Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(1, completed.longValue());
// should be 1 consumer and 2 processors
Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=consumers,*"), null);
assertEquals("Should be 1 consumer", 1, set.size());
set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), null);
assertEquals("Should be 2 processors", 2, set.size());
// stop
log.info(">>>>>>>>>>>>>>>>>> invoking stop <<<<<<<<<<<<<<<<<<<<<");
mbeanServer.invoke(on, "stop", null, null);
log.info(">>>>>>>>>>>>>>>>>> invoking stop DONE <<<<<<<<<<<<<<<<<<<<<");
state = (String) mbeanServer.getAttribute(on, "State");
assertEquals("Should be stopped", ServiceStatus.Stopped.name(), state);
// should be 0 consumer and 0 processor
set = mbeanServer.queryNames(new ObjectName("*:type=consumers,*"), null);
assertEquals("Should be 0 consumer", 0, set.size());
set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), null);
assertEquals("Should be 0 processor", 0, set.size());
mock.reset();
mock.expectedBodiesReceived("Bye World");
// wait 3 seconds while route is stopped to verify that file was not consumed
mock.setResultWaitTime(3000);
template.sendBodyAndHeader("file://target/managed", "Bye World", Exchange.FILE_NAME, "bye.txt");
// route is stopped so we do not get the file
mock.assertIsNotSatisfied();
// prepare mock for starting route
mock.reset();
mock.expectedBodiesReceived("Bye World");
// start
log.info(">>>>>>>>>>>>>>>>> invoking start <<<<<<<<<<<<<<<<<<");
mbeanServer.invoke(on, "start", null, null);
log.info(">>>>>>>>>>>>>>>>> invoking start DONE <<<<<<<<<<<<<<<<<<");
state = (String) mbeanServer.getAttribute(on, "State");
assertEquals("Should be started", ServiceStatus.Started.name(), state);
// should be 1 consumer and 1 processor
set = mbeanServer.queryNames(new ObjectName("*:type=consumers,*"), null);
assertEquals("Should be 1 consumer", 1, set.size());
set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), null);
assertEquals("Should be 2 processors", 2, set.size());
// this time the file is consumed
mock.assertIsSatisfied();
// need a bit time to let JMX update
Thread.sleep(1000);
// should have 2 completed exchange
completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(2, completed.longValue());
}
use of javax.management.MBeanServer in project camel by apache.
the class ManagedRouteStopAndStartTest method testStopAndStartRoute.
public void testStopAndStartRoute() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MBeanServer mbeanServer = getMBeanServer();
ObjectName on = getRouteObjectName(mbeanServer);
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
template.sendBodyAndHeader("file://target/managed", "Hello World", Exchange.FILE_NAME, "hello.txt");
assertMockEndpointsSatisfied();
// should be started
String state = (String) mbeanServer.getAttribute(on, "State");
assertEquals("Should be started", ServiceStatus.Started.name(), state);
String id = (String) mbeanServer.getAttribute(on, "RouteId");
assertEquals("foo", id);
String description = (String) mbeanServer.getAttribute(on, "Description");
assertEquals("This is the foo route", description);
// stop
mbeanServer.invoke(on, "stop", null, null);
state = (String) mbeanServer.getAttribute(on, "State");
assertEquals("Should be stopped", ServiceStatus.Stopped.name(), state);
mock.reset();
mock.expectedBodiesReceived("Bye World");
// wait 3 seconds while route is stopped to verify that file was not consumed
mock.setResultWaitTime(3000);
template.sendBodyAndHeader("file://target/managed", "Bye World", Exchange.FILE_NAME, "bye.txt");
// route is stopped so we do not get the file
mock.assertIsNotSatisfied();
// prepare mock for starting route
mock.reset();
mock.expectedBodiesReceived("Bye World");
// start
mbeanServer.invoke(on, "start", null, null);
state = (String) mbeanServer.getAttribute(on, "State");
assertEquals("Should be started", ServiceStatus.Started.name(), state);
// this time the file is consumed
mock.assertIsSatisfied();
}
use of javax.management.MBeanServer in project camel by apache.
the class ManagedRouteStopUsingMBeanAPITest method testStopRoute.
public void testStopRoute() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
// fire a message to get it running
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
MBeanServer mbeanServer = getMBeanServer();
Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
assertEquals(1, set.size());
ObjectName on = set.iterator().next();
ManagedRouteMBean mbean = context.getManagementStrategy().getManagementAgent().newProxyClient(on, ManagedRouteMBean.class);
// the route has this starting endpoint uri
assertEquals("direct://start", mbean.getEndpointUri());
// should be started
assertEquals("Should be started", ServiceStatus.Started.name(), mbean.getState());
mbean.stop();
// should be stopped
assertEquals("Should be stopped", ServiceStatus.Stopped.name(), mbean.getState());
}
Aggregations