Search in sources :

Example 16 with ObjectName

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

the class ManagedCamelContextUpdateRoutesFromXmlTest method testDumpAsXml.

public void testDumpAsXml() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    MBeanServer mbeanServer = getMBeanServer();
    // there should be 1 routes to start with
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(1, set.size());
    // update existing route, and add a 2nd
    String xml = "<routes id=\"myRoute\" xmlns=\"http://camel.apache.org/schema/spring\">" + "<route id=\"myRoute\">" + "  <from uri=\"direct:start\"/>" + "  <log message=\"This is a changed route saying ${body}\"/>" + "  <to uri=\"mock:changed\"/>" + "</route>" + "<route id=\"myOtherRoute\">" + "  <from uri=\"seda:bar\"/>" + "  <to uri=\"mock:bar\"/>" + "</route>" + "</routes>";
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=context,name=\"camel-1\"");
    mbeanServer.invoke(on, "addOrUpdateRoutesFromXml", new Object[] { xml }, new String[] { "java.lang.String" });
    // there should be 2 routes now
    set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(2, set.size());
    // test updated route
    getMockEndpoint("mock:changed").expectedMessageCount(1);
    template.sendBody("direct:start", "Bye World");
    assertMockEndpointsSatisfied();
    // test new route
    getMockEndpoint("mock:bar").expectedMessageCount(1);
    template.sendBody("seda:bar", "Hi Camel");
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 17 with ObjectName

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

the class ManagedCanekContextExchangeStatisticsTest method testExchangesCompletedStatistics.

public void testExchangesCompletedStatistics() 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\"");
    Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(0, completed.longValue());
    ObjectName route1 = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route1\"");
    Long completed1 = (Long) mbeanServer.getAttribute(route1, "ExchangesCompleted");
    assertEquals(0, completed1.longValue());
    ObjectName route2 = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route2\"");
    Long completed2 = (Long) mbeanServer.getAttribute(route1, "ExchangesCompleted");
    assertEquals(0, completed2.longValue());
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    completed = (Long) mbeanServer.getAttribute(route1, "ExchangesCompleted");
    assertEquals(1, completed.longValue());
    completed1 = (Long) mbeanServer.getAttribute(route1, "ExchangesCompleted");
    assertEquals(1, completed1.longValue());
    completed2 = (Long) mbeanServer.getAttribute(route2, "ExchangesCompleted");
    assertEquals(0, completed2.longValue());
    resetMocks();
    getMockEndpoint("mock:result").expectedMessageCount(2);
    template.sendBody("direct:start", "Hi World");
    template.sendBody("direct:bar", "Bye World");
    assertMockEndpointsSatisfied();
    completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(3, completed.longValue());
    completed1 = (Long) mbeanServer.getAttribute(route1, "ExchangesCompleted");
    assertEquals(2, completed1.longValue());
    completed2 = (Long) mbeanServer.getAttribute(route2, "ExchangesCompleted");
    assertEquals(1, completed2.longValue());
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 18 with ObjectName

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

the class ManagedRecipientListTest method testManageRecipientList.

public void testManageRecipientList() 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", "mock:foo");
    template.sendBodyAndHeader("direct:start", "Bye World", "whereto", "mock:foo");
    template.sendBodyAndHeader("direct:start", "Hi World", "whereto", "mock: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);
    Boolean parallel = (Boolean) mbeanServer.getAttribute(on, "ParallelProcessing");
    assertEquals(false, parallel.booleanValue());
    String lan = (String) mbeanServer.getAttribute(on, "ExpressionLanguage");
    assertEquals("header", lan);
    String uri = (String) mbeanServer.getAttribute(on, "Expression");
    assertEquals("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(2, data.size());
    data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { true }, new String[] { "boolean" });
    assertNotNull(data);
    assertEquals(18, data.size());
    String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
    assertNotNull(json);
    assertTrue(json.contains("\"description\": \"Routes messages to a number of dynamically specified recipients (dynamic to)"));
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Example 19 with ObjectName

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

the class ManagedRedeliverRouteOnlyTest method testRedeliver.

public void testRedeliver() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MBeanServer mbeanServer = getMBeanServer();
    getMockEndpoint("mock:foo").expectedMessageCount(1);
    Object out = template.requestBody("direct:start", "Hello World");
    assertEquals("Error", out);
    assertMockEndpointsSatisfied();
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route1\"");
    Long num = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(1, num.longValue());
    num = (Long) mbeanServer.getAttribute(on, "ExchangesFailed");
    assertEquals(0, num.longValue());
    num = (Long) mbeanServer.getAttribute(on, "FailuresHandled");
    assertEquals(1, num.longValue());
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 20 with ObjectName

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

the class ManagedRefProducerTest method testProducer.

public void testProducer() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    // fire a message to get it running
    getMockEndpoint("mock:result").expectedMessageCount(1);
    getMockEndpoint("foo").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    MBeanServer mbeanServer = getMBeanServer();
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=producers,*"), null);
    assertEquals(2, set.size());
    Iterator<ObjectName> it = set.iterator();
    for (int i = 0; i < 2; i++) {
        ObjectName on = it.next();
        boolean registered = mbeanServer.isRegistered(on);
        assertEquals("Should be registered", true, registered);
        String uri = (String) mbeanServer.getAttribute(on, "EndpointUri");
        assertTrue(uri, uri.equals("mock://foo") || uri.equals("mock://result"));
        // should be started
        String state = (String) mbeanServer.getAttribute(on, "State");
        assertEquals("Should be started", ServiceStatus.Started.name(), state);
    }
    set = mbeanServer.queryNames(new ObjectName("*:type=endpoints,*"), null);
    assertEquals(4, set.size());
    it = set.iterator();
    for (int i = 0; i < 4; i++) {
        ObjectName on = it.next();
        boolean registered = mbeanServer.isRegistered(on);
        assertEquals("Should be registered", true, registered);
        String uri = (String) mbeanServer.getAttribute(on, "EndpointUri");
        assertTrue(uri, uri.equals("direct://start") || uri.equals("ref://foo") || uri.equals("mock://foo") || uri.equals("mock://result"));
    }
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) 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