use of javax.management.ObjectName in project camel by apache.
the class ManagedCamelContextUpdateRoutesFromXmlTest method testDumpAsXml.
public void testDumpAsXml() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
MBeanServer mbeanServer = getMBeanServer();
// there should be 1 routes to start with
Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
assertEquals(1, set.size());
// update existing route, and add a 2nd
String xml = "<routes id=\"myRoute\" xmlns=\"http://camel.apache.org/schema/spring\">" + "<route id=\"myRoute\">" + " <from uri=\"direct:start\"/>" + " <log message=\"This is a changed route saying ${body}\"/>" + " <to uri=\"mock:changed\"/>" + "</route>" + "<route id=\"myOtherRoute\">" + " <from uri=\"seda:bar\"/>" + " <to uri=\"mock:bar\"/>" + "</route>" + "</routes>";
ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=context,name=\"camel-1\"");
mbeanServer.invoke(on, "addOrUpdateRoutesFromXml", new Object[] { xml }, new String[] { "java.lang.String" });
// there should be 2 routes now
set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
assertEquals(2, set.size());
// test updated route
getMockEndpoint("mock:changed").expectedMessageCount(1);
template.sendBody("direct:start", "Bye World");
assertMockEndpointsSatisfied();
// test new route
getMockEndpoint("mock:bar").expectedMessageCount(1);
template.sendBody("seda:bar", "Hi Camel");
assertMockEndpointsSatisfied();
}
use of javax.management.ObjectName in project camel by apache.
the class ManagedCanekContextExchangeStatisticsTest method testExchangesCompletedStatistics.
public void testExchangesCompletedStatistics() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MBeanServer mbeanServer = getMBeanServer();
ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=context,name=\"camel-1\"");
Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(0, completed.longValue());
ObjectName route1 = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route1\"");
Long completed1 = (Long) mbeanServer.getAttribute(route1, "ExchangesCompleted");
assertEquals(0, completed1.longValue());
ObjectName route2 = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route2\"");
Long completed2 = (Long) mbeanServer.getAttribute(route1, "ExchangesCompleted");
assertEquals(0, completed2.longValue());
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
completed = (Long) mbeanServer.getAttribute(route1, "ExchangesCompleted");
assertEquals(1, completed.longValue());
completed1 = (Long) mbeanServer.getAttribute(route1, "ExchangesCompleted");
assertEquals(1, completed1.longValue());
completed2 = (Long) mbeanServer.getAttribute(route2, "ExchangesCompleted");
assertEquals(0, completed2.longValue());
resetMocks();
getMockEndpoint("mock:result").expectedMessageCount(2);
template.sendBody("direct:start", "Hi World");
template.sendBody("direct:bar", "Bye World");
assertMockEndpointsSatisfied();
completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(3, completed.longValue());
completed1 = (Long) mbeanServer.getAttribute(route1, "ExchangesCompleted");
assertEquals(2, completed1.longValue());
completed2 = (Long) mbeanServer.getAttribute(route2, "ExchangesCompleted");
assertEquals(1, completed2.longValue());
}
use of javax.management.ObjectName in project camel by apache.
the class ManagedRecipientListTest method testManageRecipientList.
public void testManageRecipientList() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MockEndpoint foo = getMockEndpoint("mock:foo");
foo.expectedMessageCount(2);
MockEndpoint bar = getMockEndpoint("mock:bar");
bar.expectedMessageCount(1);
template.sendBodyAndHeader("direct:start", "Hello World", "whereto", "mock:foo");
template.sendBodyAndHeader("direct:start", "Bye World", "whereto", "mock:foo");
template.sendBodyAndHeader("direct:start", "Hi World", "whereto", "mock:bar");
assertMockEndpointsSatisfied();
// get the stats for the route
MBeanServer mbeanServer = getMBeanServer();
// get the object name for the delayer
ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mysend\"");
// should be on route1
String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
assertEquals("route1", routeId);
String camelId = (String) mbeanServer.getAttribute(on, "CamelId");
assertEquals("camel-1", camelId);
String state = (String) mbeanServer.getAttribute(on, "State");
assertEquals(ServiceStatus.Started.name(), state);
Boolean parallel = (Boolean) mbeanServer.getAttribute(on, "ParallelProcessing");
assertEquals(false, parallel.booleanValue());
String lan = (String) mbeanServer.getAttribute(on, "ExpressionLanguage");
assertEquals("header", lan);
String uri = (String) mbeanServer.getAttribute(on, "Expression");
assertEquals("whereto", uri);
TabularData data = (TabularData) mbeanServer.invoke(on, "extendedInformation", null, null);
assertNotNull(data);
assertEquals(2, data.size());
data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { false }, new String[] { "boolean" });
assertNotNull(data);
assertEquals(2, data.size());
data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { true }, new String[] { "boolean" });
assertNotNull(data);
assertEquals(18, data.size());
String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
assertNotNull(json);
assertTrue(json.contains("\"description\": \"Routes messages to a number of dynamically specified recipients (dynamic to)"));
}
use of javax.management.ObjectName in project camel by apache.
the class ManagedRedeliverRouteOnlyTest method testRedeliver.
public void testRedeliver() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MBeanServer mbeanServer = getMBeanServer();
getMockEndpoint("mock:foo").expectedMessageCount(1);
Object out = template.requestBody("direct:start", "Hello World");
assertEquals("Error", out);
assertMockEndpointsSatisfied();
ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route1\"");
Long num = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(1, num.longValue());
num = (Long) mbeanServer.getAttribute(on, "ExchangesFailed");
assertEquals(0, num.longValue());
num = (Long) mbeanServer.getAttribute(on, "FailuresHandled");
assertEquals(1, num.longValue());
}
use of javax.management.ObjectName in project camel by apache.
the class ManagedRefProducerTest method testProducer.
public void testProducer() 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);
getMockEndpoint("foo").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
MBeanServer mbeanServer = getMBeanServer();
Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=producers,*"), null);
assertEquals(2, set.size());
Iterator<ObjectName> it = set.iterator();
for (int i = 0; i < 2; i++) {
ObjectName on = it.next();
boolean registered = mbeanServer.isRegistered(on);
assertEquals("Should be registered", true, registered);
String uri = (String) mbeanServer.getAttribute(on, "EndpointUri");
assertTrue(uri, uri.equals("mock://foo") || uri.equals("mock://result"));
// should be started
String state = (String) mbeanServer.getAttribute(on, "State");
assertEquals("Should be started", ServiceStatus.Started.name(), state);
}
set = mbeanServer.queryNames(new ObjectName("*:type=endpoints,*"), null);
assertEquals(4, set.size());
it = set.iterator();
for (int i = 0; i < 4; i++) {
ObjectName on = it.next();
boolean registered = mbeanServer.isRegistered(on);
assertEquals("Should be registered", true, registered);
String uri = (String) mbeanServer.getAttribute(on, "EndpointUri");
assertTrue(uri, uri.equals("direct://start") || uri.equals("ref://foo") || uri.equals("mock://foo") || uri.equals("mock://result"));
}
}
Aggregations