Search in sources :

Example 46 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class EventTypeTest method testOnErrorHeaderForwarded.

@Test
public void testOnErrorHeaderForwarded() throws Exception {
    new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("reactive-streams:numbers?forwardOnError=true").to("mock:endpoint");
        }
    }.addRoutesToCamelContext(context);
    Subscriber<Integer> numbers = CamelReactiveStreams.get(context).streamSubscriber("numbers", Integer.class);
    context.start();
    RuntimeException ex = new RuntimeException("1");
    Flowable.just(1).map(n -> {
        if (n == 1) {
            throw ex;
        }
        return n;
    }).subscribe(numbers);
    MockEndpoint endpoint = getMockEndpoint("mock:endpoint");
    endpoint.expectedMessageCount(1);
    endpoint.expectedHeaderReceived(ReactiveStreamsConstants.REACTIVE_STREAMS_EVENT_TYPE, "onError");
    endpoint.assertIsSatisfied();
    Exchange exch = endpoint.getExchanges().get(0);
    assertEquals(ex, exch.getIn().getBody());
}
Also used : CamelReactiveStreams(org.apache.camel.component.reactive.streams.api.CamelReactiveStreams) Flowable(io.reactivex.Flowable) RouteBuilder(org.apache.camel.builder.RouteBuilder) Exchange(org.apache.camel.Exchange) Test(org.junit.Test) CamelTestSupport(org.apache.camel.test.junit4.CamelTestSupport) Subscriber(org.reactivestreams.Subscriber) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Exchange(org.apache.camel.Exchange) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 47 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class AbstractPlatformTestSupport method testSubscriber.

@Test
public void testSubscriber() throws Exception {
    int num = 20;
    new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("reactive-streams:integers").to("mock:endpoint");
        }
    }.addRoutesToCamelContext(context);
    CamelReactiveStreamsService camel = CamelReactiveStreams.get(context);
    List<Integer> elements = new LinkedList<>();
    for (int i = 1; i <= num; i++) {
        elements.add(i);
    }
    changeSign(elements, camel.streamSubscriber("integers", Integer.class));
    context.start();
    MockEndpoint mock = getMockEndpoint("mock:endpoint");
    mock.expectedMessageCount(num);
    mock.assertIsSatisfied();
    for (Exchange ex : mock.getExchanges()) {
        Integer number = ex.getIn().getBody(Integer.class);
        assertNotNull(number);
        assertTrue(number < 0);
    }
}
Also used : Exchange(org.apache.camel.Exchange) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) CamelReactiveStreamsService(org.apache.camel.component.reactive.streams.api.CamelReactiveStreamsService) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 48 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class CamelPublisherConversionVerificationTest method createPublisher.

@Override
public Publisher<Long> createPublisher(long l) {
    CamelContext context = new DefaultCamelContext();
    RouteBuilder builder = new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("timer:tick?delay=500&period=50&repeatCount=" + l).setBody().simple("random(1000)").to("reactive-streams:prod");
        }
    };
    Publisher<Long> pub = CamelReactiveStreams.get(context).fromStream("prod", Long.class);
    try {
        builder.addRoutesToCamelContext(context);
        context.start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return pub;
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 49 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class CamelPublisherVerificationTest method createPublisher.

@Override
public Publisher<Exchange> createPublisher(long l) {
    CamelContext context = new DefaultCamelContext();
    RouteBuilder builder = new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("timer:tick?delay=500&period=50&repeatCount=" + l).to("reactive-streams:prod");
        }
    };
    Publisher<Exchange> pub = CamelReactiveStreams.get(context).fromStream("prod");
    try {
        builder.addRoutesToCamelContext(context);
        context.start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return pub;
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Exchange(org.apache.camel.Exchange) RouteBuilder(org.apache.camel.builder.RouteBuilder) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 50 with RouteBuilder

use of org.apache.camel.builder.RouteBuilder in project camel by apache.

the class DirectClientAPITest method testDirectCallFromCamel.

@Test
public void testDirectCallFromCamel() throws Exception {
    new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:source").to("direct:stream").setBody().simple("after stream: ${body}").to("mock:dest");
        }
    }.addRoutesToCamelContext(context);
    context.start();
    camel.process("direct:stream", p -> Flowable.fromPublisher(p).map(exchange -> {
        int val = exchange.getIn().getBody(Integer.class);
        exchange.getOut().setBody(-val);
        return exchange;
    }));
    for (int i = 1; i <= 3; i++) {
        template.sendBody("direct:source", i);
    }
    MockEndpoint mock = getMockEndpoint("mock:dest");
    mock.expectedMessageCount(3);
    mock.assertIsSatisfied();
    int id = 1;
    for (Exchange ex : mock.getExchanges()) {
        String content = ex.getIn().getBody(String.class);
        assertEquals("after stream: " + (-id++), content);
    }
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) Flowable(io.reactivex.Flowable) ReactiveStreamsTestSupport(org.apache.camel.component.reactive.streams.support.ReactiveStreamsTestSupport) RouteBuilder(org.apache.camel.builder.RouteBuilder) Publisher(org.reactivestreams.Publisher) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) BlockingQueue(java.util.concurrent.BlockingQueue) Exchange(org.apache.camel.Exchange) Test(org.junit.Test) JndiRegistry(org.apache.camel.impl.JndiRegistry) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Exchange(org.apache.camel.Exchange) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Aggregations

RouteBuilder (org.apache.camel.builder.RouteBuilder)1759 Exchange (org.apache.camel.Exchange)628 Processor (org.apache.camel.Processor)545 Test (org.junit.Test)476 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)341 CamelExecutionException (org.apache.camel.CamelExecutionException)135 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)119 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)104 File (java.io.File)68 CamelContext (org.apache.camel.CamelContext)64 IOException (java.io.IOException)61 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)42 HashMap (java.util.HashMap)35 Path (org.apache.hadoop.fs.Path)34 CountDownLatch (java.util.concurrent.CountDownLatch)32 Configuration (org.apache.hadoop.conf.Configuration)32 Endpoint (org.apache.camel.Endpoint)30 ArrayFile (org.apache.hadoop.io.ArrayFile)30 SequenceFile (org.apache.hadoop.io.SequenceFile)30 RuntimeCamelException (org.apache.camel.RuntimeCamelException)26