Search in sources :

Example 1 with NotifyBuilder

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();
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) Mailbox(org.jvnet.mock_javamail.Mailbox) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) HashSet(java.util.HashSet)

Example 2 with NotifyBuilder

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);
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) Test(org.junit.Test)

Example 3 with NotifyBuilder

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);
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) Test(org.junit.Test)

Example 4 with NotifyBuilder

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);
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) Test(org.junit.Test)

Example 5 with NotifyBuilder

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);
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Aggregations

NotifyBuilder (org.apache.camel.builder.NotifyBuilder)109 Test (org.junit.Test)72 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)30 File (java.io.File)24 Exchange (org.apache.camel.Exchange)10 RouteBuilder (org.apache.camel.builder.RouteBuilder)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 HashSet (java.util.HashSet)4 MBeanServer (javax.management.MBeanServer)4 ObjectName (javax.management.ObjectName)4 Processor (org.apache.camel.Processor)4 StopWatch (org.apache.camel.util.StopWatch)4 ConnectException (java.net.ConnectException)3 ExecutorService (java.util.concurrent.ExecutorService)3 Ignore (org.junit.Ignore)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Future (java.util.concurrent.Future)2 ZipFile (java.util.zip.ZipFile)2