use of javax.management.ObjectName in project camel by apache.
the class ManagedCircuitBreakerLoadBalancerTest method testManageCircuitBreakerLoadBalancer.
public void testManageCircuitBreakerLoadBalancer() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
getMockEndpoint("mock:foo").whenExchangeReceived(1, new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
throw new SQLException("Forced");
}
});
MockEndpoint foo = getMockEndpoint("mock:foo");
foo.expectedBodiesReceived("Hello World", "Bye World");
try {
template.sendBodyAndHeader("direct:start", "Hello World", "foo", "123");
fail("Should fail");
} catch (Exception e) {
assertIsInstanceOf(SQLException.class, e.getCause());
assertEquals("Forced", e.getCause().getMessage());
}
template.sendBodyAndHeader("direct:start", "Bye World", "foo", "123");
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);
Integer size = (Integer) mbeanServer.getAttribute(on, "Size");
assertEquals(1, size.intValue());
Long half = (Long) mbeanServer.getAttribute(on, "HalfOpenAfter");
assertEquals(5000, half.longValue());
Integer attempts = (Integer) mbeanServer.getAttribute(on, "Threshold");
assertEquals(2, attempts.intValue());
String exceptions = (String) mbeanServer.getAttribute(on, "Exceptions");
assertEquals("java.io.IOException,java.sql.SQLException", exceptions);
String cbState = (String) mbeanServer.getAttribute(on, "CircuitBreakerState");
assertEquals("closed", cbState);
String dump = (String) mbeanServer.invoke(on, "dumpState", null, null);
assertTrue(dump.startsWith("State closed, failures 0, closed since"));
TabularData data = (TabularData) mbeanServer.invoke(on, "exceptionStatistics", 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(5, data.size());
String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
assertNotNull(json);
assertTrue(json.contains("\"description\": \"Balances message processing among a number of nodes"));
}
use of javax.management.ObjectName in project camel by apache.
the class ManagedConvertBodyTest method testManageConvertBody.
public void testManageConvertBody() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MockEndpoint foo = getMockEndpoint("mock:foo");
foo.expectedMessageCount(1);
template.sendBodyAndHeader("direct:start", "Hello World", "foo", "123");
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);
String uri = (String) mbeanServer.getAttribute(on, "Type");
assertEquals("byte[]", uri);
TabularData 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(4, data.size());
String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
assertNotNull(json);
assertTrue(json.contains("\"description\": \"Converts the message body to another type"));
assertTrue(json.contains("byte[]"));
}
use of javax.management.ObjectName in project camel by apache.
the class ManagedCustomBeanTest method testManageCustomBean.
public void testManageCustomBean() 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=processors,name=\"custom\"");
getMockEndpoint("mock:result").expectedMessageCount(1);
getMockEndpoint("mock:result").expectedHeaderReceived("foo", "hey");
template.sendBody("direct:start", "World");
assertMockEndpointsSatisfied();
String foo = (String) mbeanServer.getAttribute(on, "Foo");
assertEquals("hey", foo);
// change foo
mbeanServer.setAttribute(on, new Attribute("Foo", "changed"));
resetMocks();
getMockEndpoint("mock:result").expectedMessageCount(1);
getMockEndpoint("mock:result").expectedHeaderReceived("foo", "changed");
template.sendBody("direct:start", "Camel");
assertMockEndpointsSatisfied();
}
use of javax.management.ObjectName in project camel by apache.
the class ManagedCustomComponentNameTest method testCustomName.
public void testCustomName() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MBeanServer mbeanServer = getMBeanServer();
Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=components,*"), null);
assertEquals(3, set.size());
ObjectName on = set.iterator().next();
assertTrue("Should be registered", mbeanServer.isRegistered(on));
String state = (String) mbeanServer.getAttribute(on, "State");
assertEquals(ServiceStatus.Started.name(), state);
String id = (String) mbeanServer.getAttribute(on, "CamelId");
assertEquals("camel-1", id);
context.stop();
assertFalse("Should no longer be registered", mbeanServer.isRegistered(on));
set = mbeanServer.queryNames(new ObjectName("*:type=components,*"), null);
assertEquals("Should no longer be registered", 0, set.size());
}
use of javax.management.ObjectName in project camel by apache.
the class ManagedCustomPolicyTest method testPolicy.
public void testPolicy() 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();
assertEquals(1, counter.get());
MBeanServer mbeanServer = getMBeanServer();
Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), null);
assertEquals(3, set.size());
ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"foo\"");
assertTrue("Should be registered: foo", mbeanServer.isRegistered(on));
on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"result\"");
assertTrue("Should be registered: result", mbeanServer.isRegistered(on));
on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"bar\"");
assertTrue("Should be registered: bar", mbeanServer.isRegistered(on));
}
Aggregations