use of javax.management.ObjectName in project camel by apache.
the class BacklogTracerFilterTest method testBacklogTracerFilter.
@SuppressWarnings("unchecked")
public void testBacklogTracerFilter() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MBeanServer mbeanServer = getMBeanServer();
ObjectName on = new ObjectName("org.apache.camel:context=camel-1,type=tracer,name=BacklogTracer");
assertNotNull(on);
mbeanServer.isRegistered(on);
Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
assertEquals("Should not be enabled", Boolean.FALSE, enabled);
Integer size = (Integer) mbeanServer.getAttribute(on, "BacklogSize");
assertEquals("Should be 1000", 1000, size.intValue());
// set the filter to match only if header foo exists
mbeanServer.setAttribute(on, new Attribute("TraceFilter", "${header.foo} != null"));
// enable it
mbeanServer.setAttribute(on, new Attribute("Enabled", Boolean.TRUE));
getMockEndpoint("mock:foo").expectedMessageCount(2);
getMockEndpoint("mock:bar").expectedMessageCount(2);
template.sendBody("direct:start", "Hello World");
template.sendBodyAndHeader("direct:start", "Bye World", "foo", 123);
assertMockEndpointsSatisfied();
List<Exchange> exchanges = getMockEndpoint("mock:foo").getReceivedExchanges();
List<BacklogTracerEventMessage> events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpAllTracedMessages", null, null);
assertNotNull(events);
assertEquals(3, events.size());
BacklogTracerEventMessage event = events.get(0);
assertEquals(null, event.getToNode());
assertEquals(" <message exchangeId=\"" + exchanges.get(1).getExchangeId() + "\">\n" + " <headers>\n" + " <header key=\"foo\" type=\"java.lang.Integer\">123</header>\n" + " </headers>\n" + " <body type=\"java.lang.String\">Bye World</body>\n" + " </message>", event.getMessageAsXml());
BacklogTracerEventMessage event1 = events.get(1);
assertEquals("foo", event1.getToNode());
assertEquals(" <message exchangeId=\"" + exchanges.get(1).getExchangeId() + "\">\n" + " <headers>\n" + " <header key=\"foo\" type=\"java.lang.Integer\">123</header>\n" + " </headers>\n" + " <body type=\"java.lang.String\">Bye World</body>\n" + " </message>", event1.getMessageAsXml());
BacklogTracerEventMessage event2 = events.get(2);
assertEquals("bar", event2.getToNode());
assertEquals(" <message exchangeId=\"" + exchanges.get(1).getExchangeId() + "\">\n" + " <headers>\n" + " <header key=\"foo\" type=\"java.lang.Integer\">123</header>\n" + " </headers>\n" + " <body type=\"java.lang.String\">Bye World</body>\n" + " </message>", event2.getMessageAsXml());
}
use of javax.management.ObjectName in project camel by apache.
the class BacklogTracerIdOnAllNodesTest method testBacklogTracerEventMessage.
@SuppressWarnings("unchecked")
public void testBacklogTracerEventMessage() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MBeanServer mbeanServer = getMBeanServer();
ObjectName on = new ObjectName("org.apache.camel:context=camel-1,type=tracer,name=BacklogTracer");
assertNotNull(on);
mbeanServer.isRegistered(on);
Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
assertEquals("Should not be enabled", Boolean.FALSE, enabled);
Integer size = (Integer) mbeanServer.getAttribute(on, "BacklogSize");
assertEquals("Should be 1000", 1000, size.intValue());
// enable it
mbeanServer.setAttribute(on, new Attribute("Enabled", Boolean.TRUE));
getMockEndpoint("mock:camel").expectedBodiesReceived("Hello Camel");
getMockEndpoint("mock:other").expectedBodiesReceived("Hello World");
getMockEndpoint("mock:end").expectedMessageCount(2);
template.sendBody("direct:start", "Hello Camel");
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
List<Exchange> fooExchanges = getMockEndpoint("mock:foo").getReceivedExchanges();
List<Exchange> camelExchanges = getMockEndpoint("mock:camel").getReceivedExchanges();
RouteDefinition route = context.getRouteDefinitions().get(0);
assertNotNull(route);
ChoiceDefinition choice = (ChoiceDefinition) route.getOutputs().get(0);
assertEquals("choice1", choice.getId());
WhenDefinition when = (WhenDefinition) choice.getOutputs().get(0);
assertEquals("when1", when.getId());
LogDefinition log1 = (LogDefinition) when.getOutputs().get(0);
assertEquals("log1", log1.getId());
ToDefinition to1 = (ToDefinition) when.getOutputs().get(1);
assertEquals("camel", to1.getId());
OtherwiseDefinition other = (OtherwiseDefinition) choice.getOutputs().get(1);
assertEquals("otherwise1", other.getId());
LogDefinition log2 = (LogDefinition) other.getOutputs().get(0);
assertEquals("log2", log2.getId());
ToDefinition to2 = (ToDefinition) other.getOutputs().get(1);
assertEquals("to1", to2.getId());
ToDefinition to3 = (ToDefinition) other.getOutputs().get(2);
assertEquals("foo", to3.getId());
ToDefinition to4 = (ToDefinition) route.getOutputs().get(1);
assertEquals("end", to4.getId());
List<BacklogTracerEventMessage> events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "to1" }, new String[] { "java.lang.String" });
assertNotNull(events);
assertEquals(1, events.size());
BacklogTracerEventMessage event1 = events.get(0);
assertEquals("to1", event1.getToNode());
assertEquals(" <message exchangeId=\"" + fooExchanges.get(0).getExchangeId() + "\">\n" + " <body type=\"java.lang.String\">Hello World</body>\n" + " </message>", event1.getMessageAsXml());
events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "camel" }, new String[] { "java.lang.String" });
assertNotNull(events);
assertEquals(1, events.size());
event1 = events.get(0);
assertEquals("camel", event1.getToNode());
assertEquals(" <message exchangeId=\"" + camelExchanges.get(0).getExchangeId() + "\">\n" + " <body type=\"java.lang.String\">Hello Camel</body>\n" + " </message>", event1.getMessageAsXml());
}
use of javax.management.ObjectName in project camel by apache.
the class JmxInstrumentationDisableOnCamelContextTest method testMBeansRegistered.
@Override
public void testMBeansRegistered() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
resolveMandatoryEndpoint("mock:end", MockEndpoint.class);
Set<ObjectName> s = mbsc.queryNames(new ObjectName(domainName + ":type=endpoints,*"), null);
assertEquals("Could not find 0 endpoints: " + s, 0, s.size());
s = mbsc.queryNames(new ObjectName(domainName + ":type=contexts,*"), null);
assertEquals("Could not find 0 context: " + s, 0, s.size());
s = mbsc.queryNames(new ObjectName(domainName + ":type=processors,*"), null);
assertEquals("Could not find 0 processor: " + s, 0, s.size());
s = mbsc.queryNames(new ObjectName(domainName + ":type=routes,*"), null);
assertEquals("Could not find 0 route: " + s, 0, s.size());
}
use of javax.management.ObjectName in project camel by apache.
the class JmxInstrumentationOnlyRegisterProcessorWithCustomIdTest method testCustomId.
public void testCustomId() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
Set<ObjectName> s = server.queryNames(new ObjectName(domainName + ":type=endpoints,*"), null);
assertEquals("Could not find 2 endpoints: " + s, 6, s.size());
s = server.queryNames(new ObjectName(domainName + ":type=context,*"), null);
assertEquals("Could not find 1 context: " + s, 1, s.size());
s = server.queryNames(new ObjectName(domainName + ":type=processors,*"), null);
assertEquals("Could not find 1 processor: " + s, 1, s.size());
// should be mock foo
ObjectName on = s.iterator().next();
String id = (String) server.getAttribute(on, "ProcessorId");
assertEquals("myfoo", id);
s = server.queryNames(new ObjectName(domainName + ":type=routes,*"), null);
assertEquals("Could not find 2 route: " + s, 2, s.size());
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
}
use of javax.management.ObjectName in project camel by apache.
the class JmxInstrumentationUsingPlatformMBSTest method testMBeanServerType.
@Override
public void testMBeanServerType() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
try {
mbsc.getMBeanInfo(new ObjectName("java.lang:type=OperatingSystem"));
// should not get here
assertFalse(true);
} catch (InstanceNotFoundException e) {
// expected
}
}
Aggregations