Search in sources :

Example 66 with MBeanServer

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

the class RemoveRouteDefinitionTest method testShutdownRoute.

@SuppressWarnings("deprecation")
public void testShutdownRoute() 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.shutdownRoute("route1");
    // route is shutdown (= also removed), so its not longer in JMX
    set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(0, set.size());
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) ArrayList(java.util.ArrayList) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 67 with MBeanServer

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

the class RemoveRouteDefinitionTest method testStopAndRemoveRoute.

public void testStopAndRemoveRoute() 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);
    // must stop before we can remove
    context.stopRoute("route1");
    context.removeRoute("route1");
    // route is removed, so its not longer in JMX
    set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(0, set.size());
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) ArrayList(java.util.ArrayList) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 68 with MBeanServer

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

the class TwoManagedCamelContextAutoAssignedNameClashTest method testTwoManagedCamelContextClash.

public void testTwoManagedCamelContextClash() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    camel1 = createCamelContext();
    camel1.start();
    assertTrue("Should be started", camel1.getStatus().isStarted());
    MBeanServer mbeanServer = camel1.getManagementStrategy().getManagementAgent().getMBeanServer();
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=" + camel1.getManagementName() + ",type=context,name=\"camel-1\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on));
    // now cheat and reset the counter so we can test for a clash
    DefaultCamelContextNameStrategy.setCounter(0);
    camel2 = createCamelContext();
    camel2.start();
    ObjectName on2 = ObjectName.getInstance("org.apache.camel:context=" + camel2.getManagementName() + ",type=context,name=\"camel-1\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on2));
    assertTrue("Should still be registered after name clash", mbeanServer.isRegistered(on));
    assertTrue("Should still be registered after name clash", mbeanServer.isRegistered(on2));
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 69 with MBeanServer

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

the class TwoManagedCamelContextClashTest method testTwoManagedCamelContextNoClashCustomPattern.

public void testTwoManagedCamelContextNoClashCustomPattern() throws Exception {
    camel1 = createCamelContext("foo", "killer-#counter#");
    camel2 = createCamelContext("foo", "killer-#counter#");
    camel1.start();
    assertTrue("Should be started", camel1.getStatus().isStarted());
    MBeanServer mbeanServer = camel1.getManagementStrategy().getManagementAgent().getMBeanServer();
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=" + camel1.getManagementName() + ",type=context,name=\"foo\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on));
    // the pattern has a counter so no clash
    camel2.start();
    ObjectName on2 = ObjectName.getInstance("org.apache.camel:context=" + camel2.getManagementName() + ",type=context,name=\"foo\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on2));
    assertTrue("Should still be registered after name clash", mbeanServer.isRegistered(on));
    assertTrue("Should still be registered after name clash", mbeanServer.isRegistered(on2));
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 70 with MBeanServer

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

the class TwoManagedCamelContextTest method testTwoManagedCamelContext.

public void testTwoManagedCamelContext() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    camel1 = createCamelContext("foo");
    camel2 = createCamelContext("bar");
    camel1.start();
    camel2.start();
    MBeanServer mbeanServer = camel1.getManagementStrategy().getManagementAgent().getMBeanServer();
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=foo,type=context,name=\"foo\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on));
    ObjectName on2 = ObjectName.getInstance("org.apache.camel:context=bar,type=context,name=\"bar\"");
    assertTrue("Should be registered", mbeanServer.isRegistered(on2));
    camel1.stop();
    camel2.stop();
    assertFalse("Should be unregistered", mbeanServer.isRegistered(on));
    assertFalse("Should be unregistered", mbeanServer.isRegistered(on2));
}
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