Search in sources :

Example 76 with MBeanServer

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

the class ManagedThrottlerTest method testRejectedExecutionCallerRuns.

public void testRejectedExecutionCallerRuns() 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 throttlerName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mythrottler2\"");
    // use route to get the total time
    ObjectName routeName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route2\"");
    // reset the counters
    mbeanServer.invoke(routeName, "reset", null, null);
    MockEndpoint mock = getMockEndpoint("mock:endAsyncRejectCallerRuns");
    // only one message (the first one) should get through because the rest should get delayed
    mock.expectedMessageCount(10);
    MockEndpoint exceptionMock = getMockEndpoint("mock:rejectedExceptionEndpoint");
    exceptionMock.expectedMessageCount(0);
    for (int i = 0; i < 10; i++) {
        template.sendBody("seda:throttleCountRejectExecutionCallerRuns", "Message " + i);
    }
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 77 with MBeanServer

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

the class ManagedThrottlerTest method testThrottleVisableViaJmx.

public void testThrottleVisableViaJmx() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    if (isPlatform("windows")) {
        // windows needs more sleep to read updated jmx values so we skip as we dont want further delays in core tests
        return;
    }
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    // get the object name for the delayer
    ObjectName throttlerName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mythrottler2\"");
    // use route to get the total time
    ObjectName routeName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route2\"");
    // reset the counters
    mbeanServer.invoke(routeName, "reset", null, null);
    getMockEndpoint("mock:end").expectedMessageCount(10);
    NotifyBuilder notifier = new NotifyBuilder(context).from("seda:throttleCount").whenReceived(5).create();
    for (int i = 0; i < 10; i++) {
        template.sendBody("seda:throttleCount", "Message " + i);
    }
    assertTrue(notifier.matches(2, TimeUnit.SECONDS));
    assertMockEndpointsSatisfied();
    Long completed = (Long) mbeanServer.getAttribute(routeName, "ExchangesCompleted");
    assertEquals(10, completed.longValue());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 78 with MBeanServer

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

the class ManagedThrottlerTest method testRejectedExecution.

public void testRejectedExecution() 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 throttlerName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mythrottler2\"");
    // use route to get the total time
    ObjectName routeName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route2\"");
    // reset the counters
    mbeanServer.invoke(routeName, "reset", null, null);
    MockEndpoint mock = getMockEndpoint("mock:endAsyncReject");
    // only one message (the first one) should get through because the rest should get delayed
    mock.expectedMessageCount(1);
    MockEndpoint exceptionMock = getMockEndpoint("mock:rejectedExceptionEndpoint1");
    exceptionMock.expectedMessageCount(9);
    for (int i = 0; i < 10; i++) {
        template.sendBody("seda:throttleCountRejectExecution", "Message " + i);
    }
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 79 with MBeanServer

use of javax.management.MBeanServer 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 80 with MBeanServer

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

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