use of javax.management.ObjectName in project camel by apache.
the class ManagedErrorHandlerOptionsTest method testManagedErrorHandlerOptions.
public void testManagedErrorHandlerOptions() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
counter = 0;
MBeanServer mbeanServer = getMBeanServer();
Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=errorhandlers,*"), null);
assertEquals(1, set.size());
ObjectName on = set.iterator().next();
mbeanServer.setAttribute(on, new Attribute("MaximumRedeliveries", 3));
Integer max = (Integer) mbeanServer.getAttribute(on, "MaximumRedeliveries");
assertEquals(3, max.intValue());
mbeanServer.setAttribute(on, new Attribute("MaximumRedeliveryDelay", Long.valueOf("20000")));
Long delay = (Long) mbeanServer.getAttribute(on, "MaximumRedeliveryDelay");
assertEquals(20000, delay.longValue());
mbeanServer.setAttribute(on, new Attribute("RedeliveryDelay", Long.valueOf("250")));
delay = (Long) mbeanServer.getAttribute(on, "RedeliveryDelay");
assertEquals(250, delay.longValue());
String camelId = (String) mbeanServer.getAttribute(on, "CamelId");
assertEquals("camel-1", camelId);
mbeanServer.setAttribute(on, new Attribute("BackOffMultiplier", Double.valueOf("3.5")));
Double backoff = (Double) mbeanServer.getAttribute(on, "BackOffMultiplier");
assertNotNull(backoff);
mbeanServer.setAttribute(on, new Attribute("CollisionAvoidanceFactor", Double.valueOf("1.5")));
Double cf = (Double) mbeanServer.getAttribute(on, "CollisionAvoidanceFactor");
assertNotNull(cf);
mbeanServer.setAttribute(on, new Attribute("CollisionAvoidancePercent", Double.valueOf("75")));
Double cp = (Double) mbeanServer.getAttribute(on, "CollisionAvoidancePercent");
assertNotNull(cp);
mbeanServer.setAttribute(on, new Attribute("DelayPattern", "0:1000;5:5000"));
String dp = (String) mbeanServer.getAttribute(on, "DelayPattern");
assertNotNull(dp);
mbeanServer.setAttribute(on, new Attribute("RetriesExhaustedLogLevel", "WARN"));
String ell = (String) mbeanServer.getAttribute(on, "RetriesExhaustedLogLevel");
assertEquals(LoggingLevel.WARN.name(), ell);
mbeanServer.setAttribute(on, new Attribute("RetryAttemptedLogLevel", "WARN"));
String rll = (String) mbeanServer.getAttribute(on, "RetryAttemptedLogLevel");
assertEquals(LoggingLevel.WARN.name(), rll);
mbeanServer.setAttribute(on, new Attribute("LogStackTrace", Boolean.TRUE));
Boolean lst = (Boolean) mbeanServer.getAttribute(on, "LogStackTrace");
assertEquals(true, lst.booleanValue());
mbeanServer.setAttribute(on, new Attribute("UseCollisionAvoidance", Boolean.TRUE));
Boolean uca = (Boolean) mbeanServer.getAttribute(on, "UseCollisionAvoidance");
assertEquals(true, uca.booleanValue());
mbeanServer.setAttribute(on, new Attribute("UseExponentialBackOff", Boolean.TRUE));
Boolean uebf = (Boolean) mbeanServer.getAttribute(on, "UseExponentialBackOff");
assertEquals(true, uebf.booleanValue());
Boolean ne = (Boolean) mbeanServer.getAttribute(on, "DeadLetterHandleNewException");
assertEquals(false, ne.booleanValue());
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertEquals(3, counter);
assertMockEndpointsSatisfied();
// now change to 0 attempts and try again
counter = 0;
mock.reset();
mock.expectedMessageCount(0);
mbeanServer.setAttribute(on, new Attribute("MaximumRedeliveries", 0));
try {
template.sendBody("direct:start", "Bye World");
fail("Should have thrown exception");
} catch (CamelExecutionException e) {
IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
assertEquals("Forced", cause.getMessage());
}
assertEquals(1, counter);
// and should now be 0
max = (Integer) mbeanServer.getAttribute(on, "MaximumRedeliveries");
assertEquals(0, max.intValue());
}
use of javax.management.ObjectName in project camel by apache.
the class ManagedErrorHandlerTest method testManagedErrorHandler.
public void testManagedErrorHandler() 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=errorhandlers,*"), null);
// there should only be 2 error handler types as route 1 and route 3 uses the same default error handler
assertEquals(2, set.size());
Iterator<ObjectName> it = set.iterator();
ObjectName on1 = it.next();
ObjectName on2 = it.next();
String name1 = on1.getCanonicalName();
String name2 = on2.getCanonicalName();
assertTrue("Should be a default error handler", name1.contains("CamelDefaultErrorHandlerBuilder") || name2.contains("CamelDefaultErrorHandlerBuilder"));
assertTrue("Should be a dead letter error handler", name1.contains("DeadLetterChannelBuilder") || name2.contains("DeadLetterChannelBuilder"));
}
use of javax.management.ObjectName in project camel by apache.
the class ManagedFailoverLoadBalancerTest method testManageFailoverLoadBalancer.
public void testManageFailoverLoadBalancer() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
getMockEndpoint("mock:foo").whenAnyExchangeReceived(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
throw new IOException("Forced");
}
});
MockEndpoint bar = getMockEndpoint("mock:bar");
bar.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);
Integer size = (Integer) mbeanServer.getAttribute(on, "Size");
assertEquals(2, size.intValue());
Boolean roundRobin = (Boolean) mbeanServer.getAttribute(on, "RoundRobin");
assertEquals(true, roundRobin.booleanValue());
Boolean sticky = (Boolean) mbeanServer.getAttribute(on, "Sticky");
assertEquals(true, sticky.booleanValue());
Integer attempts = (Integer) mbeanServer.getAttribute(on, "MaximumFailoverAttempts");
assertEquals(3, attempts.intValue());
String exceptions = (String) mbeanServer.getAttribute(on, "Exceptions");
assertEquals("java.io.IOException,java.sql.SQLException", exceptions);
String id = (String) mbeanServer.getAttribute(on, "LastGoodProcessorId");
assertEquals("bar", id);
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(3, 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 ManagedFromRestGetEmbeddedRouteTest method testFromRestModel.
public void testFromRestModel() 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\"");
String xml = (String) mbeanServer.invoke(on, "dumpRestsAsXml", null, null);
assertNotNull(xml);
log.info(xml);
assertTrue(xml.contains("<rests"));
assertTrue(xml.contains("<rest path=\"/say/hello\">"));
assertTrue(xml.contains("<rest path=\"/say/bye\">"));
assertTrue(xml.contains("</rest>"));
assertTrue(xml.contains("<get"));
assertTrue(xml.contains("<route"));
assertTrue(xml.contains("<transform"));
assertTrue(xml.contains("<post"));
assertTrue(xml.contains("application/json"));
assertTrue(xml.contains("</rests>"));
String xml2 = (String) mbeanServer.invoke(on, "dumpRoutesAsXml", null, null);
log.info(xml2);
// and we should have rest in the routes that indicate its from a rest dsl
assertTrue(xml2.contains("rest=\"true\""));
// there should be 2 + 1 routes
assertEquals(2 + 1, context.getRouteDefinitions().size());
}
use of javax.management.ObjectName in project camel by apache.
the class ManagedFromRestPlaceholderTest method testFromRestModelPlaceholder.
public void testFromRestModelPlaceholder() 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\"");
String xml = (String) mbeanServer.invoke(on, "dumpRestsAsXml", new Object[] { true }, new String[] { "boolean" });
assertNotNull(xml);
log.info(xml);
assertTrue(xml.contains("<rests"));
assertTrue(xml.contains("<rest path=\"/say/hello\">"));
assertTrue(xml.contains("<rest path=\"/say/bye\">"));
assertTrue(xml.contains("</rest>"));
assertTrue(xml.contains("<get"));
assertTrue(xml.contains("application/json"));
assertTrue(xml.contains("<post"));
assertTrue(xml.contains("application/json"));
assertTrue(xml.contains("</rests>"));
assertTrue(xml.contains("<param collectionFormat=\"multi\" dataType=\"string\" defaultValue=\"b\" description=\"header param description2\" " + "name=\"header_letter\" required=\"false\" type=\"query\">"));
assertTrue(xml.contains("<param dataType=\"integer\" defaultValue=\"1\" description=\"header param description1\" " + "name=\"header_count\" required=\"true\" type=\"header\">"));
assertTrue(xml.contains("<value>1</value>"));
assertTrue(xml.contains("<value>a</value>"));
assertTrue(xml.contains("<responseMessage code=\"300\" message=\"test msg\" responseModel=\"java.lang.Integer\"/>"));
String xml2 = (String) mbeanServer.invoke(on, "dumpRoutesAsXml", null, null);
log.info(xml2);
// and we should have rest in the routes that indicate its from a rest dsl
assertTrue(xml2.contains("rest=\"true\""));
// there should be 3 + 2 routes
assertEquals(3 + 2, context.getRouteDefinitions().size());
}
Aggregations