use of javax.management.Attribute in project camel by apache.
the class BacklogTracerTest 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);
assertTrue(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());
Boolean removeOnDump = (Boolean) mbeanServer.getAttribute(on, "RemoveOnDump");
assertEquals(Boolean.TRUE, removeOnDump);
// 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.sendBody("direct:start", "Bye World");
assertMockEndpointsSatisfied();
List<Exchange> exchanges = getMockEndpoint("mock:foo").getReceivedExchanges();
List<BacklogTracerEventMessage> events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages", new Object[] { "foo" }, new String[] { "java.lang.String" });
assertNotNull(events);
assertEquals(2, events.size());
BacklogTracerEventMessage event1 = events.get(0);
assertEquals("foo", event1.getToNode());
assertEquals(" <message exchangeId=\"" + exchanges.get(0).getExchangeId() + "\">\n" + " <body type=\"java.lang.String\">Hello World</body>\n" + " </message>", event1.getMessageAsXml());
BacklogTracerEventMessage event2 = events.get(1);
assertEquals("foo", event2.getToNode());
assertEquals(" <message exchangeId=\"" + exchanges.get(1).getExchangeId() + "\">\n" + " <body type=\"java.lang.String\">Bye World</body>\n" + " </message>", event2.getMessageAsXml());
}
use of javax.management.Attribute in project camel by apache.
the class BacklogTracerTest method testBacklogTracerEventMessageAsXml.
public void testBacklogTracerEventMessageAsXml() throws Exception {
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:foo").expectedMessageCount(2);
getMockEndpoint("mock:bar").expectedMessageCount(2);
template.sendBody("direct:start", "Hello World");
template.sendBody("direct:start", "Bye World");
assertMockEndpointsSatisfied();
String events = (String) mbeanServer.invoke(on, "dumpTracedMessagesAsXml", new Object[] { "foo" }, new String[] { "java.lang.String" });
assertNotNull(events);
log.info(events);
// should be valid XML
Document dom = context.getTypeConverter().convertTo(Document.class, events);
assertNotNull(dom);
NodeList list = dom.getElementsByTagName("backlogTracerEventMessage");
assertEquals(2, list.getLength());
}
use of javax.management.Attribute in project camel by apache.
the class BacklogTracerTest method testBacklogTracerEventMessageDumpAllAsXml.
public void testBacklogTracerEventMessageDumpAllAsXml() throws Exception {
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);
// 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.sendBody("direct:start", "Bye World");
assertMockEndpointsSatisfied();
String events = (String) mbeanServer.invoke(on, "dumpAllTracedMessagesAsXml", null, null);
assertNotNull(events);
log.info(events);
// should be valid XML
Document dom = context.getTypeConverter().convertTo(Document.class, events);
assertNotNull(dom);
NodeList list = dom.getElementsByTagName("backlogTracerEventMessage");
assertEquals(6, list.getLength());
}
use of javax.management.Attribute in project camel by apache.
the class ManagedTracerOptionsTest method doAssertFormatter.
private void doAssertFormatter(MBeanServer mbeanServer, ObjectName on) throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
mbeanServer.setAttribute(on, new Attribute("FormatterShowBody", Boolean.TRUE));
Boolean fsb = (Boolean) mbeanServer.getAttribute(on, "FormatterShowBody");
assertEquals(true, fsb.booleanValue());
mbeanServer.setAttribute(on, new Attribute("FormatterShowBodyType", Boolean.TRUE));
Boolean fsbt = (Boolean) mbeanServer.getAttribute(on, "FormatterShowBodyType");
assertEquals(true, fsbt.booleanValue());
mbeanServer.setAttribute(on, new Attribute("FormatterShowOutBody", Boolean.TRUE));
Boolean fsob = (Boolean) mbeanServer.getAttribute(on, "FormatterShowOutBody");
assertEquals(true, fsob.booleanValue());
mbeanServer.setAttribute(on, new Attribute("FormatterShowOutBodyType", Boolean.TRUE));
Boolean fsobt = (Boolean) mbeanServer.getAttribute(on, "FormatterShowOutBodyType");
assertEquals(true, fsobt.booleanValue());
mbeanServer.setAttribute(on, new Attribute("FormatterShowBreadCrumb", Boolean.TRUE));
Boolean fsbc = (Boolean) mbeanServer.getAttribute(on, "FormatterShowBreadCrumb");
assertEquals(true, fsbc.booleanValue());
mbeanServer.setAttribute(on, new Attribute("FormatterShowExchangeId", Boolean.TRUE));
Boolean fsei = (Boolean) mbeanServer.getAttribute(on, "FormatterShowExchangeId");
assertEquals(true, fsei.booleanValue());
mbeanServer.setAttribute(on, new Attribute("FormatterShowShortExchangeId", Boolean.TRUE));
Boolean fssei = (Boolean) mbeanServer.getAttribute(on, "FormatterShowShortExchangeId");
assertEquals(true, fssei.booleanValue());
mbeanServer.setAttribute(on, new Attribute("FormatterShowHeaders", Boolean.TRUE));
Boolean fsh = (Boolean) mbeanServer.getAttribute(on, "FormatterShowHeaders");
assertEquals(true, fsh.booleanValue());
mbeanServer.setAttribute(on, new Attribute("FormatterShowOutHeaders", Boolean.TRUE));
Boolean fsoh = (Boolean) mbeanServer.getAttribute(on, "FormatterShowOutHeaders");
assertEquals(true, fsoh.booleanValue());
mbeanServer.setAttribute(on, new Attribute("FormatterShowProperties", Boolean.TRUE));
Boolean fsp = (Boolean) mbeanServer.getAttribute(on, "FormatterShowProperties");
assertEquals(true, fsp.booleanValue());
mbeanServer.setAttribute(on, new Attribute("FormatterShowNode", Boolean.TRUE));
Boolean fsn = (Boolean) mbeanServer.getAttribute(on, "FormatterShowNode");
assertEquals(true, fsn.booleanValue());
mbeanServer.setAttribute(on, new Attribute("FormatterShowRouteId", Boolean.FALSE));
Boolean fsr = (Boolean) mbeanServer.getAttribute(on, "FormatterShowRouteId");
assertEquals(false, fsr.booleanValue());
mbeanServer.setAttribute(on, new Attribute("FormatterShowExchangePattern", Boolean.TRUE));
Boolean fsep = (Boolean) mbeanServer.getAttribute(on, "FormatterShowExchangePattern");
assertEquals(true, fsep.booleanValue());
mbeanServer.setAttribute(on, new Attribute("FormatterShowException", Boolean.TRUE));
Boolean fsex = (Boolean) mbeanServer.getAttribute(on, "FormatterShowException");
assertEquals(true, fsex.booleanValue());
mbeanServer.setAttribute(on, new Attribute("FormatterBreadCrumbLength", 100));
Integer fbcl = (Integer) mbeanServer.getAttribute(on, "FormatterBreadCrumbLength");
assertEquals(100, fbcl.intValue());
mbeanServer.setAttribute(on, new Attribute("FormatterNodeLength", 50));
Integer fnl = (Integer) mbeanServer.getAttribute(on, "FormatterNodeLength");
assertEquals(50, fnl.intValue());
mbeanServer.setAttribute(on, new Attribute("FormatterMaxChars", 250));
Integer fmc = (Integer) mbeanServer.getAttribute(on, "FormatterMaxChars");
assertEquals(250, fmc.intValue());
}
use of javax.management.Attribute 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);
}
Aggregations