Search in sources :

Example 6 with Attribute

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());
}
Also used : Exchange(org.apache.camel.Exchange) BacklogTracerEventMessage(org.apache.camel.api.management.mbean.BacklogTracerEventMessage) Attribute(javax.management.Attribute) List(java.util.List) NodeList(org.w3c.dom.NodeList) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 7 with Attribute

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());
}
Also used : Attribute(javax.management.Attribute) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 8 with Attribute

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());
}
Also used : Attribute(javax.management.Attribute) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 9 with Attribute

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());
}
Also used : Attribute(javax.management.Attribute)

Example 10 with Attribute

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);
}
Also used : Attribute(javax.management.Attribute) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Aggregations

Attribute (javax.management.Attribute)157 ObjectName (javax.management.ObjectName)94 MBeanServer (javax.management.MBeanServer)56 AttributeList (javax.management.AttributeList)46 Test (org.junit.Test)38 ReflectionException (javax.management.ReflectionException)29 MBeanException (javax.management.MBeanException)25 HashMap (java.util.HashMap)23 InstanceNotFoundException (javax.management.InstanceNotFoundException)22 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)21 AttributeNotFoundException (javax.management.AttributeNotFoundException)20 MBeanServerConnection (javax.management.MBeanServerConnection)15 MBeanInfo (javax.management.MBeanInfo)14 JMXConnector (javax.management.remote.JMXConnector)13 RuntimeOperationsException (javax.management.RuntimeOperationsException)12 List (java.util.List)10 BacklogTracerEventMessage (org.apache.camel.api.management.mbean.BacklogTracerEventMessage)10 IOException (java.io.IOException)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 ArrayList (java.util.ArrayList)9