Search in sources :

Example 56 with MBeanServer

use of javax.management.MBeanServer in project camel by apache.

the class ManagedCamelContextDumpRoutesCoverageAsXml method testRouteCoverageStats.

public void testRouteCoverageStats() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=context,name=\"camel-1\"");
    getMockEndpoint("mock:foo").expectedMessageCount(1);
    getMockEndpoint("mock:bar").expectedMessageCount(2);
    template.asyncSendBody("direct:start", "Hello World");
    template.asyncSendBody("direct:bar", "Hi World");
    template.asyncSendBody("direct:bar", "Bye World");
    assertMockEndpointsSatisfied();
    String xml = (String) mbeanServer.invoke(on, "dumpRoutesCoverageAsXml", null, null);
    log.info(xml);
    assertTrue(xml.contains("exchangesTotal=\"3\""));
    assertTrue(xml.contains("exchangesTotal=\"2\""));
    // should be valid XML
    Document doc = context.getTypeConverter().convertTo(Document.class, xml);
    assertNotNull(doc);
}
Also used : Document(org.w3c.dom.Document) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 57 with MBeanServer

use of javax.management.MBeanServer in project camel by apache.

the class BacklogTracerTest method testBacklogTracerNotRemoveOnDump.

@SuppressWarnings("unchecked")
public void testBacklogTracerNotRemoveOnDump() 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 removeOnDump = (Boolean) mbeanServer.getAttribute(on, "RemoveOnDump");
    assertEquals(Boolean.TRUE, removeOnDump);
    // disable it
    mbeanServer.setAttribute(on, new Attribute("RemoveOnDump", Boolean.FALSE));
    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();
    List<BacklogTracerEventMessage> events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpAllTracedMessages", null, null);
    assertNotNull(events);
    assertEquals(6, events.size());
    // and if we get again they are still there
    events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpAllTracedMessages", null, null);
    assertNotNull(events);
    assertEquals(6, events.size());
    // send in another message
    resetMocks();
    getMockEndpoint("mock:foo").expectedMessageCount(1);
    getMockEndpoint("mock:bar").expectedMessageCount(1);
    template.sendBody("direct:start", "Hi World");
    assertMockEndpointsSatisfied();
    // and now we should have 3 more messages
    events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpAllTracedMessages", null, null);
    assertNotNull(events);
    assertEquals(9, events.size());
}
Also used : 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 58 with MBeanServer

use of javax.management.MBeanServer 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 59 with MBeanServer

use of javax.management.MBeanServer 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 60 with MBeanServer

use of javax.management.MBeanServer 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)

Aggregations

MBeanServer (javax.management.MBeanServer)830 ObjectName (javax.management.ObjectName)690 Test (org.junit.Test)143 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)93 MalformedObjectNameException (javax.management.MalformedObjectNameException)62 JMXServiceURL (javax.management.remote.JMXServiceURL)60 Attribute (javax.management.Attribute)56 IOException (java.io.IOException)54 HashMap (java.util.HashMap)51 TabularData (javax.management.openmbean.TabularData)51 JMXConnectorServer (javax.management.remote.JMXConnectorServer)44 JMXConnector (javax.management.remote.JMXConnector)37 ArrayList (java.util.ArrayList)35 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)34 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)34 InstanceNotFoundException (javax.management.InstanceNotFoundException)32 MBeanRegistrationException (javax.management.MBeanRegistrationException)29 Map (java.util.Map)28 MBeanServerConnection (javax.management.MBeanServerConnection)28 LocalMBeanServer (org.apache.openejb.monitoring.LocalMBeanServer)28