Search in sources :

Example 91 with VertxInternal

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

the class HATest method checkDeploymentExists.

protected void checkDeploymentExists(int pos, String verticleName, DeploymentOptions options) {
    VertxInternal vi = (VertxInternal) vertices[pos];
    for (String deploymentID : vi.deploymentIDs()) {
        Deployment dep = vi.getDeployment(deploymentID);
        if (verticleName.equals(dep.verticleIdentifier()) && options.toJson().equals(dep.deploymentOptions().toJson())) {
            return;
        }
    }
    fail("Can't find deployment for verticleName: " + verticleName + " on node " + pos);
}
Also used : VertxInternal(io.vertx.core.impl.VertxInternal) Deployment(io.vertx.core.impl.Deployment)

Example 92 with VertxInternal

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

the class HATest method kill.

protected void kill(int pos) {
    VertxInternal v = (VertxInternal) vertices[pos];
    v.executeBlocking(fut -> {
        try {
            v.simulateKill();
            fut.complete();
        } catch (Exception e) {
            fut.fail(e);
        }
    }, false, ar -> {
        if (!ar.succeeded()) {
            fail(ar.cause());
        }
    });
}
Also used : VertxInternal(io.vertx.core.impl.VertxInternal)

Example 93 with VertxInternal

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

the class TimerTest method testPeriodicOnContext.

@Test
public void testPeriodicOnContext() {
    disableThreadChecks();
    waitFor(4);
    ContextInternal ctx1 = ((VertxInternal) vertx).createEventLoopContext();
    ContextInternal ctx2 = ((VertxInternal) vertx).createEventLoopContext();
    assertNotSame(ctx1, ctx2);
    ctx2.runOnContext(v -> {
        vertx.setPeriodic(10, new Handler<Long>() {

            int count;

            @Override
            public void handle(Long l) {
                assertSame(ctx2, vertx.getOrCreateContext());
                if (++count == 2) {
                    vertx.cancelTimer(l);
                }
                complete();
            }
        });
        ctx1.setPeriodic(10, new Handler<Long>() {

            int count;

            @Override
            public void handle(Long l) {
                assertSame(ctx1, vertx.getOrCreateContext());
                if (++count == 2) {
                    vertx.cancelTimer(l);
                }
                complete();
            }
        });
    });
    await();
}
Also used : VertxInternal(io.vertx.core.impl.VertxInternal) AtomicLong(java.util.concurrent.atomic.AtomicLong) ContextInternal(io.vertx.core.impl.ContextInternal) Test(org.junit.Test)

Example 94 with VertxInternal

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

the class HATest method testFailureInFailover.

@Test
public void testFailureInFailover() throws Exception {
    vertx1 = startVertx();
    vertx2 = startVertx();
    vertx3 = startVertx();
    CountDownLatch latch1 = new CountDownLatch(1);
    vertx1.deployVerticle("java:" + HAVerticle1.class.getName(), new DeploymentOptions().setHa(true), ar -> {
        assertTrue(ar.succeeded());
        assertTrue(vertx1.deploymentIDs().contains(ar.result()));
        latch1.countDown();
    });
    awaitLatch(latch1);
    ((VertxInternal) vertx2).failDuringFailover(true);
    ((VertxInternal) vertx3).failDuringFailover(true);
    CountDownLatch latch2 = new CountDownLatch(1);
    ((VertxInternal) vertx2).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
        assertFalse(succeeded);
        latch2.countDown();
    });
    ((VertxInternal) vertx3).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
        assertFalse(succeeded);
        latch2.countDown();
    });
    ((VertxInternal) vertx1).simulateKill();
    awaitLatch(latch2);
    // Now try again - this time failover should work
    assertTrue(vertx2.deploymentIDs().isEmpty());
    assertTrue(vertx3.deploymentIDs().isEmpty());
    ((VertxInternal) vertx2).failDuringFailover(false);
    CountDownLatch latch3 = new CountDownLatch(1);
    ((VertxInternal) vertx2).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
        assertTrue(succeeded);
        latch3.countDown();
    });
    ((VertxInternal) vertx3).simulateKill();
    awaitLatch(latch3);
    assertWaitUntil(() -> vertx2.deploymentIDs().size() == 1);
}
Also used : VertxInternal(io.vertx.core.impl.VertxInternal) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 95 with VertxInternal

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

the class HATest method testNonHADeployments.

@Test
public void testNonHADeployments() throws Exception {
    vertx1 = startVertx();
    vertx2 = startVertx();
    // Deploy an HA and a non HA deployment
    CountDownLatch latch1 = new CountDownLatch(2);
    vertx2.deployVerticle("java:" + HAVerticle1.class.getName(), new DeploymentOptions().setHa(true), ar -> {
        assertTrue(ar.succeeded());
        assertTrue(vertx2.deploymentIDs().contains(ar.result()));
        latch1.countDown();
    });
    vertx2.deployVerticle("java:" + HAVerticle2.class.getName(), new DeploymentOptions().setHa(false), ar -> {
        assertTrue(ar.succeeded());
        assertTrue(vertx2.deploymentIDs().contains(ar.result()));
        latch1.countDown();
    });
    awaitLatch(latch1);
    CountDownLatch latch2 = new CountDownLatch(1);
    ((VertxInternal) vertx1).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
        assertTrue(succeeded);
        latch2.countDown();
    });
    ((VertxInternal) vertx2).simulateKill();
    awaitLatch(latch2);
    assertTrue(vertx1.deploymentIDs().size() == 1);
    String depID = vertx1.deploymentIDs().iterator().next();
    assertTrue(((VertxInternal) vertx1).getDeployment(depID).verticleIdentifier().equals("java:" + HAVerticle1.class.getName()));
}
Also used : VertxInternal(io.vertx.core.impl.VertxInternal) CountDownLatch(java.util.concurrent.CountDownLatch) HAVerticle1(io.vertx.test.verticles.HAVerticle1) Test(org.junit.Test)

Aggregations

VertxInternal (io.vertx.core.impl.VertxInternal)102 Test (org.junit.Test)73 CountDownLatch (java.util.concurrent.CountDownLatch)46 VertxOptions (io.vertx.core.VertxOptions)30 Buffer (io.vertx.core.buffer.Buffer)29 JsonObject (io.vertx.core.json.JsonObject)29 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