Search in sources :

Example 11 with VertxInternal

use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.

the class ComplexHATest method kill.

protected void kill(int pos) {
    // Save the deploymentIDs first
    takeDeploymentSnapshots();
    VertxInternal v = (VertxInternal) vertices[pos];
    killedNode = pos;
    v.executeBlocking(fut -> {
        v.simulateKill();
        fut.complete();
    }, false, ar -> {
        assertTrue(ar.succeeded());
    });
}
Also used : VertxInternal(io.vertx.core.impl.VertxInternal)

Example 12 with VertxInternal

use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.

the class ComplexHATest method checkDeployments.

protected void checkDeployments() {
    int totalDeployed = 0;
    for (int i = 0; i < vertices.length; i++) {
        VertxInternal v = (VertxInternal) vertices[i];
        if (!v.isKilled()) {
            totalDeployed += checkHasDeployments(i, i);
        }
    }
    assertEquals(totDeployed, totalDeployed);
}
Also used : VertxInternal(io.vertx.core.impl.VertxInternal)

Example 13 with VertxInternal

use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.

the class VertxTest method testCloseHookFailure1.

@Test
public void testCloseHookFailure1() throws Exception {
    AtomicInteger closedCount = new AtomicInteger();
    class Hook implements Closeable {

        @Override
        public void close(Handler<AsyncResult<Void>> completionHandler) {
            if (closedCount.incrementAndGet() == 1) {
                throw new RuntimeException();
            } else {
                completionHandler.handle(Future.succeededFuture());
            }
        }
    }
    VertxInternal vertx = (VertxInternal) Vertx.vertx();
    vertx.addCloseHook(new Hook());
    vertx.addCloseHook(new Hook());
    // Now undeploy
    vertx.close(ar -> {
        assertTrue(ar.succeeded());
        assertEquals(2, closedCount.get());
        testComplete();
    });
    await();
}
Also used : VertxInternal(io.vertx.core.impl.VertxInternal) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Closeable(io.vertx.core.Closeable) Handler(io.vertx.core.Handler) Test(org.junit.Test)

Example 14 with VertxInternal

use of io.vertx.core.impl.VertxInternal in project vertx-web by vert-x3.

the class MVELTemplateEngineImpl method render.

@Override
public void render(RoutingContext context, String templateDirectory, String templateFileName, Handler<AsyncResult<Buffer>> handler) {
    try {
        templateFileName = templateDirectory + templateFileName;
        CompiledTemplate template = isCachingEnabled() ? cache.get(templateFileName) : null;
        if (template == null) {
            // real compile
            String loc = adjustLocation(templateFileName);
            String templateText = Utils.readFileToString(context.vertx(), loc);
            if (templateText == null) {
                throw new IllegalArgumentException("Cannot find template " + loc);
            }
            template = TemplateCompiler.compileTemplate(templateText);
            if (isCachingEnabled()) {
                cache.put(templateFileName, template);
            }
        }
        Map<String, RoutingContext> variables = new HashMap<>(1);
        variables.put("context", context);
        final VertxInternal vertxInternal = (VertxInternal) context.vertx();
        String directoryName = vertxInternal.resolveFile(templateFileName).getParent();
        handler.handle(Future.succeededFuture(Buffer.buffer((String) new TemplateRuntime(template.getTemplate(), null, template.getRoot(), directoryName).execute(new StringAppender(), variables, new ImmutableDefaultFactory()))));
    } catch (Exception ex) {
        handler.handle(Future.failedFuture(ex));
    }
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) VertxInternal(io.vertx.core.impl.VertxInternal) ImmutableDefaultFactory(org.mvel2.integration.impl.ImmutableDefaultFactory) HashMap(java.util.HashMap) StringAppender(org.mvel2.util.StringAppender) TemplateRuntime(org.mvel2.templates.TemplateRuntime) CompiledTemplate(org.mvel2.templates.CompiledTemplate)

Example 15 with VertxInternal

use of io.vertx.core.impl.VertxInternal in project vertx-auth by vert-x3.

the class StormpathTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    // Setup our shiro+stormpath+vertx integration
    File file = ((VertxInternal) vertx).resolveFile("stormpath.properties");
    ApiKey apiKey = ApiKeys.builder().setFileLocation(file.getAbsolutePath()).build();
    Client client = Clients.builder().setApiKey(apiKey).build();
    ApplicationRealm stormpathAppRealm = new ApplicationRealm();
    stormpathAppRealm.setClient(client);
    stormpathAppRealm.setApplicationRestUrl("https://api.stormpath.com/v1/applications/2oFtzixwgN0wYKt25euKpg");
    authProvider = ShiroAuth.create(vertx, stormpathAppRealm);
}
Also used : VertxInternal(io.vertx.core.impl.VertxInternal) ApiKey(com.stormpath.sdk.api.ApiKey) Client(com.stormpath.sdk.client.Client) File(java.io.File) ApplicationRealm(com.stormpath.shiro.realm.ApplicationRealm)

Aggregations

VertxInternal (io.vertx.core.impl.VertxInternal)100 Test (org.junit.Test)73 CountDownLatch (java.util.concurrent.CountDownLatch)46 VertxOptions (io.vertx.core.VertxOptions)30 JsonObject (io.vertx.core.json.JsonObject)29 Buffer (io.vertx.core.buffer.Buffer)28 File (java.io.File)27 AtomicReference (java.util.concurrent.atomic.AtomicReference)27 VertxException (io.vertx.core.VertxException)24 HttpClient (io.vertx.core.http.HttpClient)24 NetClient (io.vertx.core.net.NetClient)24 TimeUnit (java.util.concurrent.TimeUnit)24 NetServerOptions (io.vertx.core.net.NetServerOptions)23 InetAddress (java.net.InetAddress)23 Channel (io.netty.channel.Channel)22 InetSocketAddress (java.net.InetSocketAddress)22 CompletableFuture (java.util.concurrent.CompletableFuture)22 NetServer (io.vertx.core.net.NetServer)21 ChannelFuture (io.netty.channel.ChannelFuture)20 Bootstrap (io.netty.bootstrap.Bootstrap)19