use of javax.management.ObjectName in project camel by apache.
the class ManagedSuspendedServiceTest method testConsumeSuspendAndResumeFile.
public void testConsumeSuspendAndResumeFile() 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=consumers,*"), null);
assertEquals(1, set.size());
ObjectName on = set.iterator().next();
boolean registered = mbeanServer.isRegistered(on);
assertEquals("Should be registered", true, registered);
Boolean ss = (Boolean) mbeanServer.getAttribute(on, "SupportSuspension");
assertEquals(true, ss.booleanValue());
Boolean suspended = (Boolean) mbeanServer.getAttribute(on, "Suspended");
assertEquals(false, suspended.booleanValue());
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
template.sendBodyAndHeader("file://target/suspended", "Bye World", Exchange.FILE_NAME, "bye.txt");
template.sendBodyAndHeader("file://target/suspended", "Hello World", Exchange.FILE_NAME, "hello.txt");
assertMockEndpointsSatisfied();
Thread.sleep(1000);
// now its suspended by the policy
suspended = (Boolean) mbeanServer.getAttribute(on, "Suspended");
assertEquals(true, suspended.booleanValue());
// the route is suspended by the policy so we should only receive one
String[] files = new File("target/suspended/").list();
assertNotNull(files);
assertEquals("The file should exists", 1, files.length);
// reset mock
mock.reset();
mock.expectedMessageCount(1);
// now resume it
mbeanServer.invoke(on, "resume", null, null);
assertMockEndpointsSatisfied();
suspended = (Boolean) mbeanServer.getAttribute(on, "Suspended");
assertEquals(false, suspended.booleanValue());
Thread.sleep(500);
// and the file is now deleted
files = new File("target/suspended/").list();
assertNotNull(files);
assertEquals("The file should exists", 0, files.length);
}
use of javax.management.ObjectName in project camel by apache.
the class ManagedThrottlerTest method testThrottleAsyncExceptionVisableViaJmx.
public void testThrottleAsyncExceptionVisableViaJmx() 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=\"mythrottler4\"");
// use route to get the total time
ObjectName routeName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route4\"");
// reset the counters
mbeanServer.invoke(routeName, "reset", null, null);
getMockEndpoint("mock:endAsyncException").expectedMessageCount(10);
NotifyBuilder notifier = new NotifyBuilder(context).from("seda:throttleCountAsyncException").whenReceived(5).create();
for (int i = 0; i < 10; i++) {
template.sendBody("seda:throttleCountAsyncException", "Message " + i);
}
assertTrue(notifier.matches(2, TimeUnit.SECONDS));
assertMockEndpointsSatisfied();
// give a sec for exception handling to finish..
Thread.sleep(500);
// since all exchanges ended w/ exception, they are not completed
Long completed = (Long) mbeanServer.getAttribute(routeName, "ExchangesCompleted");
assertEquals(0, completed.longValue());
}
use of javax.management.ObjectName 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();
}
use of javax.management.ObjectName 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());
}
use of javax.management.ObjectName 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();
}
Aggregations