Package io.vertx.core

Examples of io.vertx.core.Vertx


  public RepeatRule repeatRule = new RepeatRule();


  @Test
  public void testQuorumLost() throws Exception {
    Vertx vertx1 = startVertx(3);
    Vertx vertx2 = startVertx(3);
    Vertx 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.deployments().contains(ar.result()));
      ;
    });
    vertx2.deployVerticle("java:" + HAVerticle2.class.getName(), options, ar -> {
      assertTrue(ar.succeeded());
      assertTrue(vertx2.deployments().contains(ar.result()));
      ;
    });
    waitUntil(() -> vertx1.deployments().size() == 1 && vertx2.deployments().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.deployments().isEmpty() && vertx2.deployments().isEmpty());
    // Now re-instate the quorum
    Vertx vertx4 = startVertx(3);
    waitUntil(() -> vertx1.deployments().size() == 1 && vertx2.deployments().size() == 1);

    closeVertices(vertx1, vertx2, vertx4);
  }
View Full Code Here


    closeVertices(vertx1, vertx2, vertx4);
  }

  @Test
  public void testCleanCloseNoFailover() throws Exception {
    Vertx vertx1 = startVertx();
    Vertx vertx2 = startVertx();
    DeploymentOptions options = new DeploymentOptions().setHa(true);
    JsonObject config = new JsonObject().put("foo", "bar");
    options.setConfig(config);
    vertx2.deployVerticle("java:" + HAVerticle1.class.getName(), options, ar -> {
      assertTrue(ar.succeeded());
    });
    waitUntil(() -> vertx2.deployments().size() == 1);
    ((VertxInternal)vertx1).failoverCompleteHandler(succeeded -> {
      fail("Should not be called");
    });
    vertx2.close(ar -> {
      vertx.setTimer(500, tid -> {
        // Wait a bit in case failover happens
        testComplete();
      });
    });
View Full Code Here

    closeVertices(vertx1);
  }

  @Test
  public void testFailureInFailover() throws Exception {
    Vertx vertx1 = startVertx();
    Vertx vertx2 = startVertx();
    Vertx vertx3 = startVertx();
    CountDownLatch latch1 = new CountDownLatch(1);
    vertx1.deployVerticle("java:" + HAVerticle1.class.getName(), new DeploymentOptions().setHa(true), ar -> {
      assertTrue(ar.succeeded());
      assertTrue(vertx1.deployments().contains(ar.result()));
      latch1.countDown();
    });
    awaitLatch(latch1);
    ((VertxInternal)vertx2).failDuringFailover(true);
    ((VertxInternal)vertx3).failDuringFailover(true);
    CountDownLatch latch2 = new CountDownLatch(1);
    ((VertxInternal)vertx2).failoverCompleteHandler(succeeded -> {
      assertFalse(succeeded);
      latch2.countDown();
    });
    ((VertxInternal)vertx3).failoverCompleteHandler(succeeded -> {
      assertFalse(succeeded);
      latch2.countDown();
    });
    ((VertxInternal)vertx1).simulateKill();
    awaitLatch(latch2);

    // Now try again - this time failover should work

    assertTrue(vertx2.deployments().isEmpty());
    assertTrue(vertx3.deployments().isEmpty());
    ((VertxInternal)vertx2).failDuringFailover(false);
    CountDownLatch latch3 = new CountDownLatch(1);
    ((VertxInternal)vertx2).failoverCompleteHandler(succeeded -> {
      assertTrue(succeeded);
      latch3.countDown();
View Full Code Here

    closeVertices(vertx1, vertx2, vertx3);
  }

  @Test
  public void testHaGroups() throws Exception {
    Vertx vertx1 = startVertx("group1", 1);
    Vertx vertx2 = startVertx("group1", 1);
    Vertx vertx3 = startVertx("group2", 1);
    Vertx 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.deployments().contains(ar.result()));
      latch1.countDown();
    });
    vertx3.deployVerticle("java:" + HAVerticle2.class.getName(), new DeploymentOptions().setHa(true), ar -> {
      assertTrue(ar.succeeded());
      assertTrue(vertx3.deployments().contains(ar.result()));
      latch1.countDown();
    });
    awaitLatch(latch1);
    CountDownLatch latch2 = new CountDownLatch(1);
    ((VertxInternal)vertx1).failoverCompleteHandler(succeeded -> {
      fail("Should not failover here");
    });
    ((VertxInternal)vertx2).failoverCompleteHandler(succeeded -> {
      fail("Should not failover here");
    });
    ((VertxInternal)vertx4).failoverCompleteHandler(succeeded -> {
      assertTrue(succeeded);
      latch2.countDown();
    });
    ((VertxInternal)vertx3).simulateKill();
    awaitLatch(latch2);
    assertTrue(vertx4.deployments().size() == 1);
    CountDownLatch latch3 = new CountDownLatch(1);
    ((VertxInternal)vertx2).failoverCompleteHandler(succeeded -> {
      assertTrue(succeeded);
      latch3.countDown();
    });
View Full Code Here

  }

  @Test
  public void testNonHADeployments() throws Exception {
    Vertx vertx1 = startVertx();
    Vertx 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.deployments().contains(ar.result()));
      latch1.countDown();
    });
    vertx2.deployVerticle("java:" + HAVerticle2.class.getName(), new DeploymentOptions().setHa(false), ar -> {
      assertTrue(ar.succeeded());
      assertTrue(vertx2.deployments().contains(ar.result()));
      latch1.countDown();
    });
    awaitLatch(latch1);
    CountDownLatch latch2 = new CountDownLatch(1);
    ((VertxInternal)vertx1).failoverCompleteHandler(succeeded -> {
View Full Code Here

    closeVertices(vertx1, vertx2);
  }

  @Test
  public void testCloseRemovesFromCluster() throws Exception {
    Vertx vertx1 = startVertx();
    Vertx vertx2 = startVertx();
    Vertx vertx3 = startVertx();
    CountDownLatch latch1 = new CountDownLatch(1);
    vertx3.deployVerticle("java:" + HAVerticle1.class.getName(), new DeploymentOptions().setHa(true), ar -> {
      assertTrue(ar.succeeded());
      assertTrue(vertx3.deployments().contains(ar.result()));
      latch1.countDown();
    });
    awaitLatch(latch1);
    CountDownLatch latch2 = new CountDownLatch(1);
    // Close vertx2 - this should not then participate in failover
View Full Code Here

  }

  @Test
  public void testQuorumWithHaGroups() throws Exception {

    Vertx vertx1 = startVertx("group1", 2);
    Vertx vertx2 = startVertx("group2", 2);

    vertx1.deployVerticle("java:" + HAVerticle1.class.getName(), new DeploymentOptions().setHa(true), ar -> {
      assertTrue(ar.succeeded());
      assertTrue(vertx1.deployments().contains(ar.result()));
    });

    // Wait a little while
    Thread.sleep(500);
    //Should not be deployed yet
    assertTrue(vertx1.deployments().isEmpty());

    Vertx vertx3 = startVertx("group1", 2);
    // Now should deploy
    waitUntil(() -> vertx1.deployments().size() == 1);

    vertx2.deployVerticle("java:" + HAVerticle1.class.getName(), new DeploymentOptions().setHa(true), ar -> {
      assertTrue(ar.succeeded());
      assertTrue(vertx2.deployments().contains(ar.result()));
    });

    // Wait a little while
    Thread.sleep(500);
    //Should not be deployed yet
    assertTrue(vertx2.deployments().isEmpty());

    Vertx vertx4 = startVertx("group2", 2);
    // Now should deploy
    waitUntil(() -> vertx2.deployments().size() == 1);

    // Noow stop vertx4
    CountDownLatch latch = new CountDownLatch(1);
    vertx4.close(ar -> {
      latch.countDown();
    });

    awaitLatch(latch);
    waitUntil(() -> vertx2.deployments().isEmpty());
View Full Code Here

  protected void deployRandomVerticles(Runnable runner) {
    int toDeploy = 0;
    AtomicInteger deployCount = new AtomicInteger();
    for (int pos: aliveNodes) {
      int numToDeploy = random.nextInt(maxVerticlesPerNode + 1);
      Vertx v = vertices[pos];
      int ii = pos;
      for (int j = 0; j < numToDeploy; j++) {
        JsonObject config = new JsonObject();
        config.put("foo", TestUtils.randomAlphaString(100));
        DeploymentOptions options = new DeploymentOptions().setHa(true).setConfig(config);
        String verticleName = "java:io.vertx.test.core.HAVerticle" + (random.nextInt(3) + 1);
        toDeploy++;
        v.deployVerticle(verticleName, options, ar -> {
          assertTrue(ar.succeeded());
          deployCount.incrementAndGet();
        });
      }
    }
View Full Code Here

  protected void undeployRandomVerticles(Runnable runner) {
    int toUndeploy = 0;
    AtomicInteger undeployCount = new AtomicInteger();
    for (int pos: aliveNodes) {
      Vertx v = vertices[pos];
      int deployedNum = v.deployments().size();
      int numToUnDeploy = random.nextInt(deployedNum + 1);
      List<String> deployed = new ArrayList<>(v.deployments());
      int ii = pos;
      for (int j = 0; j < numToUnDeploy; j++) {
        int depPos = random.nextInt(deployed.size());
        String depID = deployed.remove(depPos);
        toUndeploy++;
        v.undeployVerticle(depID, onSuccess(d -> {
          undeployCount.incrementAndGet();
        }));
      }
    }
    int totUndeployed = toUndeploy;
View Full Code Here

    assertTrue(file3.getPath().startsWith(".vertx/file-cache-"));
  }

  @Test
  public void testDeleteCacheDir() throws Exception {
    Vertx vertx2 = Vertx.vertx();
    FileResolver resolver2 = new FileResolver(vertx2);
    File file = resolver2.resolveFile(fileName1);
    assertTrue(file.exists());
    File cacheDir = file.getParentFile().getParentFile();
    assertTrue(cacheDir.exists());
    resolver2.deleteCacheDir(onSuccess(res -> {
      assertFalse(cacheDir.exists());
      vertx2.close(res2 -> {
        testComplete();
      });
    }));
    await();
  }
View Full Code Here

TOP

Related Classes of io.vertx.core.Vertx

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.