use of javax.management.MBeanServer 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.MBeanServer 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();
}
use of javax.management.MBeanServer 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());
}
use of javax.management.MBeanServer in project camel by apache.
the class ManagedRouteUpdateRouteFromXmlTest method testUpdateRouteFromXml.
public void testUpdateRouteFromXml() 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.sendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
// should be started
String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
assertEquals("myRoute", routeId);
String xml = "<route id=\"myRoute\" xmlns=\"http://camel.apache.org/schema/spring\">" + " <from uri=\"direct:start\"/>" + " <log message=\"This is a changed route saying ${body}\"/>" + " <to uri=\"mock:changed\"/>" + "</route>";
mbeanServer.invoke(on, "updateRouteFromXml", new Object[] { xml }, new String[] { "java.lang.String" });
assertEquals(1, context.getRoutes().size());
getMockEndpoint("mock:changed").expectedMessageCount(1);
template.sendBody("direct:start", "Bye World");
assertMockEndpointsSatisfied();
}
use of javax.management.MBeanServer in project camel by apache.
the class ManagedRoutePerformanceCounterTest method testPerformanceCounterStats.
public void testPerformanceCounterStats() 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();
ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route1\"");
Long delta = (Long) mbeanServer.getAttribute(on, "DeltaProcessingTime");
assertEquals(0, delta.intValue());
getMockEndpoint("mock:result").expectedMessageCount(1);
template.asyncSendBody("direct:start", "Hello World");
// cater for slow boxes
Integer inFlight = null;
for (int i = 0; i < 10; i++) {
Thread.sleep(500);
inFlight = (Integer) mbeanServer.getAttribute(on, "InflightExchanges");
if (inFlight.longValue() == 1) {
break;
}
}
assertNotNull("too slow server", inFlight);
assertEquals(1, inFlight.longValue());
assertMockEndpointsSatisfied();
Thread.sleep(3000);
Long completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(1, completed.longValue());
delta = (Long) mbeanServer.getAttribute(on, "DeltaProcessingTime");
Long last = (Long) mbeanServer.getAttribute(on, "LastProcessingTime");
Long total = (Long) mbeanServer.getAttribute(on, "TotalProcessingTime");
assertNotNull(delta);
assertTrue("Should take around 3 sec: was " + last, last > 2900);
assertTrue("Should take around 3 sec: was " + total, total > 2900);
// send in another message
template.sendBody("direct:start", "Bye World");
completed = (Long) mbeanServer.getAttribute(on, "ExchangesCompleted");
assertEquals(2, completed.longValue());
delta = (Long) mbeanServer.getAttribute(on, "DeltaProcessingTime");
last = (Long) mbeanServer.getAttribute(on, "LastProcessingTime");
total = (Long) mbeanServer.getAttribute(on, "TotalProcessingTime");
assertNotNull(delta);
assertTrue("Should take around 3 sec: was " + last, last > 2900);
assertTrue("Should be around 5 sec now: was " + total, total > 4900);
Date reset = (Date) mbeanServer.getAttribute(on, "ResetTimestamp");
assertNotNull(reset);
Date lastFailed = (Date) mbeanServer.getAttribute(on, "LastExchangeFailureTimestamp");
Date firstFailed = (Date) mbeanServer.getAttribute(on, "FirstExchangeFailureTimestamp");
assertNull(lastFailed);
assertNull(firstFailed);
inFlight = (Integer) mbeanServer.getAttribute(on, "InflightExchanges");
assertEquals(0, inFlight.longValue());
}
Aggregations