use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class VertxTest method testFinalizeNetClient.
@Test
public void testFinalizeNetClient() throws Exception {
VertxInternal vertx = (VertxInternal) Vertx.vertx();
try {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<NetSocket> socketRef = new AtomicReference<>();
vertx.createNetServer().connectHandler(socketRef::set).listen(1234, "localhost").onComplete(onSuccess(server -> latch.countDown()));
awaitLatch(latch);
AtomicBoolean closed = new AtomicBoolean();
CloseFuture closeFuture = new CloseFuture();
NetClient client = vertx.createNetClient(new NetClientOptions(), closeFuture);
vertx.addCloseHook(closeFuture);
closeFuture.future().onComplete(ar -> closed.set(true));
closeFuture = null;
client.connect(1234, "localhost", onSuccess(so -> {
}));
WeakReference<NetClient> ref = new WeakReference<>(client);
client = null;
assertWaitUntil(() -> socketRef.get() != null);
for (int i = 0; i < 10; i++) {
Thread.sleep(10);
RUNNER.runSystemGC();
assertFalse(closed.get());
assertNotNull(ref.get());
}
socketRef.get().close();
long now = System.currentTimeMillis();
while (true) {
assertTrue(System.currentTimeMillis() - now < 20_000);
RUNNER.runSystemGC();
if (ref.get() == null) {
assertTrue(closed.get());
break;
}
}
} finally {
vertx.close(ar -> {
testComplete();
});
}
await();
}
use of io.vertx.core.impl.VertxInternal 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);
}
use of io.vertx.core.impl.VertxInternal 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 -> {
// Wait a bit in case failover happens
assertEquals("Verticle should still be deployed here 1", 1, vertx1.deploymentIDs().size());
assertTrue("Verticle should not failover here 2", vertx2.deploymentIDs().isEmpty());
testComplete();
});
});
await();
}
use of io.vertx.core.impl.VertxInternal 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 -> {
// Wait a bit in case failover happens
testComplete();
});
});
await();
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class HATest method testCloseRemovesFromCluster.
@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()));
}
Aggregations