Search in sources :

Example 71 with ObjectName

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

the class ManagedWireTapTest method testManageWireTap.

public void testManageWireTap() 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", "foo");
    template.sendBodyAndHeader("direct:start", "Bye World", "whereto", "foo");
    template.sendBodyAndHeader("direct:start", "Hi World", "whereto", "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 uri = (String) mbeanServer.getAttribute(on, "Uri");
    assertEquals("direct:${header.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(3, data.size());
    data = (TabularData) mbeanServer.invoke(on, "explain", new Object[] { true }, new String[] { "boolean" });
    assertNotNull(data);
    assertEquals(11, data.size());
    String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
    assertNotNull(json);
    assertTrue(json.contains("\"description\": \"Routes a copy of a message (or creates a new message) to a secondary destination while continue routing the original message"));
    assertTrue(json.contains(" \"uri\": { \"kind\": \"attribute\", \"required\": \"true\", \"type\": \"string\", \"javaType\": \"java.lang.String\"," + " \"deprecated\": \"false\", \"value\": \"direct:${header.whereto}\""));
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Example 72 with ObjectName

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

the class MultiInstanceProcessorTest method testCounters.

@Override
public void testCounters() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:end", MockEndpoint.class);
    resultEndpoint.expectedBodiesReceived("<hello>world!</hello>", "<hello>world!</hello>");
    sendBody("direct:start", "<hello>world!</hello>");
    resultEndpoint.assertIsSatisfied();
    verifyCounter(mbsc, new ObjectName(domainName + ":type=routes,*"));
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ObjectName(javax.management.ObjectName)

Example 73 with ObjectName

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

the class MultiInstanceProcessorTest method testMBeansRegistered.

/**
     * It retrieves a mbean for each "to" processor instance in the query ":type=processor"
     */
@Override
public void testMBeansRegistered() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    assertDefaultDomain();
    resolveMandatoryEndpoint("mock:end", MockEndpoint.class);
    Set<ObjectName> s = mbsc.queryNames(new ObjectName(domainName + ":type=endpoints,*"), null);
    assertEquals("Could not find 2 endpoints: " + s, 2, s.size());
    s = mbsc.queryNames(new ObjectName(domainName + ":type=context,*"), null);
    assertEquals("Could not find 1 context: " + s, 1, s.size());
    s = mbsc.queryNames(new ObjectName(domainName + ":type=processors,*"), null);
    assertEquals("Could not find 3 processor: " + s, 3, s.size());
    s = mbsc.queryNames(new ObjectName(domainName + ":type=routes,*"), null);
    assertEquals("Could not find 1 route: " + s, 1, s.size());
}
Also used : ObjectName(javax.management.ObjectName)

Example 74 with ObjectName

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

the class RemoveRouteDefinitionTest method testStopRoute.

public void testStopRoute() 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.stopRoute("route1");
    // route is only stopped so its still in JMX
    set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(1, set.size());
}
Also used : RouteDefinition(org.apache.camel.model.RouteDefinition) ArrayList(java.util.ArrayList) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 75 with ObjectName

use of javax.management.ObjectName 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)

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