Search in sources :

Example 61 with MBeanServer

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

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

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

Example 64 with MBeanServer

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

the class ManagedWireTapTest method testManageWireTap.

public void testManageWireTap() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MockEndpoint foo = getMockEndpoint("mock:foo");
    foo.expectedMessageCount(2);
    MockEndpoint bar = getMockEndpoint("mock:bar");
    bar.expectedMessageCount(1);
    template.sendBodyAndHeader("direct:start", "Hello World", "whereto", "foo");
    template.sendBodyAndHeader("direct:start", "Bye World", "whereto", "foo");
    template.sendBodyAndHeader("direct:start", "Hi World", "whereto", "bar");
    assertMockEndpointsSatisfied();
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    // get the object name for the delayer
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mysend\"");
    // should be on route1
    String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
    assertEquals("route1", routeId);
    String camelId = (String) mbeanServer.getAttribute(on, "CamelId");
    assertEquals("camel-1", camelId);
    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals(ServiceStatus.Started.name(), state);
    String uri = (String) mbeanServer.getAttribute(on, "Uri");
    assertEquals("direct:${header.whereto}", uri);
    TabularData data = (TabularData) mbeanServer.invoke(on, "extendedInformation", null, null);
    assertNotNull(data);
    assertEquals(2, data.size());
    data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { false }, new String[] { "boolean" });
    assertNotNull(data);
    assertEquals(3, data.size());
    data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { true }, new String[] { "boolean" });
    assertNotNull(data);
    assertEquals(11, data.size());
    String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
    assertNotNull(json);
    assertTrue(json.contains("\"description\": \"Routes a copy of a message (or creates a new message) to a secondary destination while continue routing the original message"));
    assertTrue(json.contains(" \"uri\": { \"kind\": \"attribute\", \"required\": \"true\", \"type\": \"string\", \"javaType\": \"java.lang.String\"," + " \"deprecated\": \"false\", \"value\": \"direct:${header.whereto}\""));
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Example 65 with MBeanServer

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

the class RemoveRouteDefinitionTest method testStopRoute.

public void testStopRoute() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MBeanServer mbeanServer = getMBeanServer();
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(1, set.size());
    ObjectName on = set.iterator().next();
    boolean registered = mbeanServer.isRegistered(on);
    assertEquals("Should be registered", true, registered);
    RouteDefinition definition = context.getRouteDefinition("route1");
    List<RouteDefinition> routeDefinitions = new ArrayList<RouteDefinition>();
    routeDefinitions.add(definition);
    context.stopRoute("route1");
    // route is only stopped so its still in JMX
    set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(1, set.size());
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) ArrayList(java.util.ArrayList) 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