use of org.apache.camel.builder.NotifyBuilder in project camel by apache.
the class MailProducerConcurrentTest method doSendMessages.
private void doSendMessages(int files, int poolSize) throws Exception {
Mailbox.clearAll();
NotifyBuilder builder = new NotifyBuilder(context).whenDone(files).create();
getMockEndpoint("mock:result").expectedMessageCount(files);
getMockEndpoint("mock:result").expectsNoDuplicates(body());
final CountDownLatch latch = new CountDownLatch(files);
ExecutorService executor = Executors.newFixedThreadPool(poolSize);
for (int i = 0; i < files; i++) {
final int index = i;
executor.submit(new Callable<Object>() {
public Object call() throws Exception {
template.sendBodyAndHeader("direct:start", "Message " + index, "To", "someone@localhost");
latch.countDown();
return null;
}
});
}
// wait first for all the exchanges above to be thoroughly sent asynchronously
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertMockEndpointsSatisfied();
assertTrue(builder.matchesMockWaitTime());
Mailbox box = Mailbox.get("someone@localhost");
assertEquals(files, box.size());
// as we use concurrent producers the mails can arrive out of order
Set<Object> bodies = new HashSet<Object>();
for (int i = 0; i < files; i++) {
bodies.add(box.get(i).getContent());
}
assertEquals("There should be " + files + " unique mails", files, bodies.size());
executor.shutdownNow();
}
use of org.apache.camel.builder.NotifyBuilder in project camel by apache.
the class MllpTcpClientProducerConnectionErrorTest method testConnectionResetBeforeReadingAcknowledgement.
@Test()
public void testConnectionResetBeforeReadingAcknowledgement() throws Exception {
complete.expectedMessageCount(0);
writeEx.expectedMessageCount(0);
receiveEx.expectedMessageCount(1);
mllpServer.setResetSocketBeforeAcknowledgementModulus(1);
NotifyBuilder done = new NotifyBuilder(context).whenCompleted(1).create();
source.sendBody(generateMessage());
assertTrue("Should have completed an exchange", done.matches(5, TimeUnit.SECONDS));
assertMockEndpointsSatisfied(5, TimeUnit.SECONDS);
}
use of org.apache.camel.builder.NotifyBuilder in project camel by apache.
the class MllpTcpClientProducerConnectionErrorTest method testConnectionClosedBeforeSendingHL7Message.
@Test
public void testConnectionClosedBeforeSendingHL7Message() throws Exception {
complete.expectedMessageCount(1);
writeEx.expectedMessageCount(0);
receiveEx.expectedMessageCount(1);
NotifyBuilder done = new NotifyBuilder(context).whenCompleted(2).create();
// Need to send one message to get the connection established
source.sendBody(generateMessage());
mllpServer.closeClientConnections();
source.sendBody(generateMessage());
assertTrue("Should have completed an exchange", done.matches(5, TimeUnit.SECONDS));
assertMockEndpointsSatisfied(5, TimeUnit.SECONDS);
}
use of org.apache.camel.builder.NotifyBuilder in project camel by apache.
the class MllpTcpClientProducerConnectionErrorTest method testConnectionResetBeforeSendingHL7Message.
@Test()
public void testConnectionResetBeforeSendingHL7Message() throws Exception {
complete.expectedMessageCount(1);
writeEx.expectedMessageCount(1);
receiveEx.expectedMessageCount(0);
NotifyBuilder done = new NotifyBuilder(context).whenCompleted(2).create();
// Need to send one message to get the connection established
source.sendBody(generateMessage());
mllpServer.resetClientConnections();
source.sendBody(generateMessage());
assertTrue("Should have completed an exchange", done.matches(5, TimeUnit.SECONDS));
assertMockEndpointsSatisfied(5, TimeUnit.SECONDS);
}
use of org.apache.camel.builder.NotifyBuilder in project camel by apache.
the class MllpTcpClientProducerTest method testSendMultipleMessages.
@Test
public void testSendMultipleMessages() throws Exception {
int messageCount = 5;
acknowledged.expectedMessageCount(messageCount);
timeoutError.expectedMessageCount(0);
NotifyBuilder[] complete = new NotifyBuilder[messageCount];
for (int i = 0; i < messageCount; ++i) {
complete[i] = new NotifyBuilder(context).whenDone(i + 1).create();
}
for (int i = 0; i < messageCount; ++i) {
source.sendBody(generateMessage(i + 1));
assertTrue("Messege " + i + " not completed", complete[i].matches(1, TimeUnit.SECONDS));
}
assertMockEndpointsSatisfied(15, TimeUnit.SECONDS);
}
Aggregations