Search in sources :

Example 91 with ObjectName

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

the class ManagedThrottlingInflightRoutePolicyTest 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);
    // should have route policy
    String policy = (String) mbeanServer.getAttribute(on, "RoutePolicyList");
    assertNotNull(policy);
    assertTrue("Should be a throttling, was: " + policy, policy.startsWith("ThrottlingInflightRoutePolicy"));
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 92 with ObjectName

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

the class ManagedTopicLoadBalancerTest method testManageTopicLoadBalancer.

public void testManageTopicLoadBalancer() 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();
    // 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);
    Integer size = (Integer) mbeanServer.getAttribute(on, "Size");
    assertEquals(2, size.intValue());
    TabularData 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(5, data.size());
    String json = (String) mbeanServer.invoke(on, "informationJson", null, null);
    assertNotNull(json);
    assertTrue(json.contains("\"description\": \"Balances message processing among a number of nodes"));
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Example 93 with ObjectName

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

the class ManagedTransformerRegistryTest method testManageTransformerRegistry.

public void testManageTransformerRegistry() 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();
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=services,*"), null);
    List<ObjectName> list = new ArrayList<ObjectName>(set);
    ObjectName on = null;
    for (ObjectName name : list) {
        if (name.getCanonicalName().contains("DefaultTransformerRegistry")) {
            on = name;
            break;
        }
    }
    assertNotNull("Should have found TransformerRegistry", on);
    Integer max = (Integer) mbeanServer.getAttribute(on, "MaximumCacheSize");
    assertEquals(1000, max.intValue());
    Integer current = (Integer) mbeanServer.getAttribute(on, "Size");
    assertEquals(3, current.intValue());
    current = (Integer) mbeanServer.getAttribute(on, "StaticSize");
    assertEquals(0, current.intValue());
    current = (Integer) mbeanServer.getAttribute(on, "DynamicSize");
    assertEquals(3, current.intValue());
    String source = (String) mbeanServer.getAttribute(on, "Source");
    assertTrue(source.startsWith("TransformerRegistry"));
    assertTrue(source.endsWith("capacity: 1000"));
    TabularData data = (TabularData) mbeanServer.invoke(on, "listTransformers", null, null);
    for (Object row : data.values()) {
        CompositeData composite = (CompositeData) row;
        String scheme = (String) composite.get("scheme");
        String from = (String) composite.get("from");
        String to = (String) composite.get("to");
        String description = (String) composite.get("description");
        boolean isStatic = (boolean) composite.get("static");
        boolean isDynamic = (boolean) composite.get("dynamic");
        LOG.info("[{}][{}][{}][{}][{}][{}]", scheme, from, to, isStatic, isDynamic, description);
        if (description.startsWith("ProcessorTransformer")) {
            assertEquals(null, scheme);
            assertEquals("xml:foo", from);
            assertEquals("json:bar", to);
        } else if (description.startsWith("DataFormatTransformer")) {
            assertEquals(null, scheme);
            assertEquals("java:" + ManagedTransformerRegistryTest.class.getName(), from);
            assertEquals("xml:test", to);
        } else if (description.startsWith("MyTransformer")) {
            assertEquals("custom", scheme);
            assertEquals(null, from);
            assertEquals(null, to);
        } else {
            fail("Unexpected transformer:" + description);
        }
    }
    assertEquals(3, data.size());
}
Also used : CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Example 94 with ObjectName

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

the class ManagedTypeConverterRegistryTest method testTypeConverterRegistry.

public void testTypeConverterRegistry() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    getMockEndpoint("mock:a").expectedMessageCount(2);
    template.sendBody("direct:start", "3");
    template.sendBody("direct:start", "7");
    assertMockEndpointsSatisfied();
    MBeanServer mbeanServer = getMBeanServer();
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=services,*");
    // number of services
    Set<ObjectName> names = mbeanServer.queryNames(on, null);
    ObjectName name = null;
    for (ObjectName service : names) {
        if (service.toString().contains("DefaultTypeConverter")) {
            name = service;
            break;
        }
    }
    assertNotNull("Cannot find DefaultTypeConverter", name);
    // is disabled by default
    Boolean enabled = (Boolean) mbeanServer.getAttribute(name, "StatisticsEnabled");
    assertEquals(Boolean.FALSE, enabled);
    // need to enable statistics
    mbeanServer.setAttribute(name, new Attribute("StatisticsEnabled", Boolean.TRUE));
    Long failed = (Long) mbeanServer.getAttribute(name, "FailedCounter");
    assertEquals(0, failed.intValue());
    Long miss = (Long) mbeanServer.getAttribute(name, "MissCounter");
    assertEquals(0, miss.intValue());
    try {
        template.sendBody("direct:start", "foo");
        fail("Should have thrown exception");
    } catch (Exception e) {
    // expected
    }
    // should now have a failed
    failed = (Long) mbeanServer.getAttribute(name, "FailedCounter");
    assertEquals(1, failed.intValue());
    miss = (Long) mbeanServer.getAttribute(name, "MissCounter");
    assertEquals(0, miss.intValue());
    // reset
    mbeanServer.invoke(name, "resetTypeConversionCounters", null, null);
    failed = (Long) mbeanServer.getAttribute(name, "FailedCounter");
    assertEquals(0, failed.intValue());
    miss = (Long) mbeanServer.getAttribute(name, "MissCounter");
    assertEquals(0, miss.intValue());
    // we have more than 150 converters out of the box
    Integer converters = (Integer) mbeanServer.getAttribute(name, "NumberOfTypeConverters");
    assertTrue("Should be more than 150 converters, was: " + converters, converters >= 150);
    Boolean has = (Boolean) mbeanServer.invoke(name, "hasTypeConverter", new Object[] { "String", "java.io.InputStream" }, new String[] { "java.lang.String", "java.lang.String" });
    assertTrue("Should have type converter", has.booleanValue());
    has = (Boolean) mbeanServer.invoke(name, "hasTypeConverter", new Object[] { "java.math.BigInteger", "int" }, new String[] { "java.lang.String", "java.lang.String" });
    assertFalse("Should not have type converter", has.booleanValue());
    // we have more than 150 converters out of the box
    TabularData data = (TabularData) mbeanServer.invoke(name, "listTypeConverters", null, null);
    assertTrue("Should be more than 150 converters, was: " + data.size(), data.size() >= 150);
}
Also used : Attribute(javax.management.Attribute) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Example 95 with ObjectName

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

the class ManagedRouteStopAndStartCleanupTest method testStopAndStartRoute.

public void testStopAndStartRoute() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MBeanServer mbeanServer = getMBeanServer();
    ObjectName on = getRouteObjectName(mbeanServer);
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    template.sendBodyAndHeader("file://target/managed", "Hello World", Exchange.FILE_NAME, "hello.txt");
    assertMockEndpointsSatisfied();
    // should be started
    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("Should be started", ServiceStatus.Started.name(), state);
    // need a bit time to let JMX update
    Thread.sleep(1000);
    // should have 1 completed exchange
    Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(1, completed.longValue());
    // should be 1 consumer and 2 processors
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=consumers,*"), null);
    assertEquals("Should be 1 consumer", 1, set.size());
    set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), null);
    assertEquals("Should be 2 processors", 2, set.size());
    // stop
    log.info(">>>>>>>>>>>>>>>>>> invoking stop <<<<<<<<<<<<<<<<<<<<<");
    mbeanServer.invoke(on, "stop", null, null);
    log.info(">>>>>>>>>>>>>>>>>> invoking stop DONE <<<<<<<<<<<<<<<<<<<<<");
    state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("Should be stopped", ServiceStatus.Stopped.name(), state);
    // should be 0 consumer and 0 processor
    set = mbeanServer.queryNames(new ObjectName("*:type=consumers,*"), null);
    assertEquals("Should be 0 consumer", 0, set.size());
    set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), null);
    assertEquals("Should be 0 processor", 0, set.size());
    mock.reset();
    mock.expectedBodiesReceived("Bye World");
    // wait 3 seconds while route is stopped to verify that file was not consumed
    mock.setResultWaitTime(3000);
    template.sendBodyAndHeader("file://target/managed", "Bye World", Exchange.FILE_NAME, "bye.txt");
    // route is stopped so we do not get the file
    mock.assertIsNotSatisfied();
    // prepare mock for starting route
    mock.reset();
    mock.expectedBodiesReceived("Bye World");
    // start
    log.info(">>>>>>>>>>>>>>>>> invoking start <<<<<<<<<<<<<<<<<<");
    mbeanServer.invoke(on, "start", null, null);
    log.info(">>>>>>>>>>>>>>>>> invoking start DONE <<<<<<<<<<<<<<<<<<");
    state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("Should be started", ServiceStatus.Started.name(), state);
    // should be 1 consumer and 1 processor
    set = mbeanServer.queryNames(new ObjectName("*:type=consumers,*"), null);
    assertEquals("Should be 1 consumer", 1, set.size());
    set = mbeanServer.queryNames(new ObjectName("*:type=processors,*"), null);
    assertEquals("Should be 2 processors", 2, set.size());
    // this time the file is consumed
    mock.assertIsSatisfied();
    // need a bit time to let JMX update
    Thread.sleep(1000);
    // should have 2 completed exchange
    completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
    assertEquals(2, completed.longValue());
}
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