Search in sources :

Example 96 with MBeanServer

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

the class ManagedSendProcessorTest method testManageSendProcessor.

public void testManageSendProcessor() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedMessageCount(1);
    MockEndpoint foo = getMockEndpoint("mock:foo");
    foo.expectedMessageCount(0);
    template.sendBody("direct:start", "Hello World");
    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 destination = (String) mbeanServer.getAttribute(on, "Destination");
    assertEquals("mock://result", destination);
    String pattern = (String) mbeanServer.getAttribute(on, "MessageExchangePattern");
    assertNull(pattern);
    TabularData data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { false }, new String[] { "boolean" });
    assertNotNull(data);
    assertEquals(2, data.size());
    data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { true }, new String[] { "boolean" });
    assertNotNull(data);
    assertEquals(5, data.size());
    String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
    assertNotNull(json);
    assertTrue(json.contains("\"description\": \"Sends the message to a static endpoint\""));
    assertTrue(json.contains(" \"uri\": { \"kind\": \"attribute\", \"required\": \"true\", \"type\": \"string\", \"javaType\": \"java.lang.String\"," + " \"deprecated\": \"false\", \"value\": \"mock:result\""));
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Example 97 with MBeanServer

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

the class ManagedRoundRobinLoadBalancerTest method testManageRoundRobinLoadBalancer.

public void testManageRoundRobinLoadBalancer() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MockEndpoint foo = getMockEndpoint("mock:foo");
    foo.expectedMessageCount(1);
    MockEndpoint bar = getMockEndpoint("mock:bar");
    bar.expectedMessageCount(1);
    template.sendBodyAndHeader("direct:start", "Hello World", "foo", "123");
    template.sendBodyAndHeader("direct:start", "Bye World", "foo", "123");
    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);
    Integer size = (Integer) mbeanServer.getAttribute(on, "Size");
    assertEquals(2, size.intValue());
    String last = (String) mbeanServer.getAttribute(on, "LastChosenProcessorId");
    assertEquals("bar", last);
    TabularData data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { false }, new String[] { "boolean" });
    assertNotNull(data);
    assertEquals(2, data.size());
    data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { true }, new String[] { "boolean" });
    assertNotNull(data);
    assertEquals(5, data.size());
    String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
    assertNotNull(json);
    assertTrue(json.contains("\"description\": \"Balances message processing among a number of nodes"));
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Example 98 with MBeanServer

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

the class ManagedRouteAddRemoveTest method testRouteAddRemoteRouteWithRecipientListAndRouteScopedOnException.

public void testRouteAddRemoteRouteWithRecipientListAndRouteScopedOnException() throws Exception {
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    result.assertIsSatisfied();
    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);
    assertEquals(services, names.size());
    log.info("Adding 2nd route");
    // add a 2nd route
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:bar").routeId("bar").onException(Exception.class).handled(true).recipientList(header("error")).end().end().recipientList(header("bar")).throwException(new IllegalArgumentException("Forced"));
        }
    });
    // and send a message to it
    getMockEndpoint("mock:bar").expectedMessageCount(1);
    getMockEndpoint("mock:error").expectedMessageCount(1);
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("error", "mock:error");
    headers.put("bar", "mock:bar");
    template.sendBodyAndHeaders("direct:bar", "Hello World", headers);
    assertMockEndpointsSatisfied();
    // there should still be the same number of services
    names = mbeanServer.queryNames(on, null);
    assertEquals(services, names.size());
    // now stop and remove the 2nd route
    log.info("Stopping 2nd route");
    context.stopRoute("bar");
    log.info("Removing 2nd route");
    boolean removed = context.removeRoute("bar");
    assertTrue(removed);
    // there should still be the same number of services
    names = mbeanServer.queryNames(on, null);
    assertEquals(services, names.size());
    log.info("Shutting down...");
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) HashMap(java.util.HashMap) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Example 99 with MBeanServer

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

the class ManagedRouteAddRemoveTest method testRouteAddRemoteRouteWithRecipientList.

public void testRouteAddRemoteRouteWithRecipientList() throws Exception {
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    result.assertIsSatisfied();
    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);
    assertEquals(services, names.size());
    // number of producers
    ObjectName onP = ObjectName.getInstance("org.apache.camel:context=camel-1,type=producers,*");
    Set<ObjectName> namesP = mbeanServer.queryNames(onP, null);
    assertEquals(1, namesP.size());
    log.info("Adding 2nd route");
    // add a 2nd route
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:bar").routeId("bar").recipientList(header("bar"));
        }
    });
    // and send a message to it
    MockEndpoint bar = getMockEndpoint("mock:bar");
    bar.expectedMessageCount(1);
    template.sendBodyAndHeader("direct:bar", "Hello World", "bar", "mock:bar");
    bar.assertIsSatisfied();
    // there should still be the same number of services
    names = mbeanServer.queryNames(on, null);
    assertEquals(services, names.size());
    // but as its recipient list which is dynamic-to we do not add a new producer
    namesP = mbeanServer.queryNames(onP, null);
    assertEquals(1, namesP.size());
    log.info("Removing 2nd route");
    // now remove the 2nd route
    context.stopRoute("bar");
    boolean removed = context.removeRoute("bar");
    assertTrue(removed);
    // there should still be the same number of services
    names = mbeanServer.queryNames(on, null);
    assertEquals(services, names.size());
    // and we still have the original producer
    namesP = mbeanServer.queryNames(onP, null);
    assertEquals(1, namesP.size());
    log.info("Shutting down...");
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 100 with MBeanServer

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

the class ManagedRouteAutoStartupTest 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\"");
    ObjectName onFoo = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"foo\"");
    ObjectName onBar = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"bar\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on));
    String name = (String) mbeanServer.getAttribute(on, "CamelId");
    assertEquals("camel-1", name);
    String state = (String) mbeanServer.getAttribute(onFoo, "State");
    assertEquals("Stopped", state);
    state = (String) mbeanServer.getAttribute(onBar, "State");
    assertEquals("Started", state);
    // start the route
    mbeanServer.invoke(onFoo, "start", null, null);
    state = (String) mbeanServer.getAttribute(onFoo, "State");
    assertEquals("Started", state);
    Object reply = mbeanServer.invoke(on, "requestBody", new Object[] { "direct:foo", "Hello World" }, new String[] { "java.lang.String", "java.lang.Object" });
    assertEquals("Bye World", reply);
    // stop Camel
    mbeanServer.invoke(on, "stop", null, null);
}
Also used : 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