Search in sources :

Example 11 with ReactorGraphBuilder

use of ru.fix.completable.reactor.runtime.ReactorGraphBuilder 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 12 with ReactorGraphBuilder

use of ru.fix.completable.reactor.runtime.ReactorGraphBuilder 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)

Example 13 with ReactorGraphBuilder

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

the class CompletableReactorHandlerArgumentsTest method arguments_test_4.

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

        String data;
    }
    class Service {

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

        ReactorGraphBuilder graphBuilder = new ReactorGraphBuilder(this);

        Processor<Payload> processor = graphBuilder.processor().forPayload(Payload.class).passArg(pld -> (short) 3).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();
        }
    }
    val graph = new Config().graph();
    reactor.registerReactorGraph(graph);
    assertEquals("3true67", 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 14 with ReactorGraphBuilder

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

the class CompletableReactorHandlerArgumentsTest method arguments_test_5.

@Test
public void arguments_test_5() 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, BigInteger arg4, long arg5) {
            return CompletableFuture.completedFuture(arg1 + arg2 + arg3 + arg4 + arg5);
        }
    }
    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 -> 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("13true67", 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 15 with ReactorGraphBuilder

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

the class CompletableReactorHandlerArgumentsTest method arguments_test_1.

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

        String data;
    }
    class Service {

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

        ReactorGraphBuilder graphBuilder = new ReactorGraphBuilder(this);

        Processor<Payload> processor = graphBuilder.processor().forPayload(Payload.class).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("7", reactor.submit(new Payload()).getResultFuture().get(5, TimeUnit.SECONDS).getData());
}
Also used : ReactorGraphBuilder(ru.fix.completable.reactor.runtime.ReactorGraphBuilder) Processor(ru.fix.completable.reactor.runtime.dsl.Processor) Reactored(ru.fix.completable.reactor.api.Reactored) Data(lombok.Data) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)24 ReactorGraphBuilder (ru.fix.completable.reactor.runtime.ReactorGraphBuilder)24 lombok.val (lombok.val)23 Processor (ru.fix.completable.reactor.runtime.dsl.Processor)23 CompletableReactor (ru.fix.completable.reactor.runtime.CompletableReactor)13 Data (lombok.Data)10 Reactored (ru.fix.completable.reactor.api.Reactored)10 CompletableFuture (java.util.concurrent.CompletableFuture)8 TimeUnit (java.util.concurrent.TimeUnit)8 Before (org.junit.Before)8 SimpleProfiler (ru.fix.commons.profiler.impl.SimpleProfiler)8 ReactorGraph (ru.fix.completable.reactor.runtime.ReactorGraph)8 Assert.assertEquals (org.junit.Assert.assertEquals)7 MergePoint (ru.fix.completable.reactor.runtime.dsl.MergePoint)7 BigInteger (java.math.BigInteger)6 Semaphore (java.util.concurrent.Semaphore)3 TimeoutException (java.util.concurrent.TimeoutException)3 Accessors (lombok.experimental.Accessors)2 lombok.experimental.var (lombok.experimental.var)2 Subgraph (ru.fix.completable.reactor.runtime.dsl.Subgraph)2