Search in sources :

Example 96 with ObjectName

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

the class ManagedRouteStopAndStartTest 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);
    String id = (String) mbeanServer.getAttribute(on, "RouteId");
    assertEquals("foo", id);
    String description = (String) mbeanServer.getAttribute(on, "Description");
    assertEquals("This is the foo route", description);
    // stop
    mbeanServer.invoke(on, "stop", null, null);
    state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("Should be stopped", ServiceStatus.Stopped.name(), state);
    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
    mbeanServer.invoke(on, "start", null, null);
    state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("Should be started", ServiceStatus.Started.name(), state);
    // this time the file is consumed
    mock.assertIsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 97 with ObjectName

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

the class ManagedRouteStopUsingMBeanAPITest method testStopRoute.

public void testStopRoute() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    // fire a message to get it running
    getMockEndpoint("mock:result").expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    MBeanServer mbeanServer = getMBeanServer();
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(1, set.size());
    ObjectName on = set.iterator().next();
    ManagedRouteMBean mbean = context.getManagementStrategy().getManagementAgent().newProxyClient(on, ManagedRouteMBean.class);
    // the route has this starting endpoint uri
    assertEquals("direct://start", mbean.getEndpointUri());
    // should be started
    assertEquals("Should be started", ServiceStatus.Started.name(), mbean.getState());
    mbean.stop();
    // should be stopped
    assertEquals("Should be stopped", ServiceStatus.Stopped.name(), mbean.getState());
}
Also used : ManagedRouteMBean(org.apache.camel.api.management.mbean.ManagedRouteMBean) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 98 with ObjectName

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

the class ManagedRouteStopWithAbortAfterTimeoutTest method getRouteObjectName.

static ObjectName getRouteObjectName(MBeanServer mbeanServer) throws Exception {
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
    assertEquals(1, set.size());
    return set.iterator().next();
}
Also used : ObjectName(javax.management.ObjectName)

Example 99 with ObjectName

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

the class ManagedRouteStopWithAbortAfterTimeoutTest method testStopRouteWithAbortAfterTimeoutFalse.

public void testStopRouteWithAbortAfterTimeoutFalse() throws Exception {
    // JMX tests dont work well on AIX or windows CI servers (hangs them)
    if (isPlatform("aix") || isPlatform("windows")) {
        return;
    }
    MockEndpoint mockEP = getMockEndpoint("mock:result");
    MBeanServer mbeanServer = getMBeanServer();
    ObjectName on = getRouteObjectName(mbeanServer);
    // confirm that route has started
    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("route should be started", ServiceStatus.Started.name(), state);
    //send some message through the route
    for (int i = 0; i < 5; i++) {
        template.sendBody("seda:start", "message-" + i);
    }
    // stop route with a 2s timeout and abortAfterTimeout=false (normal timeout behavior)
    Long timeout = new Long(2);
    Boolean abortAfterTimeout = Boolean.FALSE;
    Object[] params = { timeout, abortAfterTimeout };
    String[] sig = { "java.lang.Long", "java.lang.Boolean" };
    Boolean stopRouteResponse = (Boolean) mbeanServer.invoke(on, "stop", params, sig);
    // confirm that route is stopped
    state = (String) mbeanServer.getAttribute(on, "State");
    assertTrue("stopRoute response should be True", stopRouteResponse);
    assertEquals("route should be stopped", ServiceStatus.Stopped.name(), state);
    // send some more messages through the route
    for (int i = 5; i < 10; i++) {
        template.sendBody("seda:start", "message-" + i);
    }
    Thread.sleep(3000);
    assertTrue("Should not have received more than 5 messages", mockEP.getExchanges().size() <= 5);
}
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 100 with ObjectName

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

the class ManagedRouteStopWithAbortAfterTimeoutTest method testStopRouteWithAbortAfterTimeoutTrue.

public void testStopRouteWithAbortAfterTimeoutTrue() throws Exception {
    // JMX tests dont work well on AIX or windows CI servers (hangs them)
    if (isPlatform("aix") || isPlatform("windows")) {
        return;
    }
    MockEndpoint mockEP = getMockEndpoint("mock:result");
    mockEP.setExpectedMessageCount(10);
    MBeanServer mbeanServer = getMBeanServer();
    ObjectName on = getRouteObjectName(mbeanServer);
    // confirm that route has started
    String state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("route should be started", ServiceStatus.Started.name(), state);
    //send some message through the route
    for (int i = 0; i < 5; i++) {
        template.sendBody("seda:start", "message-" + i);
    }
    // stop route with a 2s timeout and abortAfterTimeout=true (should abort after 2s)
    Long timeout = new Long(2);
    Boolean abortAfterTimeout = Boolean.TRUE;
    Object[] params = { timeout, abortAfterTimeout };
    String[] sig = { "java.lang.Long", "java.lang.Boolean" };
    Boolean stopRouteResponse = (Boolean) mbeanServer.invoke(on, "stop", params, sig);
    // confirm that route is still running
    state = (String) mbeanServer.getAttribute(on, "State");
    assertFalse("stopRoute response should be False", stopRouteResponse);
    assertEquals("route should still be started", ServiceStatus.Started.name(), state);
    //send some more messages through the route
    for (int i = 5; i < 10; i++) {
        template.sendBody("seda:start", "message-" + i);
    }
    mockEP.assertIsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) 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