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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations