use of org.apache.camel.builder.NotifyBuilder in project camel by apache.
the class ManagedThrottlerTest method testThrottleAsyncVisableViaJmx.
public void testThrottleAsyncVisableViaJmx() 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=\"mythrottler3\"");
// use route to get the total time
ObjectName routeName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route3\"");
// reset the counters
mbeanServer.invoke(routeName, "reset", null, null);
getMockEndpoint("mock:endAsync").expectedMessageCount(10);
// we pick '5' because we are right in the middle of the number of messages
// that have been and reduces any race conditions to minimal...
NotifyBuilder notifier = new NotifyBuilder(context).from("seda:throttleCountAsync").whenReceived(5).create();
for (int i = 0; i < 10; i++) {
template.sendBody("seda:throttleCountAsync", "Message " + i);
}
assertTrue(notifier.matches(2, TimeUnit.SECONDS));
assertMockEndpointsSatisfied();
Long completed = (Long) mbeanServer.getAttribute(routeName, "ExchangesCompleted");
assertEquals(10, completed.longValue());
}
use of org.apache.camel.builder.NotifyBuilder in project camel by apache.
the class ConsumerCompletionTest method testReleaseOnFailure.
@Test
public void testReleaseOnFailure() throws Exception {
shouldIdie = true;
final long jobId = 111;
final long priority = BeanstalkComponent.DEFAULT_PRIORITY;
final int delay = BeanstalkComponent.DEFAULT_DELAY;
final byte[] payload = Helper.stringToBytes(testMessage);
final Job jobMock = mock(Job.class);
when(jobMock.getJobId()).thenReturn(jobId);
when(jobMock.getData()).thenReturn(payload);
when(client.reserve(anyInt())).thenReturn(jobMock).thenReturn(null);
when(client.statsJob(anyInt())).thenReturn(null);
when(client.release(anyInt(), anyLong(), anyInt())).thenReturn(true);
NotifyBuilder notify = new NotifyBuilder(context).whenFailed(1).create();
MockEndpoint result = getMockEndpoint("mock:result");
result.expectedMessageCount(0);
context.startRoute("foo");
assertTrue(notify.matches(5, TimeUnit.SECONDS));
verify(client, atLeastOnce()).reserve(anyInt());
verify(client, atLeastOnce()).statsJob(anyInt());
verify(client).release(jobId, priority, delay);
}
use of org.apache.camel.builder.NotifyBuilder in project camel by apache.
the class NettyConcurrentTest method doSendMessages.
private void doSendMessages(int files, int poolSize) throws Exception {
StopWatch watch = new StopWatch();
NotifyBuilder notify = new NotifyBuilder(context).whenDone(files).create();
ExecutorService executor = Executors.newFixedThreadPool(poolSize);
// we access the responses Map below only inside the main thread,
// so no need for a thread-safe Map implementation
Map<Integer, Future<String>> responses = new HashMap<Integer, Future<String>>();
for (int i = 0; i < files; i++) {
final int index = i;
Future<String> out = executor.submit(new Callable<String>() {
public String call() throws Exception {
String reply = template.requestBody("netty:tcp://localhost:{{port}}", index, String.class);
log.debug("Sent {} received {}", index, reply);
assertEquals("Bye " + index, reply);
return reply;
}
});
responses.put(index, out);
}
notify.matches(2, TimeUnit.MINUTES);
log.info("Took " + watch.taken() + " millis to process " + files + " messages using " + poolSize + " client threads.");
assertEquals(files, responses.size());
// get all responses
Set<String> unique = new HashSet<String>();
for (Future<String> future : responses.values()) {
unique.add(future.get());
}
// should be 'files' unique responses
assertEquals("Should be " + files + " unique responses", files, unique.size());
executor.shutdownNow();
}
use of org.apache.camel.builder.NotifyBuilder in project camel by apache.
the class AbstractTransactionTest method assertResult.
protected void assertResult() throws InterruptedException {
// should be 1 completed and 1 failed
NotifyBuilder notify = new NotifyBuilder(context).whenDone(2).create();
template.sendBody("activemq:queue:foo", "blah");
notify.matchesMockWaitTime();
assertTrue("Expected only 2 calls to process() (1 failure, 1 success) but encountered " + getConditionalExceptionProcessor().getCount() + ".", getConditionalExceptionProcessor().getCount() == 2);
}
use of org.apache.camel.builder.NotifyBuilder in project camel by apache.
the class MllpTcpServerConsumerTest method testMessageReadTimeout.
@Test
public void testMessageReadTimeout() throws Exception {
result.expectedMessageCount(0);
timeout.expectedMessageCount(1);
NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
mllpClient.setSendEndOfBlock(false);
mllpClient.setSendEndOfData(false);
mllpClient.sendFramedData(generateMessage());
assertTrue("One exchange should have completed", notify.matches(15, TimeUnit.SECONDS));
assertMockEndpointsSatisfied();
}
Aggregations