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);
}
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();
}
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();
}
}
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();
}
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);
}
Aggregations