Search in sources :

Example 6 with Reactored

use of ru.fix.completable.reactor.api.Reactored 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 7 with Reactored

use of ru.fix.completable.reactor.api.Reactored 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 8 with Reactored

use of ru.fix.completable.reactor.api.Reactored 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 9 with Reactored

use of ru.fix.completable.reactor.api.Reactored 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 10 with Reactored

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

Aggregations

Reactored (ru.fix.completable.reactor.api.Reactored)14 lombok.val (lombok.val)12 Data (lombok.Data)8 Test (org.junit.Test)8 ReactorGraphBuilder (ru.fix.completable.reactor.runtime.ReactorGraphBuilder)8 Processor (ru.fix.completable.reactor.runtime.dsl.Processor)8 ReactorGraph (ru.fix.completable.reactor.runtime.ReactorGraph)7 BigInteger (java.math.BigInteger)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 TimeUnit (java.util.concurrent.TimeUnit)6 Assert.assertEquals (org.junit.Assert.assertEquals)6 Before (org.junit.Before)6 SimpleProfiler (ru.fix.commons.profiler.impl.SimpleProfiler)6 CompletableReactor (ru.fix.completable.reactor.runtime.CompletableReactor)6 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Slf4j (lombok.extern.slf4j.Slf4j)1