Search in sources :

Example 61 with ObjectName

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

the class ManagedCBRTest method testManagedCBR.

// CAMEL-4044: mbeans not registered for children of choice
public void testManagedCBR() 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=routes,name=\"route\"");
    assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
    on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"task-a\"");
    assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
    on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"choice\"");
    assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
    on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"task-b\"");
    assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
    on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"task-c\"");
    assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
    on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"task-d\"");
    assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
    on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"task-e\"");
    assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
    on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"task-done\"");
    assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 62 with ObjectName

use of javax.management.ObjectName 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 63 with ObjectName

use of javax.management.ObjectName 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 64 with ObjectName

use of javax.management.ObjectName 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 65 with ObjectName

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

Aggregations

ObjectName (javax.management.ObjectName)1515 MBeanServer (javax.management.MBeanServer)691 Test (org.junit.Test)258 MalformedObjectNameException (javax.management.MalformedObjectNameException)168 IOException (java.io.IOException)101 HashMap (java.util.HashMap)99 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)97 Attribute (javax.management.Attribute)94 InstanceNotFoundException (javax.management.InstanceNotFoundException)94 ArrayList (java.util.ArrayList)91 MBeanServerConnection (javax.management.MBeanServerConnection)72 Map (java.util.Map)66 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)66 MBeanInfo (javax.management.MBeanInfo)64 TabularData (javax.management.openmbean.TabularData)55 JMXServiceURL (javax.management.remote.JMXServiceURL)55 MBeanRegistrationException (javax.management.MBeanRegistrationException)53 JMXConnector (javax.management.remote.JMXConnector)53 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)48 Notification (javax.management.Notification)47