Search in sources :

Example 66 with ObjectName

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

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

the class JmxInstrumentationCustomMBeanTest method testManagedEndpoint.

public void testManagedEndpoint() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    assertDefaultDomain();
    resolveMandatoryEndpoint("direct:start", DirectEndpoint.class);
    ObjectName objName = new ObjectName(domainName + ":type=endpoints,*");
    Set<ObjectName> s = mbsc.queryNames(objName, null);
    assertEquals(2, s.size());
}
Also used : ObjectName(javax.management.ObjectName)

Example 68 with ObjectName

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

the class ManagedCamelContextPropertiesTest method testGetSetProperties.

public void testGetSetProperties() 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=19-camel-1,type=context,name=\"camel-1\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on));
    String name = (String) mbeanServer.getAttribute(on, "CamelId");
    assertEquals("camel-1", name);
    // invoke operations
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    mbeanServer.invoke(on, "setProperty", new String[] { Exchange.LOG_DEBUG_BODY_MAX_CHARS, "-1" }, new String[] { "java.lang.String", "java.lang.String" });
    mbeanServer.invoke(on, "setProperty", new String[] { Exchange.LOG_DEBUG_BODY_STREAMS, "true" }, new String[] { "java.lang.String", "java.lang.String" });
    Object invoke = mbeanServer.invoke(on, "getProperty", new String[] { Exchange.LOG_DEBUG_BODY_MAX_CHARS }, new String[] { "java.lang.String" });
    assertEquals("-1", invoke);
    invoke = mbeanServer.invoke(on, "getProperty", new String[] { Exchange.LOG_DEBUG_BODY_STREAMS }, new String[] { "java.lang.String" });
    assertEquals("true", invoke);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 69 with ObjectName

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

the class ManagedCamelContextSuspendResumeTest method testManagedCamelContext.

public void testManagedCamelContext() 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=context,name=\"camel-1\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on));
    String name = (String) mbeanServer.getAttribute(on, "CamelId");
    assertEquals("camel-1", name);
    String uptime = (String) mbeanServer.getAttribute(on, "Uptime");
    assertNotNull(uptime);
    long uptimeMillis = (Long) mbeanServer.getAttribute(on, "UptimeMillis");
    assertTrue(uptimeMillis > 0);
    String status = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("Started", status);
    // invoke operations
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    Object reply = mbeanServer.invoke(on, "requestBody", new Object[] { "direct:foo", "Hello World" }, new String[] { "java.lang.String", "java.lang.Object" });
    assertEquals("Bye World", reply);
    // suspend Camel
    mbeanServer.invoke(on, "suspend", null, null);
    status = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("Suspended", status);
    // resume Camel
    mbeanServer.invoke(on, "resume", null, null);
    status = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("Started", status);
    reply = mbeanServer.invoke(on, "requestBody", new Object[] { "direct:foo", "Hello Camel" }, new String[] { "java.lang.String", "java.lang.Object" });
    assertEquals("Bye World", reply);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 70 with ObjectName

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

the class ManagedCamelContextTest method testManagedCamelContextExplainComponentModel.

public void testManagedCamelContextExplainComponentModel() 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=19-camel-1,type=context,name=\"camel-1\"");
    // get the json
    String json = (String) mbeanServer.invoke(on, "explainComponentJson", new Object[] { "seda", false }, new String[] { "java.lang.String", "boolean" });
    assertNotNull(json);
    assertTrue(json.contains("\"label\": \"core,endpoint\""));
    assertTrue(json.contains("\"queueSize\": { \"kind\": \"property\", \"group\": \"advanced\", \"label\": \"advanced\""));
}
Also used : 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