use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class BeanCallTest method beanCallHeaderMappingTest.
@Test
public void beanCallHeaderMappingTest() throws Exception {
new RouteBuilder() {
@Override
public void configure() throws Exception {
onException(Throwable.class).to("direct:handle").handled(true);
from("direct:num").bean(BeanCallTest.this, "processHeader").process(// Can be removed?
new UnwrapStreamProcessor()).to("mock:endpoint");
from("direct:handle").setBody().constant("ERR").to("mock:endpoint");
}
}.addRoutesToCamelContext(context);
MockEndpoint mock = getMockEndpoint("mock:endpoint");
mock.expectedMessageCount(1);
context.start();
template.sendBodyAndHeader("direct:num", 1, "myheader", 2);
mock.assertIsSatisfied();
Exchange exchange = mock.getExchanges().get(0);
assertEquals("HelloHeader 2", exchange.getIn().getBody());
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class BackpressureStrategyTest method testBackpressureBufferStrategy.
@Test
public void testBackpressureBufferStrategy() throws Exception {
new RouteBuilder() {
@Override
public void configure() throws Exception {
from("timer:gen?period=20&repeatCount=20").setBody().header(Exchange.TIMER_COUNTER).to("reactive-streams:integers");
}
}.addRoutesToCamelContext(context);
Flowable<Integer> integers = Flowable.fromPublisher(CamelReactiveStreams.get(context).fromStream("integers", Integer.class));
ConcurrentLinkedQueue<Integer> queue = new ConcurrentLinkedQueue<>();
CountDownLatch latch = new CountDownLatch(1);
Flowable.interval(0, 50, TimeUnit.MILLISECONDS).zipWith(integers, (l, i) -> i).timeout(2000, TimeUnit.MILLISECONDS, Flowable.empty()).doOnComplete(latch::countDown).subscribe(queue::add);
context().start();
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertEquals(20, queue.size());
int num = 1;
for (int i : queue) {
assertEquals(num++, i);
}
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class BackpressureStrategyTest method testBackpressureDropStrategy.
@Test
public void testBackpressureDropStrategy() throws Exception {
ReactiveStreamsComponent comp = (ReactiveStreamsComponent) context().getComponent("reactive-streams");
comp.setBackpressureStrategy(ReactiveStreamsBackpressureStrategy.DROP);
new RouteBuilder() {
@Override
public void configure() throws Exception {
from("timer:gen?period=20&repeatCount=20").setBody().header(Exchange.TIMER_COUNTER).to("reactive-streams:integers");
}
}.addRoutesToCamelContext(context);
ConcurrentLinkedQueue<Integer> queue = new ConcurrentLinkedQueue<>();
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(2);
TestSubscriber<Integer> subscriber = new TestSubscriber<Integer>() {
@Override
public void onNext(Integer o) {
queue.add(o);
latch.countDown();
latch2.countDown();
}
};
subscriber.setInitiallyRequested(1);
CamelReactiveStreams.get(context).fromStream("integers", Integer.class).subscribe(subscriber);
context().start();
assertTrue(latch.await(5, TimeUnit.SECONDS));
// wait for all numbers to be generated
Thread.sleep(1000);
subscriber.request(19);
assertTrue(latch2.await(1, TimeUnit.SECONDS));
// add other time to ensure no other items arrive
Thread.sleep(200);
assertEquals(2, queue.size());
int sum = queue.stream().reduce((i, j) -> i + j).get();
// 1 + 2 = 3
assertEquals(3, sum);
subscriber.cancel();
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class BackpressureStrategyTest method testBackpressureDropStrategyInEndpoint.
@Test
public void testBackpressureDropStrategyInEndpoint() throws Exception {
new RouteBuilder() {
@Override
public void configure() throws Exception {
from("timer:gen?period=20&repeatCount=20").setBody().header(Exchange.TIMER_COUNTER).to("reactive-streams:integers?backpressureStrategy=DROP");
}
}.addRoutesToCamelContext(context);
ConcurrentLinkedQueue<Integer> queue = new ConcurrentLinkedQueue<>();
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(2);
TestSubscriber<Integer> subscriber = new TestSubscriber<Integer>() {
@Override
public void onNext(Integer o) {
queue.add(o);
latch.countDown();
latch2.countDown();
}
};
subscriber.setInitiallyRequested(1);
CamelReactiveStreams.get(context).fromStream("integers", Integer.class).subscribe(subscriber);
context().start();
assertTrue(latch.await(5, TimeUnit.SECONDS));
// wait for all numbers to be generated
Thread.sleep(1000);
subscriber.request(19);
assertTrue(latch2.await(1, TimeUnit.SECONDS));
// add other time to ensure no other items arrive
Thread.sleep(200);
assertEquals(2, queue.size());
int sum = queue.stream().reduce((i, j) -> i + j).get();
// 1 + 2 = 3
assertEquals(3, sum);
subscriber.cancel();
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class BackpressureStrategyTest method testBackpressureLatestStrategy.
@Test
public void testBackpressureLatestStrategy() throws Exception {
ReactiveStreamsComponent comp = (ReactiveStreamsComponent) context().getComponent("reactive-streams");
comp.setBackpressureStrategy(ReactiveStreamsBackpressureStrategy.LATEST);
new RouteBuilder() {
@Override
public void configure() throws Exception {
from("timer:gen?period=20&repeatCount=20").setBody().header(Exchange.TIMER_COUNTER).to("reactive-streams:integers");
}
}.addRoutesToCamelContext(context);
ConcurrentLinkedQueue<Integer> queue = new ConcurrentLinkedQueue<>();
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(2);
TestSubscriber<Integer> subscriber = new TestSubscriber<Integer>() {
@Override
public void onNext(Integer o) {
queue.add(o);
latch.countDown();
latch2.countDown();
}
};
subscriber.setInitiallyRequested(1);
CamelReactiveStreams.get(context).fromStream("integers", Integer.class).subscribe(subscriber);
context().start();
assertTrue(latch.await(5, TimeUnit.SECONDS));
// wait for all numbers to be generated
Thread.sleep(1000);
subscriber.request(19);
assertTrue(latch2.await(1, TimeUnit.SECONDS));
// add other time to ensure no other items arrive
Thread.sleep(200);
assertEquals(2, queue.size());
int sum = queue.stream().reduce((i, j) -> i + j).get();
// 1 + 20 = 21
assertEquals(21, sum);
subscriber.cancel();
}
Aggregations