Search in sources :

Example 1 with ReactorGraph

use of ru.fix.completable.reactor.runtime.ReactorGraph in project completable-reactor by ru-fix.

the class CompletableReactorHandlerArgumentsTest method arguments_test_7.

@Test
public void arguments_test_7() throws Exception {
    @Reactored("Payload with string")
    @Data
    class Payload {

        String data;
    }
    class Service {

        @Reactored("method with 7 arguments")
        public CompletableFuture<String> foo(String arg1, int arg2, short arg3, boolean arg4, Object arg5, BigInteger arg6, long arg7) {
            return CompletableFuture.completedFuture(arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7);
        }
    }
    final Service service = new Service();
    class Config {

        ReactorGraphBuilder graphBuilder = new ReactorGraphBuilder(this);

        Processor<Payload> processor = graphBuilder.processor().forPayload(Payload.class).passArg(pld -> "1").passArg(pld -> 2).passArg(pld -> (short) 3).passArg(pld -> true).passArg(pld -> 5).passArg(pld -> BigInteger.valueOf(6L)).passArg(pld -> 7L).withHandler(service::foo).withMerger((payload, result) -> {
            payload.data = result;
            return CompletableReactorTest.Status.OK;
        }).buildProcessor();

        ReactorGraph<Payload> graph() {
            return graphBuilder.payload(Payload.class).handle(processor).mergePoint(processor).onAny().complete().coordinates().buildGraph();
        }
    }
    reactor.registerReactorGraph(new Config().graph());
    assertEquals("123true567", reactor.submit(new Payload()).getResultFuture().get(5, TimeUnit.SECONDS).getData());
}
Also used : Reactored(ru.fix.completable.reactor.api.Reactored) lombok.val(lombok.val) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) CompletableReactor(ru.fix.completable.reactor.runtime.CompletableReactor) TimeUnit(java.util.concurrent.TimeUnit) ReactorGraph(ru.fix.completable.reactor.runtime.ReactorGraph) Processor(ru.fix.completable.reactor.runtime.dsl.Processor) ReactorGraphBuilder(ru.fix.completable.reactor.runtime.ReactorGraphBuilder) Data(lombok.Data) BigInteger(java.math.BigInteger) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) SimpleProfiler(ru.fix.commons.profiler.impl.SimpleProfiler) ReactorGraphBuilder(ru.fix.completable.reactor.runtime.ReactorGraphBuilder) Processor(ru.fix.completable.reactor.runtime.dsl.Processor) Reactored(ru.fix.completable.reactor.api.Reactored) BigInteger(java.math.BigInteger) Data(lombok.Data) Test(org.junit.Test)

Example 2 with ReactorGraph

use of ru.fix.completable.reactor.runtime.ReactorGraph in project completable-reactor by ru-fix.

the class MockSubgraphTest method mock_subgraph.

@Test
public void mock_subgraph() throws Exception {
    class Config {

        final ReactorGraphBuilder graphBuilder = new ReactorGraphBuilder(this);

        Processor<MainPayload> processor1 = graphBuilder.processor().forPayload(MainPayload.class).withHandler(new Processor1()::handle).withMerger((mainPayload, any) -> Status.OK).buildProcessor();

        Subgraph<MainPayload> subgraph = graphBuilder.subgraph(SubgraphPayload.class).forPayload(MainPayload.class).passArg(pld -> new SubgraphPayload().setData(pld.getData())).withMerger((mainPayload, subgraphPayload) -> {
            mainPayload.setData(subgraphPayload.getData());
            return Status.OK;
        }).buildSubgraph();

        ReactorGraph<MainPayload> graph() {
            return graphBuilder.payload(MainPayload.class).handle(processor1).mergePoint(processor1).onAny().handle(subgraph).mergePoint(subgraph).onAny().complete().coordinates().start(488, -51).proc(processor1, 483, 19).proc(subgraph, 465, 175).merge(processor1, 519, 104).merge(subgraph, 526, 259).complete(subgraph, 532, 336).buildGraph();
        }
    }
    val graph = new Config().graph();
    ReactorGraphBuilder.write(graph);
    reactor.registerReactorGraph(graph);
    // mocking subgraph behaviour
    AtomicReference<SubgraphPayload> subgraphCapture = new AtomicReference<>();
    reactor.registerReactorGraph(SubgraphPayload.class, payload -> {
        subgraphCapture.set(payload);
        return CompletableFuture.completedFuture(new SubgraphPayload().setData("mock-subgraph-data"));
    });
    // override subgraph implementation by async method
    CompletableReactor.Execution<MainPayload> result = reactor.submit(new MainPayload().setData("main-payload-data"));
    MainPayload mainGraphResultPayload = result.getResultFuture().get(10, TimeUnit.SECONDS);
    assertNotNull(subgraphCapture.get());
    assertEquals("main-payload-data", subgraphCapture.get().getData());
    assertEquals("mock-subgraph-data", mainGraphResultPayload.getData());
}
Also used : Reactored(ru.fix.completable.reactor.api.Reactored) Accessors(lombok.experimental.Accessors) Assert.assertNotNull(org.junit.Assert.assertNotNull) lombok.val(lombok.val) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) CompletableReactor(ru.fix.completable.reactor.runtime.CompletableReactor) AtomicReference(java.util.concurrent.atomic.AtomicReference) TimeUnit(java.util.concurrent.TimeUnit) ReactorGraph(ru.fix.completable.reactor.runtime.ReactorGraph) Processor(ru.fix.completable.reactor.runtime.dsl.Processor) ReactorGraphBuilder(ru.fix.completable.reactor.runtime.ReactorGraphBuilder) Subgraph(ru.fix.completable.reactor.runtime.dsl.Subgraph) Data(lombok.Data) Profiler(ru.fix.commons.profiler.Profiler) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) SimpleProfiler(ru.fix.commons.profiler.impl.SimpleProfiler) lombok.val(lombok.val) ReactorGraphBuilder(ru.fix.completable.reactor.runtime.ReactorGraphBuilder) Processor(ru.fix.completable.reactor.runtime.dsl.Processor) AtomicReference(java.util.concurrent.atomic.AtomicReference) CompletableReactor(ru.fix.completable.reactor.runtime.CompletableReactor) Subgraph(ru.fix.completable.reactor.runtime.dsl.Subgraph) Test(org.junit.Test)

Example 3 with ReactorGraph

use of ru.fix.completable.reactor.runtime.ReactorGraph in project completable-reactor by ru-fix.

the class CompletableReactorHandlerArgumentsTest method arguments_test_2.

@Test
public void arguments_test_2() throws Exception {
    @Reactored("Payload with string")
    @Data
    class Payload {

        String data;
    }
    class Service {

        @Reactored("method with 6 arguments")
        public CompletableFuture<String> foo(BigInteger arg1, long arg2) {
            return CompletableFuture.completedFuture("" + arg1 + arg2);
        }
    }
    final Service service = new Service();
    class Config {

        ReactorGraphBuilder graphBuilder = new ReactorGraphBuilder(this);

        Processor<Payload> processor = graphBuilder.processor().forPayload(Payload.class).passArg(pld -> BigInteger.valueOf(6L)).passArg(pld -> 7L).withHandler(service::foo).withMerger((payload, result) -> {
            payload.data = result;
            return CompletableReactorTest.Status.OK;
        }).buildProcessor();

        ReactorGraph<Payload> graph() {
            return graphBuilder.payload(Payload.class).handle(processor).mergePoint(processor).onAny().complete().coordinates().buildGraph();
        }
    }
    val graph = new Config().graph();
    reactor.registerReactorGraph(graph);
    assertEquals("67", reactor.submit(new Payload()).getResultFuture().get(5, TimeUnit.SECONDS).getData());
}
Also used : Reactored(ru.fix.completable.reactor.api.Reactored) lombok.val(lombok.val) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) CompletableReactor(ru.fix.completable.reactor.runtime.CompletableReactor) TimeUnit(java.util.concurrent.TimeUnit) ReactorGraph(ru.fix.completable.reactor.runtime.ReactorGraph) Processor(ru.fix.completable.reactor.runtime.dsl.Processor) ReactorGraphBuilder(ru.fix.completable.reactor.runtime.ReactorGraphBuilder) Data(lombok.Data) BigInteger(java.math.BigInteger) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) SimpleProfiler(ru.fix.commons.profiler.impl.SimpleProfiler) lombok.val(lombok.val) ReactorGraphBuilder(ru.fix.completable.reactor.runtime.ReactorGraphBuilder) Processor(ru.fix.completable.reactor.runtime.dsl.Processor) Reactored(ru.fix.completable.reactor.api.Reactored) BigInteger(java.math.BigInteger) Data(lombok.Data) Test(org.junit.Test)

Example 4 with ReactorGraph

use of ru.fix.completable.reactor.runtime.ReactorGraph in project completable-reactor by ru-fix.

the class CompletableReactorHandlerArgumentsTest method arguments_test_6.

@Test
public void arguments_test_6() throws Exception {
    @Reactored("Payload with string")
    @Data
    class Payload {

        String data;
    }
    class Service {

        @Reactored("method with 6 arguments")
        public CompletableFuture<String> foo(String arg1, short arg2, boolean arg3, Object arg4, BigInteger arg5, long arg6) {
            return CompletableFuture.completedFuture(arg1 + arg2 + arg3 + arg4 + arg5 + arg6);
        }
    }
    final Service service = new Service();
    class Config {

        ReactorGraphBuilder graphBuilder = new ReactorGraphBuilder(this);

        Processor<Payload> processor = graphBuilder.processor().forPayload(Payload.class).passArg(pld -> "1").passArg(pld -> (short) 3).passArg(pld -> true).passArg(pld -> 5).passArg(pld -> BigInteger.valueOf(6L)).passArg(pld -> 7L).withHandler(service::foo).withMerger((payload, result) -> {
            payload.data = result;
            return CompletableReactorTest.Status.OK;
        }).buildProcessor();

        ReactorGraph<Payload> graph() {
            return graphBuilder.payload(Payload.class).handle(processor).mergePoint(processor).onAny().complete().coordinates().buildGraph();
        }
    }
    val graph = new Config().graph();
    reactor.registerReactorGraph(graph);
    assertEquals("13true567", reactor.submit(new Payload()).getResultFuture().get(5, TimeUnit.SECONDS).getData());
}
Also used : Reactored(ru.fix.completable.reactor.api.Reactored) lombok.val(lombok.val) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) CompletableReactor(ru.fix.completable.reactor.runtime.CompletableReactor) TimeUnit(java.util.concurrent.TimeUnit) ReactorGraph(ru.fix.completable.reactor.runtime.ReactorGraph) Processor(ru.fix.completable.reactor.runtime.dsl.Processor) ReactorGraphBuilder(ru.fix.completable.reactor.runtime.ReactorGraphBuilder) Data(lombok.Data) BigInteger(java.math.BigInteger) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) SimpleProfiler(ru.fix.commons.profiler.impl.SimpleProfiler) lombok.val(lombok.val) ReactorGraphBuilder(ru.fix.completable.reactor.runtime.ReactorGraphBuilder) Processor(ru.fix.completable.reactor.runtime.dsl.Processor) Reactored(ru.fix.completable.reactor.api.Reactored) BigInteger(java.math.BigInteger) Data(lombok.Data) Test(org.junit.Test)

Example 5 with ReactorGraph

use of ru.fix.completable.reactor.runtime.ReactorGraph in project completable-reactor by ru-fix.

the class CompletableReactorHandlerArgumentsTest method arguments_test_3.

@Test
public void arguments_test_3() throws Exception {
    @Reactored("Payload with string")
    @Data
    class Payload {

        String data;
    }
    class Service {

        @Reactored("method with 6 arguments")
        public CompletableFuture<String> foo(boolean arg1, BigInteger arg2, long arg3) {
            return CompletableFuture.completedFuture("" + arg1 + arg2 + arg3);
        }
    }
    final Service service = new Service();
    class Config {

        ReactorGraphBuilder graphBuilder = new ReactorGraphBuilder(this);

        Processor<Payload> processor = graphBuilder.processor().forPayload(Payload.class).passArg(pld -> true).passArg(pld -> BigInteger.valueOf(6L)).passArg(pld -> 7L).withHandler(service::foo).withMerger((payload, result) -> {
            payload.data = result;
            return CompletableReactorTest.Status.OK;
        }).buildProcessor();

        ReactorGraph<Payload> graph() {
            return graphBuilder.payload(Payload.class).handle(processor).mergePoint(processor).onAny().complete().coordinates().buildGraph();
        }
    }
    reactor.registerReactorGraph(new Config().graph());
    assertEquals("true67", reactor.submit(new Payload()).getResultFuture().get(5, TimeUnit.SECONDS).getData());
}
Also used : Reactored(ru.fix.completable.reactor.api.Reactored) lombok.val(lombok.val) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) CompletableReactor(ru.fix.completable.reactor.runtime.CompletableReactor) TimeUnit(java.util.concurrent.TimeUnit) ReactorGraph(ru.fix.completable.reactor.runtime.ReactorGraph) Processor(ru.fix.completable.reactor.runtime.dsl.Processor) ReactorGraphBuilder(ru.fix.completable.reactor.runtime.ReactorGraphBuilder) Data(lombok.Data) BigInteger(java.math.BigInteger) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) SimpleProfiler(ru.fix.commons.profiler.impl.SimpleProfiler) ReactorGraphBuilder(ru.fix.completable.reactor.runtime.ReactorGraphBuilder) Processor(ru.fix.completable.reactor.runtime.dsl.Processor) Reactored(ru.fix.completable.reactor.api.Reactored) BigInteger(java.math.BigInteger) Data(lombok.Data) Test(org.junit.Test)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)9 Data (lombok.Data)9 lombok.val (lombok.val)9 ReactorGraph (ru.fix.completable.reactor.runtime.ReactorGraph)9 TimeUnit (java.util.concurrent.TimeUnit)8 Before (org.junit.Before)8 Test (org.junit.Test)8 SimpleProfiler (ru.fix.commons.profiler.impl.SimpleProfiler)8 Reactored (ru.fix.completable.reactor.api.Reactored)8 CompletableReactor (ru.fix.completable.reactor.runtime.CompletableReactor)8 ReactorGraphBuilder (ru.fix.completable.reactor.runtime.ReactorGraphBuilder)8 Processor (ru.fix.completable.reactor.runtime.dsl.Processor)8 Assert.assertEquals (org.junit.Assert.assertEquals)7 BigInteger (java.math.BigInteger)6 Accessors (lombok.experimental.Accessors)3 Slf4j (lombok.extern.slf4j.Slf4j)2 Profiler (ru.fix.commons.profiler.Profiler)2 Subgraph (ru.fix.completable.reactor.runtime.dsl.Subgraph)2 java.util (java.util)1 ArrayList (java.util.ArrayList)1