Search in sources :

Example 26 with ObjectName

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

the class ManagedDelayerTest method testManageDelay.

public void testManageDelay() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    // get the object name for the delayer
    ObjectName delayerName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mydelayer\"");
    // use route to get the total time
    ObjectName routeName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route1\"");
    Long completed = (Long) mbeanServer.getAttribute(routeName, "ExchangesCompleted");
    assertEquals(1, completed.longValue());
    Long last = (Long) mbeanServer.getAttribute(routeName, "LastProcessingTime");
    Long total = (Long) mbeanServer.getAttribute(routeName, "TotalProcessingTime");
    assertTrue("Should take around 1 sec: was " + last, last > 900);
    assertTrue("Should take around 1 sec: was " + total, total > 900);
    // change the delay time using JMX
    mbeanServer.invoke(delayerName, "constantDelay", new Object[] { 2000 }, new String[] { "java.lang.Integer" });
    // send in another message
    template.sendBody("direct:start", "Bye World");
    Long delay = (Long) mbeanServer.getAttribute(delayerName, "Delay");
    assertNotNull(delay);
    completed = (Long) mbeanServer.getAttribute(routeName, "ExchangesCompleted");
    assertEquals(2, completed.longValue());
    last = (Long) mbeanServer.getAttribute(routeName, "LastProcessingTime");
    total = (Long) mbeanServer.getAttribute(routeName, "TotalProcessingTime");
    assertTrue("Should take around 2 sec: was " + last, last > 1900);
    assertTrue("Should be around 3 sec now: was " + total, total > 2900);
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 27 with ObjectName

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

the class ManagedDynamicRouterTest method testManageDynamicRouter.

public void testManageDynamicRouter() 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", "direct:foo");
    template.sendBodyAndHeader("direct:start", "Bye World", "whereTo", "direct:foo");
    template.sendBodyAndHeader("direct:start", "Hi World", "whereTo", "direct: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 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(6, data.size());
    String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
    assertNotNull(json);
    assertTrue(json.contains("\"description\": \"Routes messages based on dynamic rules"));
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Example 28 with ObjectName

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

the class ManagedRegisterExchangeStatisticsTest 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=routes,name=\"route1\"");
    Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(0, completed.longValue());
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(1, completed.longValue());
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 29 with ObjectName

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

the class ManagedRegisterRouteTest method testRoutes.

public void testRoutes() 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);
    String uri = (String) mbeanServer.getAttribute(on, "EndpointUri");
    // the route has this starting endpoint uri
    assertEquals("direct://start", uri);
    Integer val = (Integer) mbeanServer.getAttribute(on, "InflightExchanges");
    // the route has no inflight exchanges
    assertEquals(0, val.intValue());
    // should be started
    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("Should be started", ServiceStatus.Started.name(), state);
    // stop the route
    context.stopRoute(context.getRouteDefinitions().get(0));
    registered = mbeanServer.isRegistered(on);
    assertEquals("Should be registered", true, registered);
    // should be stopped, eg its removed
    state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("Should be stopped", ServiceStatus.Stopped.name(), state);
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 30 with ObjectName

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

the class ManagedResourceTest method testManagedResource.

@Test
public void testManagedResource() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    final ManagementAgent managementAgent = context.getManagementStrategy().getManagementAgent();
    TestCase.assertNotNull(managementAgent);
    final MBeanServer mBeanServer = managementAgent.getMBeanServer();
    TestCase.assertNotNull(mBeanServer);
    final String mBeanServerDefaultDomain = managementAgent.getMBeanServerDefaultDomain();
    TestCase.assertEquals("org.apache.camel", mBeanServerDefaultDomain);
    final String managementName = context.getManagementName();
    TestCase.assertNotNull("CamelContext should have a management name if JMX is enabled", managementName);
    LOG.info("managementName = {}", managementName);
    // Get the Camel Context MBean
    ObjectName onContext = ObjectName.getInstance(mBeanServerDefaultDomain + ":context=" + managementName + ",type=context,name=\"" + context.getName() + "\"");
    TestCase.assertTrue("Should be registered", mBeanServer.isRegistered(onContext));
    // Get myManagedBean
    ObjectName onManagedBean = ObjectName.getInstance(mBeanServerDefaultDomain + ":context=" + managementName + ",type=processors,name=\"myManagedBean\"");
    LOG.info("Canonical Name = {}", onManagedBean.getCanonicalName());
    TestCase.assertTrue("Should be registered", mBeanServer.isRegistered(onManagedBean));
    // Send a couple of messages to get some route statistics
    template.sendBody("direct:start", "Hello Camel");
    template.sendBody("direct:start", "Camel Rocks!");
    // Get MBean attribute
    int camelsSeenCount = (Integer) mBeanServer.getAttribute(onManagedBean, "CamelsSeenCount");
    TestCase.assertEquals(2, camelsSeenCount);
    // Stop the route via JMX
    mBeanServer.invoke(onManagedBean, "resetCamelsSeenCount", null, null);
    camelsSeenCount = (Integer) mBeanServer.getAttribute(onManagedBean, "CamelsSeenCount");
    TestCase.assertEquals(0, camelsSeenCount);
    String camelId = (String) mBeanServer.getAttribute(onManagedBean, "CamelId");
    assertEquals(context.getName(), camelId);
    String state = (String) mBeanServer.getAttribute(onManagedBean, "State");
    assertEquals("Started", state);
    String fqn = (String) mBeanServer.getAttribute(onManagedBean, "BeanClassName");
    assertEquals(MyManagedBean.class.getCanonicalName(), fqn);
}
Also used : ManagementAgent(org.apache.camel.spi.ManagementAgent) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

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