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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations