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 kill(int pos) { // Save the deploymentIDs first takeDeploymentSnapshots(); VertxInternal v = (VertxInternal)vertices[pos]; killedNode = pos; v.executeBlocking(fut -> { v.simulateKill(); fut.complete(); }, false, ar -> { assertTrue(ar.succeeded()); }); }
@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())); }
@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())); }
latch2.countDown(); }); ((VertxInternal)vertx1).simulateKill(); awaitLatch(latch2); latch3.countDown(); }); ((VertxInternal)vertx3).simulateKill(); awaitLatch(latch3); assertWaitUntil(() -> vertx2.deploymentIDs().size() == 1);
latch2.countDown(); }); ((VertxInternal)vertx3).simulateKill(); awaitLatch(latch2); assertTrue(vertx4.deploymentIDs().size() == 1); fail("Should not failover here 4"); }); ((VertxInternal)vertx1).simulateKill(); awaitLatch(latch3); assertTrue(vertx2.deploymentIDs().size() == 1);
@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(); }
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 kill(int pos) { // Save the deploymentIDs first takeDeploymentSnapshots(); VertxInternal v = (VertxInternal)vertices[pos]; killedNode = pos; v.executeBlocking(fut -> { v.simulateKill(); fut.complete(); }, false, ar -> { assertTrue(ar.succeeded()); }); }
@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())); }
@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())); }
latch2.countDown(); }); ((VertxInternal)vertx1).simulateKill(); awaitLatch(latch2); latch3.countDown(); }); ((VertxInternal)vertx3).simulateKill(); awaitLatch(latch3); assertWaitUntil(() -> vertx2.deploymentIDs().size() == 1);
@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(); }
latch2.countDown(); }); ((VertxInternal)vertx3).simulateKill(); awaitLatch(latch2); assertTrue(vertx4.deploymentIDs().size() == 1); fail("Should not failover here 4"); }); ((VertxInternal)vertx1).simulateKill(); awaitLatch(latch3); assertTrue(vertx2.deploymentIDs().size() == 1);