use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class HATest method checkDeploymentExists.
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.toJson().equals(dep.deploymentOptions().toJson())) {
return;
}
}
fail("Can't find deployment for verticleName: " + verticleName + " on node " + pos);
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class HATest method kill.
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());
}
});
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class TimerTest method testPeriodicOnContext.
@Test
public void testPeriodicOnContext() {
disableThreadChecks();
waitFor(4);
ContextInternal ctx1 = ((VertxInternal) vertx).createEventLoopContext();
ContextInternal ctx2 = ((VertxInternal) vertx).createEventLoopContext();
assertNotSame(ctx1, ctx2);
ctx2.runOnContext(v -> {
vertx.setPeriodic(10, new Handler<Long>() {
int count;
@Override
public void handle(Long l) {
assertSame(ctx2, vertx.getOrCreateContext());
if (++count == 2) {
vertx.cancelTimer(l);
}
complete();
}
});
ctx1.setPeriodic(10, new Handler<Long>() {
int count;
@Override
public void handle(Long l) {
assertSame(ctx1, vertx.getOrCreateContext());
if (++count == 2) {
vertx.cancelTimer(l);
}
complete();
}
});
});
await();
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class HATest method testFailureInFailover.
@Test
public void testFailureInFailover() throws Exception {
vertx1 = startVertx();
vertx2 = startVertx();
vertx3 = startVertx();
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).failDuringFailover(true);
((VertxInternal) vertx3).failDuringFailover(true);
CountDownLatch latch2 = new CountDownLatch(1);
((VertxInternal) vertx2).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
assertFalse(succeeded);
latch2.countDown();
});
((VertxInternal) vertx3).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
assertFalse(succeeded);
latch2.countDown();
});
((VertxInternal) vertx1).simulateKill();
awaitLatch(latch2);
// Now try again - this time failover should work
assertTrue(vertx2.deploymentIDs().isEmpty());
assertTrue(vertx3.deploymentIDs().isEmpty());
((VertxInternal) vertx2).failDuringFailover(false);
CountDownLatch latch3 = new CountDownLatch(1);
((VertxInternal) vertx2).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
assertTrue(succeeded);
latch3.countDown();
});
((VertxInternal) vertx3).simulateKill();
awaitLatch(latch3);
assertWaitUntil(() -> vertx2.deploymentIDs().size() == 1);
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class HATest method testNonHADeployments.
@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()));
}
Aggregations