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()); } }); }
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.equals(dep.deploymentOptions())) { return; } } fail("Can't find deployment for verticleName: " + verticleName + " on node " + pos); }
@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 -> { // Wait a bit in case failover happens testComplete(); }); }); await(); }
@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 -> { // Wait a bit in case failover happens testComplete(); }); }); await(); }
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) -> { }); ((VertxInternal)vertx4).failoverCompleteHandler((nodeID, haInfo, succeeded) -> { fail("Should not failover here 4"); }); ((VertxInternal)vertx1).simulateKill();
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()); } }); }
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.equals(dep.deploymentOptions())) { return; } } fail("Can't find deployment for verticleName: " + verticleName + " on node " + pos); }
@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 -> { // Wait a bit in case failover happens testComplete(); }); }); await(); }
@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 -> { // Wait a bit in case failover happens testComplete(); }); }); await(); }
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) -> { }); ((VertxInternal)vertx4).failoverCompleteHandler((nodeID, haInfo, succeeded) -> { fail("Should not failover here 4"); }); ((VertxInternal)vertx1).simulateKill();