Search in sources :

Example 1 with ManagedSuspendableRouteMBean

use of org.apache.camel.api.management.mbean.ManagedSuspendableRouteMBean in project camel by apache.

the class ManagedRouteSuspendAndResumeTest method testSuspendAndResume.

public void testSuspendAndResume() 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);
    // stop
    mbeanServer.invoke(on, "suspend", null, null);
    state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("Should be suspended", ServiceStatus.Suspended.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, "resume", null, null);
    state = (String) mbeanServer.getAttribute(on, "State");
    assertEquals("Should be started", ServiceStatus.Started.name(), state);
    // this time the file is consumed
    mock.assertIsSatisfied();
    ManagedSuspendableRouteMBean route = context.getManagedRoute("foo", ManagedSuspendableRouteMBean.class);
    assertNotNull(route);
    assertEquals(2, route.getExchangesCompleted());
}
Also used : ManagedSuspendableRouteMBean(org.apache.camel.api.management.mbean.ManagedSuspendableRouteMBean) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Aggregations

MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 ManagedSuspendableRouteMBean (org.apache.camel.api.management.mbean.ManagedSuspendableRouteMBean)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1