Search in sources :

Example 1 with HAVerticle1

use of io.vertx.test.verticles.HAVerticle1 in project vert.x by eclipse.

the class HATest method testCloseRemovesFromCluster.

@Test
public void testCloseRemovesFromCluster() throws Exception {
    vertx1 = startVertx();
    vertx2 = startVertx();
    vertx3 = startVertx();
    CountDownLatch latch1 = new CountDownLatch(1);
    vertx3.deployVerticle("java:" + HAVerticle1.class.getName(), new DeploymentOptions().setHa(true), ar -> {
        assertTrue(ar.succeeded());
        assertTrue(vertx3.deploymentIDs().contains(ar.result()));
        latch1.countDown();
    });
    awaitLatch(latch1);
    CountDownLatch latch2 = new CountDownLatch(1);
    // Close vertx2 - this should not then participate in failover
    vertx2.close(ar -> {
        ((VertxInternal) vertx1).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
            assertTrue(succeeded);
            latch2.countDown();
        });
        ((VertxInternal) vertx3).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)

Example 2 with HAVerticle1

use of io.vertx.test.verticles.HAVerticle1 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)2 HAVerticle1 (io.vertx.test.verticles.HAVerticle1)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Test (org.junit.Test)2