Search in sources :

Example 11 with ObjectName

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

the class ManagedInflightStatisticsTest method testManageStatisticsFailed.

public void testManageStatisticsFailed() 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();
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(1, set.size());
    ObjectName on = set.iterator().next();
    Long inflight = (Long) mbeanServer.getAttribute(on, "ExchangesInflight");
    assertEquals(0, inflight.longValue());
    Long ts = (Long) mbeanServer.getAttribute(on, "OldestInflightDuration");
    assertNull(ts);
    String id = (String) mbeanServer.getAttribute(on, "OldestInflightExchangeId");
    assertNull(id);
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedMessageCount(1);
    // start some exchanges.
    template.asyncSendBody("direct:start", 1000L);
    Thread.sleep(500);
    try {
        template.sendBody("direct:start", "Kaboom");
        fail("Should have thrown exception");
    } catch (Exception e) {
    // expected
    }
    inflight = (Long) mbeanServer.getAttribute(on, "ExchangesInflight");
    assertEquals(1, inflight.longValue());
    ts = (Long) mbeanServer.getAttribute(on, "OldestInflightDuration");
    assertNotNull(ts);
    id = (String) mbeanServer.getAttribute(on, "OldestInflightExchangeId");
    assertNotNull(id);
    assertMockEndpointsSatisfied();
    // Lets wait for all the exchanges to complete.
    Thread.sleep(500);
    inflight = (Long) mbeanServer.getAttribute(on, "ExchangesInflight");
    assertEquals(0, inflight.longValue());
    ts = (Long) mbeanServer.getAttribute(on, "OldestInflightDuration");
    assertNull(ts);
    id = (String) mbeanServer.getAttribute(on, "OldestInflightExchangeId");
    assertNull(id);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 12 with ObjectName

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

the class ManagedListComponentsTest method testListComponents.

public void testListComponents() 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=20-camel-1,type=context,name=\"camel-1\"");
    // list all components found in classpath
    TabularData data = (TabularData) mbeanServer.invoke(on, "listComponents", null, null);
    assertTrue("There should be more than 20 components", data.size() > 20);
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Example 13 with ObjectName

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

the class ManagedLoadBalancerTest method testLoadBalancer.

public void testLoadBalancer() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    getMockEndpoint("mock:a").expectedBodiesReceived("Hello World", "Hi World");
    getMockEndpoint("mock:b").expectedBodiesReceived("Bye World");
    template.sendBody("direct:start", "Hello World");
    template.sendBody("direct:start", "Bye World");
    template.sendBody("direct:start", "Hi World");
    assertMockEndpointsSatisfied();
    MBeanServer mbeanServer = getMBeanServer();
    ObjectName name = ObjectName.getInstance("org.apache.camel:context=camel-1,type=endpoints,name=\"mock://a\"");
    Long queueSize = (Long) mbeanServer.invoke(name, "queueSize", null, null);
    assertEquals(2, queueSize.intValue());
    name = ObjectName.getInstance("org.apache.camel:context=camel-1,type=endpoints,name=\"mock://b\"");
    queueSize = (Long) mbeanServer.invoke(name, "queueSize", null, null);
    assertEquals(1, queueSize.intValue());
    name = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"myBalancer\"");
    mbeanServer.isRegistered(name);
    Long total = (Long) mbeanServer.getAttribute(name, "ExchangesTotal");
    assertEquals(3, total.intValue());
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 14 with ObjectName

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

the class ManagedCamelContextTest method testManagedCamelContextRemoveEndpoint.

public void testManagedCamelContextRemoveEndpoint() 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\"");
    assertNull(context.hasEndpoint("seda:bar"));
    // create a new endpoint
    Object reply = mbeanServer.invoke(on, "createEndpoint", new Object[] { "seda:bar" }, new String[] { "java.lang.String" });
    assertEquals(Boolean.TRUE, reply);
    assertNotNull(context.hasEndpoint("seda:bar"));
    ObjectName seda = ObjectName.getInstance("org.apache.camel:context=19-camel-1,type=endpoints,name=\"seda://bar\"");
    boolean registered = mbeanServer.isRegistered(seda);
    assertTrue("Should be registered " + seda, registered);
    // remove it
    Object num = mbeanServer.invoke(on, "removeEndpoints", new Object[] { "seda:*" }, new String[] { "java.lang.String" });
    assertEquals(1, num);
    assertNull(context.hasEndpoint("seda:bar"));
    registered = mbeanServer.isRegistered(seda);
    assertFalse("Should not be registered " + seda, registered);
    // remove it again
    num = mbeanServer.invoke(on, "removeEndpoints", new Object[] { "seda:*" }, new String[] { "java.lang.String" });
    assertEquals(0, num);
    assertNull(context.hasEndpoint("seda:bar"));
    registered = mbeanServer.isRegistered(seda);
    assertFalse("Should not be registered " + seda, registered);
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 15 with ObjectName

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

the class ManagedCamelContextTest method testManagedCamelContextExplainEipModel.

public void testManagedCamelContextExplainEipModel() 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, "explainEipJson", new Object[] { "aggregate", false }, new String[] { "java.lang.String", "boolean" });
    assertNotNull(json);
    assertTrue(json.contains("\"description\": \"Aggregates many messages into a single message\""));
    assertTrue(json.contains("\"label\": \"eip,routing\""));
    assertTrue(json.contains("\"correlationExpression\": { \"kind\": \"expression\", \"displayName\": \"Correlation Expression\", \"required\": true, \"type\": \"object\""));
    assertTrue(json.contains("\"discardOnCompletionTimeout\": { \"kind\": \"attribute\", \"displayName\": \"Discard On Completion Timeout\", \"required\": false, \"type\": \"boolean\""));
}
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