Search in sources :

Example 1 with Vertx

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();
                    });
                });
            });
        });
    });
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) VertxInstance(io.vertx.core.VertxInstance) ClusterManager(io.vertx.core.spi.cluster.ClusterManager) RunWith(org.junit.runner.RunWith) Timeout(io.vertx.ext.unit.junit.Timeout) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Vertx(io.vertx.reactivex.core.Vertx) Rule(org.junit.Rule) Observable(io.reactivex.Observable) Glue(in.erail.glue.Glue) Async(io.vertx.ext.unit.Async) Vertx(io.vertx.reactivex.core.Vertx) ClusterManager(io.vertx.core.spi.cluster.ClusterManager) Test(org.junit.Test)

Example 2 with Vertx

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);
    });
}
Also used : Vertx(io.vertx.reactivex.core.Vertx)

Example 3 with 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);
}
Also used : AdapterRequest(io.knotx.dataobjects.AdapterRequest) Async(io.vertx.ext.unit.Async) AdapterProxy(io.knotx.reactivex.proxy.AdapterProxy) Vertx(io.vertx.reactivex.core.Vertx)

Example 4 with Vertx

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);
    });
}
Also used : KnotContext(io.knotx.dataobjects.KnotContext) OptionalAction(io.knotx.util.OptionalAction) KnotProxy(io.knotx.reactivex.proxy.KnotProxy) HashMap(java.util.HashMap) RoutingContext(io.vertx.reactivex.ext.web.RoutingContext) LoggerFactory(io.vertx.core.logging.LoggerFactory) RoutingEntry(io.knotx.server.configuration.RoutingEntry) Vertx(io.vertx.reactivex.core.Vertx) Map(java.util.Map) Optional(java.util.Optional) Handler(io.vertx.core.Handler) Logger(io.vertx.core.logging.Logger) KnotxServerConfiguration(io.knotx.server.configuration.KnotxServerConfiguration) RoutingEntry(io.knotx.server.configuration.RoutingEntry) KnotContext(io.knotx.dataobjects.KnotContext)

Example 5 with Vertx

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);
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) KnotContext(io.knotx.dataobjects.KnotContext) RunWith(org.junit.runner.RunWith) Logback(io.knotx.junit.rule.Logback) Action1(rx.functions.Action1) StringUtils(org.apache.commons.lang3.StringUtils) Vertx(io.vertx.reactivex.core.Vertx) FileReader(io.knotx.junit.util.FileReader) Pair(org.apache.commons.lang3.tuple.Pair) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration) TestVertxDeployer(io.knotx.junit.rule.TestVertxDeployer) KnotProxy(io.knotx.reactivex.proxy.KnotProxy) KnotContextFactory(io.knotx.junit.util.KnotContextFactory) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) IOException(java.io.IOException) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) RuleChain(org.junit.rules.RuleChain) List(java.util.List) Rule(org.junit.Rule) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) Collections(java.util.Collections) Async(io.vertx.ext.unit.Async) KnotProxy(io.knotx.reactivex.proxy.KnotProxy) Vertx(io.vertx.reactivex.core.Vertx)

Aggregations

Vertx (io.vertx.reactivex.core.Vertx)10 KnotContext (io.knotx.dataobjects.KnotContext)5 KnotProxy (io.knotx.reactivex.proxy.KnotProxy)5 Async (io.vertx.ext.unit.Async)5 KnotxServerConfiguration (io.knotx.server.configuration.KnotxServerConfiguration)3 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)3 Handler (io.vertx.core.Handler)3 Logger (io.vertx.core.logging.Logger)3 LoggerFactory (io.vertx.core.logging.LoggerFactory)3 TestContext (io.vertx.ext.unit.TestContext)3 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)3 RoutingContext (io.vertx.reactivex.ext.web.RoutingContext)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Rule (org.junit.Rule)3 Test (org.junit.Test)3 RunWith (org.junit.runner.RunWith)3 KnotxConfiguration (io.knotx.junit.rule.KnotxConfiguration)2 Logback (io.knotx.junit.rule.Logback)2 TestVertxDeployer (io.knotx.junit.rule.TestVertxDeployer)2