use of io.vertx.core.impl.VertxInternal in project vertx-openshift-it by cescoffier.
the class EventBusSenderVerticle method createHealthChecks.
private HealthChecks createHealthChecks() {
return HealthChecks.create(vertx).register("ispn-cluster-status", future -> {
VertxInternal vertxInternal = (VertxInternal) vertx;
InfinispanClusterManager clusterManager = (InfinispanClusterManager) vertxInternal.getClusterManager();
EmbeddedCacheManager cacheManager = (EmbeddedCacheManager) clusterManager.getCacheContainer();
Health health = cacheManager.getHealth();
HealthStatus healthStatus = health.getClusterHealth().getHealthStatus();
Status status = new Status().setOk(healthStatus == HealthStatus.HEALTHY).setData(JsonObject.mapFrom(health));
future.complete(status);
});
}
use of io.vertx.core.impl.VertxInternal in project vertx-openshift-it by cescoffier.
the class AsyncMapVerticle method createHealthChecks.
private HealthChecks createHealthChecks() {
return HealthChecks.create(vertx).register("ispn-cluster-status", future -> {
VertxInternal vertxInternal = (VertxInternal) vertx;
InfinispanClusterManager clusterManager = (InfinispanClusterManager) vertxInternal.getClusterManager();
EmbeddedCacheManager cacheManager = (EmbeddedCacheManager) clusterManager.getCacheContainer();
Health health = cacheManager.getHealth();
HealthStatus healthStatus = health.getClusterHealth().getHealthStatus();
Status status = new Status().setOk(healthStatus == HealthStatus.HEALTHY).setData(JsonObject.mapFrom(health));
future.complete(status);
});
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class TimerTest method testTimerOnContext.
@Test
public void testTimerOnContext() {
disableThreadChecks();
ContextInternal ctx1 = ((VertxInternal) vertx).createEventLoopContext();
waitFor(2);
ContextInternal ctx2 = ((VertxInternal) vertx).createEventLoopContext();
assertNotSame(ctx1, ctx2);
ctx2.runOnContext(v -> {
vertx.setTimer(10, l -> {
assertSame(ctx2, vertx.getOrCreateContext());
complete();
});
ctx1.setTimer(10, l -> {
assertSame(ctx1, vertx.getOrCreateContext());
complete();
});
});
await();
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class VertxTest method testCloseHookFailure2.
@Test
public void testCloseHookFailure2() throws Exception {
AtomicInteger closedCount = new AtomicInteger();
class Hook implements Closeable {
@Override
public void close(Promise<Void> completion) {
if (closedCount.incrementAndGet() == 1) {
completion.handle(Future.succeededFuture());
throw new RuntimeException();
} else {
completion.handle(Future.succeededFuture());
}
}
}
VertxInternal vertx = (VertxInternal) Vertx.vertx();
vertx.addCloseHook(new Hook());
vertx.addCloseHook(new Hook());
// Now undeploy
vertx.close(ar -> {
assertTrue(ar.succeeded());
assertEquals(2, closedCount.get());
testComplete();
});
await();
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class VertxTest method testFinalizeHttpClient.
@Test
public void testFinalizeHttpClient() throws Exception {
VertxInternal vertx = (VertxInternal) Vertx.vertx();
try {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<NetSocket> socketRef = new AtomicReference<>();
vertx.createNetServer().connectHandler(socketRef::set).listen(8080, "localhost").onComplete(onSuccess(server -> latch.countDown()));
awaitLatch(latch);
AtomicBoolean closed = new AtomicBoolean();
// No keep alive so the connection is not held in the pool ????
CloseFuture closeFuture = new CloseFuture();
closeFuture.future().onComplete(ar -> closed.set(true));
HttpClient client = vertx.createHttpClient(new HttpClientOptions().setKeepAlive(false), closeFuture);
vertx.addCloseHook(closeFuture);
client.request(HttpMethod.GET, 8080, "localhost", "/").compose(HttpClientRequest::send).onComplete(onFailure(err -> {
}));
WeakReference<HttpClient> ref = new WeakReference<>(client);
closeFuture = null;
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();
}
Aggregations