Search in sources :

Example 6 with Vertx

use of io.vertx.reactivex.core.Vertx in project knotx by Cognifide.

the class HtmlFragmentSplitterVerticleTest method callFragmentSplitterWithAssertions.

private void callFragmentSplitterWithAssertions(TestContext context, String template, Action1<KnotContext> testFunction) {
    Async async = context.async();
    KnotProxy service = KnotProxy.createProxy(new Vertx(vertx.vertx()), ADDRESS);
    service.rxProcess(KnotContextFactory.empty(template)).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) KnotContext(io.knotx.dataobjects.KnotContext) KnotProxy(io.knotx.reactivex.proxy.KnotProxy) RunWith(org.junit.runner.RunWith) KnotContextFactory(io.knotx.junit.util.KnotContextFactory) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) Test(org.junit.Test) Logback(io.knotx.junit.rule.Logback) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Action1(rx.functions.Action1) RuleChain(org.junit.rules.RuleChain) Vertx(io.vertx.reactivex.core.Vertx) Rule(org.junit.Rule) FileReader(io.knotx.junit.util.FileReader) Pair(org.apache.commons.lang3.tuple.Pair) KnotxConfiguration(io.knotx.junit.rule.KnotxConfiguration) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) TestVertxDeployer(io.knotx.junit.rule.TestVertxDeployer) Async(io.vertx.ext.unit.Async) KnotProxy(io.knotx.reactivex.proxy.KnotProxy) Vertx(io.vertx.reactivex.core.Vertx)

Example 7 with Vertx

use of io.vertx.reactivex.core.Vertx in project knotx by Cognifide.

the class KnotxRepositoryHandler method handle.

@Override
public void handle(RoutingContext context) {
    final Optional<RepositoryEntry> repositoryEntry = configuration.getDefaultFlow().repositoryForPath(context.request().path());
    final KnotContext knotContext = context.get(KnotContext.KEY);
    if (repositoryEntry.isPresent()) {
        proxies.computeIfAbsent(repositoryEntry.get().address(), adr -> RepositoryConnectorProxy.createProxyWithOptions(vertx, adr, configuration.getDeliveryOptions())).rxProcess(knotContext.getClientRequest()).doOnSuccess(this::traceMessage).subscribe(repoResponse -> handleRepositoryResponse(repoResponse, context, repositoryEntry.get(), knotContext), context::fail);
    } else {
        context.fail(HttpResponseStatus.NOT_FOUND.code());
    }
}
Also used : KnotContext(io.knotx.dataobjects.KnotContext) RepositoryConnectorProxy(io.knotx.reactivex.proxy.RepositoryConnectorProxy) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) HashMap(java.util.HashMap) HttpServerResponse(io.vertx.reactivex.core.http.HttpServerResponse) RoutingContext(io.vertx.reactivex.ext.web.RoutingContext) LoggerFactory(io.vertx.core.logging.LoggerFactory) ClientResponse(io.knotx.dataobjects.ClientResponse) RepositoryEntry(io.knotx.server.configuration.RepositoryEntry) MultiMap(io.vertx.reactivex.core.MultiMap) 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) Buffer(io.vertx.reactivex.core.buffer.Buffer) KnotContext(io.knotx.dataobjects.KnotContext) RepositoryEntry(io.knotx.server.configuration.RepositoryEntry)

Example 8 with Vertx

use of io.vertx.reactivex.core.Vertx in project knotx by Cognifide.

the class ActionKnotProxyVerticleTest method callActionKnotWithAssertions.

private void callActionKnotWithAssertions(TestContext context, KnotContext knotContext, Action1<KnotContext> onSuccess, Consumer<Throwable> onError) {
    Async async = context.async();
    KnotProxy actionKnot = KnotProxy.createProxy(new Vertx(vertx.vertx()), ADDRESS);
    actionKnot.rxProcess(knotContext).doOnSuccess(onSuccess::call).subscribe(success -> async.complete(), onError);
}
Also used : Async(io.vertx.ext.unit.Async) KnotProxy(io.knotx.reactivex.proxy.KnotProxy) Vertx(io.vertx.reactivex.core.Vertx)

Example 9 with Vertx

use of io.vertx.reactivex.core.Vertx in project knotx by Cognifide.

the class KnotxGatewayContextHandler method handle.

@Override
public void handle(RoutingContext context) {
    KnotContext knotContext = context.get(KnotContext.KEY);
    String bodyAsString = context.getBodyAsString();
    if (StringUtils.isNotBlank(bodyAsString)) {
        knotContext.setFragments(Collections.singletonList(Fragment.raw(bodyAsString)));
    }
    LOGGER.debug("CustomFlow: Routing the traffic to '{}'", address);
    proxies.computeIfAbsent(address, adr -> KnotProxy.createProxyWithOptions(vertx, adr, configuration.getDeliveryOptions())).rxProcess(knotContext).doOnSuccess(ctx -> context.put(KnotContext.KEY, ctx)).subscribe(ctx -> {
        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) KnotProxy(io.knotx.reactivex.proxy.KnotProxy) Fragment(io.knotx.dataobjects.Fragment) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) RoutingContext(io.vertx.reactivex.ext.web.RoutingContext) LoggerFactory(io.vertx.core.logging.LoggerFactory) Vertx(io.vertx.reactivex.core.Vertx) Map(java.util.Map) Handler(io.vertx.core.Handler) Logger(io.vertx.core.logging.Logger) KnotxServerConfiguration(io.knotx.server.configuration.KnotxServerConfiguration) Collections(java.util.Collections) KnotContext(io.knotx.dataobjects.KnotContext)

Example 10 with Vertx

use of io.vertx.reactivex.core.Vertx in project knotx by Cognifide.

the class TestVertxDeployer method apply.

@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            KnotxConfiguration knotxConfig = description.getAnnotation(KnotxConfiguration.class);
            if (knotxConfig == null || knotxConfig.value().isEmpty()) {
                throw new IllegalArgumentException("Missing @KnotxConfiguration annotation with the path to configuration JSON");
            }
            Vertx vertx = Vertx.newInstance(vertxContext.vertx());
            CompletableFuture<Void> toComplete = new CompletableFuture<>();
            vertx.deployVerticle(KnotxStarterVerticle.class.getName(), new DeploymentOptions().setConfig(readJson(knotxConfig.value())), ar -> {
                if (ar.succeeded()) {
                    toComplete.complete(null);
                } else {
                    toComplete.completeExceptionally(ar.cause());
                }
            });
            try {
                toComplete.get();
            } catch (ExecutionException ignore) {
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                throw e;
            }
            base.evaluate();
        }
    };
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) DeploymentOptions(io.vertx.core.DeploymentOptions) Statement(org.junit.runners.model.Statement) KnotxStarterVerticle(io.knotx.launcher.KnotxStarterVerticle) Vertx(io.vertx.reactivex.core.Vertx) ExecutionException(java.util.concurrent.ExecutionException)

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