Search in sources :

Example 11 with SynchronizationAdapter

use of org.apache.camel.support.SynchronizationAdapter in project camel by apache.

the class DefaultProducerTemplateAsyncTest method testAsyncCallbackInOnlyProcessor.

public void testAsyncCallbackInOnlyProcessor() throws Exception {
    ORDER.set(0);
    getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
    final CountDownLatch latch = new CountDownLatch(1);
    template.asyncCallback("direct:start", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody("Hello");
        }
    }, new SynchronizationAdapter() {

        @Override
        public void onDone(Exchange exchange) {
            assertEquals("Hello World", exchange.getIn().getBody());
            ORDER.addAndGet(2);
            latch.countDown();
        }
    });
    ORDER.addAndGet(1);
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    ORDER.addAndGet(4);
    assertMockEndpointsSatisfied();
    assertEquals(7, ORDER.get());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) CountDownLatch(java.util.concurrent.CountDownLatch) RuntimeCamelException(org.apache.camel.RuntimeCamelException) SynchronizationAdapter(org.apache.camel.support.SynchronizationAdapter)

Example 12 with SynchronizationAdapter

use of org.apache.camel.support.SynchronizationAdapter in project camel by apache.

the class DefaultProducerTemplateAsyncTest method testAsyncCallbackBodyInOnly.

public void testAsyncCallbackBodyInOnly() throws Exception {
    ORDER.set(0);
    getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
    final CountDownLatch latch = new CountDownLatch(1);
    template.asyncCallbackSendBody("direct:start", "Hello", new SynchronizationAdapter() {

        @Override
        public void onDone(Exchange exchange) {
            assertEquals("Hello World", exchange.getIn().getBody());
            ORDER.addAndGet(2);
            latch.countDown();
        }
    });
    ORDER.addAndGet(1);
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    ORDER.addAndGet(4);
    assertMockEndpointsSatisfied();
    assertEquals(7, ORDER.get());
}
Also used : Exchange(org.apache.camel.Exchange) CountDownLatch(java.util.concurrent.CountDownLatch) SynchronizationAdapter(org.apache.camel.support.SynchronizationAdapter)

Example 13 with SynchronizationAdapter

use of org.apache.camel.support.SynchronizationAdapter in project camel by apache.

the class DefaultProducerTemplateAsyncTest method testAsyncCallbackExchangeInOut.

public void testAsyncCallbackExchangeInOut() throws Exception {
    ORDER.set(0);
    final CountDownLatch latch = new CountDownLatch(1);
    Exchange exchange = context.getEndpoint("direct:start").createExchange();
    exchange.getIn().setBody("Hello");
    exchange.setPattern(ExchangePattern.InOut);
    template.asyncCallback("direct:echo", exchange, new SynchronizationAdapter() {

        @Override
        public void onDone(Exchange exchange) {
            assertEquals("HelloHello", exchange.getOut().getBody());
            ORDER.addAndGet(2);
            latch.countDown();
        }
    });
    ORDER.addAndGet(1);
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    ORDER.addAndGet(4);
    assertEquals(7, ORDER.get());
}
Also used : Exchange(org.apache.camel.Exchange) CountDownLatch(java.util.concurrent.CountDownLatch) SynchronizationAdapter(org.apache.camel.support.SynchronizationAdapter)

Example 14 with SynchronizationAdapter

use of org.apache.camel.support.SynchronizationAdapter in project camel by apache.

the class DefaultProducerTemplateAsyncTest method testAsyncCallbackExchangeInOutGetResult.

public void testAsyncCallbackExchangeInOutGetResult() throws Exception {
    ORDER.set(0);
    Exchange exchange = context.getEndpoint("direct:start").createExchange();
    exchange.getIn().setBody("Hello");
    exchange.setPattern(ExchangePattern.InOut);
    Future<Exchange> future = template.asyncCallback("direct:echo", exchange, new SynchronizationAdapter() {

        @Override
        public void onDone(Exchange exchange) {
            assertEquals("HelloHello", exchange.getOut().getBody());
            ORDER.addAndGet(2);
        }
    });
    ORDER.addAndGet(1);
    Exchange reply = future.get(10, TimeUnit.SECONDS);
    ORDER.addAndGet(4);
    assertEquals(7, ORDER.get());
    assertNotNull(reply);
    assertEquals("HelloHello", reply.getOut().getBody());
}
Also used : Exchange(org.apache.camel.Exchange) SynchronizationAdapter(org.apache.camel.support.SynchronizationAdapter)

Example 15 with SynchronizationAdapter

use of org.apache.camel.support.SynchronizationAdapter in project camel by apache.

the class DefaultProducerTemplateAsyncTest method testAsyncCallbackExchangeInOnly.

public void testAsyncCallbackExchangeInOnly() throws Exception {
    ORDER.set(0);
    getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
    final CountDownLatch latch = new CountDownLatch(1);
    Exchange exchange = context.getEndpoint("direct:start").createExchange();
    exchange.getIn().setBody("Hello");
    template.asyncCallback("direct:start", exchange, new SynchronizationAdapter() {

        @Override
        public void onDone(Exchange exchange) {
            assertEquals("Hello World", exchange.getIn().getBody());
            ORDER.addAndGet(2);
            latch.countDown();
        }
    });
    ORDER.addAndGet(1);
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    ORDER.addAndGet(4);
    assertMockEndpointsSatisfied();
    assertEquals(7, ORDER.get());
}
Also used : Exchange(org.apache.camel.Exchange) CountDownLatch(java.util.concurrent.CountDownLatch) SynchronizationAdapter(org.apache.camel.support.SynchronizationAdapter)

Aggregations

Exchange (org.apache.camel.Exchange)34 SynchronizationAdapter (org.apache.camel.support.SynchronizationAdapter)34 CountDownLatch (java.util.concurrent.CountDownLatch)13 Processor (org.apache.camel.Processor)13 RouteBuilder (org.apache.camel.builder.RouteBuilder)10 Message (org.apache.camel.Message)4 ExchangeTimedOutException (org.apache.camel.ExchangeTimedOutException)3 RuntimeCamelException (org.apache.camel.RuntimeCamelException)3 WaitForTaskToComplete (org.apache.camel.WaitForTaskToComplete)3 Async (io.vertx.ext.unit.Async)2 Endpoint (org.apache.camel.Endpoint)2 ProducerTemplate (org.apache.camel.ProducerTemplate)2 Test (org.junit.Test)2 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 ChannelHandler (io.netty.channel.ChannelHandler)1 EpollDatagramChannel (io.netty.channel.epoll.EpollDatagramChannel)1 EpollSocketChannel (io.netty.channel.epoll.EpollSocketChannel)1