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();
}
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());
}
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();
}
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);
}
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();
}
Aggregations