use of io.vertx.reactivex.core.Vertx in project api-framework by vinscom.
the class SingletonServiceImplTest method testStart.
@Test
public void testStart(TestContext context) throws InterruptedException, ExecutionException {
Async async = context.async(2);
Vertx vertx = Glue.instance().resolve("/io/vertx/core/Vertx");
ClusterManager cm = Glue.instance().resolve("/io/vertx/spi/cluster/ClusterManager");
vertx.sharedData().<String, String>rxGetClusterWideMap("__in.erail.services").flatMapCompletable(// Service is running on some other node
(m) -> m.rxPut("DummySingletonService", "NodeDownID")).subscribe(() -> {
DummySingletonService service = Glue.instance().resolve("/in/erail/service/DummySingletonService");
Observable.timer(100, TimeUnit.MILLISECONDS).subscribe((t) -> {
vertx.sharedData().<String, String>rxGetClusterWideMap("__in.erail.services").flatMap((m) -> {
return m.rxGet("DummySingletonService");
}).doOnSuccess((nodeId) -> {
// Validate after starting this service. Control is still with other node
context.assertNotEquals(cm.getNodeID(), nodeId);
async.countDown();
}).subscribe((nodeId) -> {
// Trigger remote node leave
service.nodeLeft("NodeDownID");
Observable.timer(100, TimeUnit.MILLISECONDS).subscribe((p) -> {
vertx.sharedData().<String, String>rxGetClusterWideMap("__in.erail.services").flatMap(m2 -> {
return m2.rxGet("DummySingletonService");
}).subscribe((updatedNodeId) -> {
context.assertEquals(cm.getNodeID(), updatedNodeId);
context.assertEquals(service.getRecorder().size(), 1);
async.countDown();
});
});
});
});
});
}
use of io.vertx.reactivex.core.Vertx in project vertx-zero by silentbalanceyh.
the class ZeroLauncher method startStandalone.
private void startStandalone(final Consumer<Vertx> consumer) {
Motor.each((name, option) -> {
final Vertx vertx = Vertx.vertx(option);
Motor.codec(vertx.eventBus().getDelegate());
VERTX.putIfAbsent(name, vertx);
consumer.accept(vertx);
});
}
use of io.vertx.reactivex.core.Vertx in project knotx by Cognifide.
the class HttpServiceAdapterProxyTest method callAdapterServiceWithAssertions.
private void callAdapterServiceWithAssertions(TestContext context, String servicePath, Action1<AdapterResponse> onSuccess, Consumer<Throwable> onError) {
AdapterRequest message = payloadMessage(servicePath);
Async async = context.async();
AdapterProxy service = AdapterProxy.createProxy(new Vertx(vertx.vertx()), ADAPTER_ADDRESS);
service.rxProcess(message).doOnSuccess(onSuccess::call).subscribe(success -> async.complete(), onError);
}
use of io.vertx.reactivex.core.Vertx in project knotx by Cognifide.
the class KnotxEngineHandler method handleRoute.
private void handleRoute(final RoutingContext context, final String address, final Map<String, RoutingEntry> routing) {
KnotContext knotContext = context.get(KnotContext.KEY);
proxies.computeIfAbsent(address, adr -> KnotProxy.createProxyWithOptions(vertx, adr, configuration.getDeliveryOptions())).rxProcess(knotContext).doOnSuccess(ctx -> context.put(KnotContext.KEY, ctx)).subscribe(ctx -> OptionalAction.of(Optional.ofNullable(ctx.getTransition())).ifPresent(on -> {
RoutingEntry entry = routing.get(on);
if (entry != null) {
handleRoute(context, entry.address(), entry.onTransition());
} else {
LOGGER.debug("Received transition '{}' from '{}'. No further routing available for the transition. Go to the response generation.", on, address);
// last knot can return default transition
context.put(KnotContext.KEY, ctx);
context.next();
}
}).ifNotPresent(() -> {
LOGGER.debug("Request processing finished by {} Knot. Go to the response generation", address);
context.put(KnotContext.KEY, ctx);
context.next();
}), error -> {
LOGGER.error("Error happened while communicating with {} engine", error, address);
context.fail(error);
});
}
use of io.vertx.reactivex.core.Vertx in project knotx by Cognifide.
the class FragmentAssemblerTest method callAssemblerWithAssertions.
private void callAssemblerWithAssertions(TestContext context, List<Pair<List<String>, String>> fragments, Action1<KnotContext> testFunction) {
Async async = context.async();
KnotProxy service = KnotProxy.createProxy(new Vertx(vertx.vertx()), ADDRESS);
service.rxProcess(KnotContextFactory.create(fragments)).map(ctx -> Pair.of(async, ctx)).doOnSuccess(success -> testFunction.call(success.getRight())).subscribe(success -> async.complete(), context::fail);
}
Aggregations