Search in sources :

Example 1 with CamelReactiveStreamsService

use of org.apache.camel.component.reactive.streams.api.CamelReactiveStreamsService in project camel by apache.

the class ExchangeRequestTest method testMultipleInteractions.

@Test
public void testMultipleInteractions() throws Exception {
    CamelReactiveStreamsService camel = CamelReactiveStreams.get(context);
    Integer sum = Flowable.just(1, 2, 3).flatMap(e -> camel.toStream("plusOne", e, Integer.class)).reduce((i, j) -> i + j).blockingGet();
    assertNotNull(sum);
    assertEquals(9, sum.intValue());
}
Also used : RoutesBuilder(org.apache.camel.RoutesBuilder) DefaultExchange(org.apache.camel.impl.DefaultExchange) CamelReactiveStreams(org.apache.camel.component.reactive.streams.api.CamelReactiveStreams) Flowable(io.reactivex.Flowable) RouteBuilder(org.apache.camel.builder.RouteBuilder) Publisher(org.reactivestreams.Publisher) Exchange(org.apache.camel.Exchange) CamelReactiveStreamsService(org.apache.camel.component.reactive.streams.api.CamelReactiveStreamsService) Test(org.junit.Test) CamelTestSupport(org.apache.camel.test.junit4.CamelTestSupport) CamelReactiveStreamsService(org.apache.camel.component.reactive.streams.api.CamelReactiveStreamsService) Test(org.junit.Test)

Example 2 with CamelReactiveStreamsService

use of org.apache.camel.component.reactive.streams.api.CamelReactiveStreamsService in project camel by apache.

the class ExchangeRequestTest method testStreamRequest.

@Test
public void testStreamRequest() throws Exception {
    CamelReactiveStreamsService camel = CamelReactiveStreams.get(context);
    Publisher<Exchange> string = camel.toStream("data", new DefaultExchange(context));
    Exchange res = Flowable.fromPublisher(string).blockingFirst();
    assertNotNull(res);
    String content = res.getIn().getBody(String.class);
    assertNotNull(content);
    assertEquals("123", content);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) CamelReactiveStreamsService(org.apache.camel.component.reactive.streams.api.CamelReactiveStreamsService) Test(org.junit.Test)

Example 3 with CamelReactiveStreamsService

use of org.apache.camel.component.reactive.streams.api.CamelReactiveStreamsService in project camel by apache.

the class ExchangeRequestTest method testInteraction.

@Test
public void testInteraction() throws Exception {
    CamelReactiveStreamsService camel = CamelReactiveStreams.get(context);
    Integer res = Flowable.fromPublisher(camel.toStream("plusOne", 1L, Integer.class)).blockingFirst();
    assertNotNull(res);
    assertEquals(2, res.intValue());
}
Also used : CamelReactiveStreamsService(org.apache.camel.component.reactive.streams.api.CamelReactiveStreamsService) Test(org.junit.Test)

Example 4 with CamelReactiveStreamsService

use of org.apache.camel.component.reactive.streams.api.CamelReactiveStreamsService 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 5 with CamelReactiveStreamsService

use of org.apache.camel.component.reactive.streams.api.CamelReactiveStreamsService in project camel by apache.

the class CamelReactiveStreamsTest method testDefaultService.

@Test
public void testDefaultService() {
    CamelReactiveStreamsService service1 = CamelReactiveStreams.get(context, "default-service");
    assertTrue(service1 instanceof CamelReactiveStreamsServiceImpl);
}
Also used : CamelReactiveStreamsService(org.apache.camel.component.reactive.streams.api.CamelReactiveStreamsService) CamelReactiveStreamsServiceImpl(org.apache.camel.component.reactive.streams.engine.CamelReactiveStreamsServiceImpl) Test(org.junit.Test)

Aggregations

CamelReactiveStreamsService (org.apache.camel.component.reactive.streams.api.CamelReactiveStreamsService)10 Test (org.junit.Test)10 Exchange (org.apache.camel.Exchange)3 RouteBuilder (org.apache.camel.builder.RouteBuilder)3 ReactiveStreamsTestService (org.apache.camel.component.reactive.streams.support.ReactiveStreamsTestService)3 LinkedList (java.util.LinkedList)2 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 CamelReactiveStreamsServiceImpl (org.apache.camel.component.reactive.streams.engine.CamelReactiveStreamsServiceImpl)2 DefaultExchange (org.apache.camel.impl.DefaultExchange)2 Flowable (io.reactivex.Flowable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 RoutesBuilder (org.apache.camel.RoutesBuilder)1 CamelReactiveStreams (org.apache.camel.component.reactive.streams.api.CamelReactiveStreams)1 CamelTestSupport (org.apache.camel.test.junit4.CamelTestSupport)1 Publisher (org.reactivestreams.Publisher)1