Search in sources :

Example 31 with DeploymentOptions

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

the class HATest method testQuorumLost.

@Test
public void testQuorumLost() throws Exception {
    vertx1 = startVertx(3);
    vertx2 = startVertx(3);
    vertx3 = startVertx(3);
    DeploymentOptions options = new DeploymentOptions().setHa(true);
    JsonObject config = new JsonObject().put("foo", "bar");
    options.setConfig(config);
    vertx1.deployVerticle("java:" + HAVerticle1.class.getName(), options, ar -> {
        assertTrue(ar.succeeded());
        assertTrue(vertx1.deploymentIDs().contains(ar.result()));
        ;
    });
    vertx2.deployVerticle("java:" + HAVerticle2.class.getName(), options, ar -> {
        assertTrue(ar.succeeded());
        assertTrue(vertx2.deploymentIDs().contains(ar.result()));
        ;
    });
    waitUntil(() -> vertx1.deploymentIDs().size() == 1 && vertx2.deploymentIDs().size() == 1);
    // Now close vertx3 - quorum should then be lost and verticles undeployed
    CountDownLatch latch = new CountDownLatch(1);
    vertx3.close(ar -> {
        latch.countDown();
    });
    awaitLatch(latch);
    waitUntil(() -> vertx1.deploymentIDs().isEmpty() && vertx2.deploymentIDs().isEmpty());
    // Now re-instate the quorum
    vertx4 = startVertx(3);
    waitUntil(() -> vertx1.deploymentIDs().size() == 1 && vertx2.deploymentIDs().size() == 1);
}
Also used : DeploymentOptions(io.vertx.core.DeploymentOptions) JsonObject(io.vertx.core.json.JsonObject) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 32 with DeploymentOptions

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

the class HATest method testNoFailoverToNonHANode.

@Test
public void testNoFailoverToNonHANode() throws Exception {
    vertx1 = startVertx();
    // Create a non HA node
    vertx2 = startVertx(null, 0, false);
    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).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
        fail("Should not failover here 2");
    });
    ((VertxInternal) vertx1).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
        fail("Should not failover here 1");
    });
    ((VertxInternal) vertx1).simulateKill();
    vertx2.close(ar -> {
        vertx.setTimer(500, tid -> {
            testComplete();
        });
    });
    await();
}
Also used : DeploymentOptions(io.vertx.core.DeploymentOptions) VertxInternal(io.vertx.core.impl.VertxInternal) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 33 with DeploymentOptions

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

the class RunCommand method run.

/**
   * Starts vert.x and deploy the verticle.
   */
@Override
public void run() {
    if (redeploy == null || redeploy.isEmpty()) {
        JsonObject conf = getConfiguration();
        if (conf == null) {
            conf = new JsonObject();
        }
        afterConfigParsed(conf);
        super.run();
        if (vertx == null) {
            // Already logged.
            ExecUtils.exitBecauseOfVertxInitializationIssue();
        }
        deploymentOptions = new DeploymentOptions();
        configureFromSystemProperties(deploymentOptions, DEPLOYMENT_OPTIONS_PROP_PREFIX);
        deploymentOptions.setConfig(conf).setWorker(worker).setHa(ha).setInstances(instances);
        beforeDeployingVerticle(deploymentOptions);
        deploy();
    } else {
        // redeploy is set, start the redeployment infrastructure (watcher).
        initializeRedeployment();
    }
}
Also used : DeploymentOptions(io.vertx.core.DeploymentOptions) JsonObject(io.vertx.core.json.JsonObject)

Example 34 with DeploymentOptions

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

the class HATest method testCleanCloseNoFailover.

@Test
public void testCleanCloseNoFailover() throws Exception {
    vertx1 = startVertx();
    vertx2 = startVertx();
    DeploymentOptions options = new DeploymentOptions().setHa(true);
    JsonObject config = new JsonObject().put("foo", "bar");
    options.setConfig(config);
    CountDownLatch deployLatch = new CountDownLatch(1);
    vertx2.deployVerticle("java:" + HAVerticle1.class.getName(), options, ar -> {
        assertTrue(ar.succeeded());
        deployLatch.countDown();
    });
    awaitLatch(deployLatch);
    ((VertxInternal) vertx1).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
        fail("Should not be called");
    });
    vertx2.close(ar -> {
        vertx.setTimer(500, tid -> {
            testComplete();
        });
    });
    await();
}
Also used : DeploymentOptions(io.vertx.core.DeploymentOptions) VertxInternal(io.vertx.core.impl.VertxInternal) JsonObject(io.vertx.core.json.JsonObject) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 35 with DeploymentOptions

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

the class HATest method testHaGroups.

@Test
public void testHaGroups() throws Exception {
    vertx1 = startVertx("group1", 1);
    vertx2 = startVertx("group1", 1);
    vertx3 = startVertx("group2", 1);
    vertx4 = startVertx("group2", 1);
    CountDownLatch latch1 = new CountDownLatch(2);
    vertx1.deployVerticle("java:" + HAVerticle1.class.getName(), new DeploymentOptions().setHa(true), ar -> {
        assertTrue(ar.succeeded());
        assertTrue(vertx1.deploymentIDs().contains(ar.result()));
        latch1.countDown();
    });
    vertx3.deployVerticle("java:" + HAVerticle2.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);
    ((VertxInternal) vertx1).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
        fail("Should not failover here 1");
    });
    ((VertxInternal) vertx2).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
        fail("Should not failover here 2");
    });
    ((VertxInternal) vertx4).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
        assertTrue(succeeded);
        latch2.countDown();
    });
    ((VertxInternal) vertx3).simulateKill();
    awaitLatch(latch2);
    assertTrue(vertx4.deploymentIDs().size() == 1);
    CountDownLatch latch3 = new CountDownLatch(1);
    ((VertxInternal) vertx2).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
        assertTrue(succeeded);
        latch3.countDown();
    });
    ((VertxInternal) vertx4).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
        fail("Should not failover here 4");
    });
    ((VertxInternal) vertx1).simulateKill();
    awaitLatch(latch3);
    assertTrue(vertx2.deploymentIDs().size() == 1);
}
Also used : DeploymentOptions(io.vertx.core.DeploymentOptions) VertxInternal(io.vertx.core.impl.VertxInternal) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

DeploymentOptions (io.vertx.core.DeploymentOptions)39 Test (org.junit.Test)25 CountDownLatch (java.util.concurrent.CountDownLatch)17 AbstractVerticle (io.vertx.core.AbstractVerticle)15 JsonObject (io.vertx.core.json.JsonObject)10 Context (io.vertx.core.Context)8 Vertx (io.vertx.core.Vertx)7 VertxInternal (io.vertx.core.impl.VertxInternal)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Future (io.vertx.core.Future)4 HttpClientOptions (io.vertx.core.http.HttpClientOptions)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Verticle (io.vertx.core.Verticle)3 VertxException (io.vertx.core.VertxException)3 Buffer (io.vertx.core.buffer.Buffer)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Collections (java.util.Collections)3 TimeUnit (java.util.concurrent.TimeUnit)3