use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class VertxTest method testCloseVertxShouldWaitConcurrentCloseHook.
@Test
public void testCloseVertxShouldWaitConcurrentCloseHook() throws Exception {
VertxInternal vertx = (VertxInternal) Vertx.vertx();
AtomicReference<Promise<Void>> ref = new AtomicReference<>();
CloseFuture fut = new CloseFuture();
fut.add(ref::set);
vertx.addCloseHook(fut);
Promise<Void> p = Promise.promise();
fut.close(p);
AtomicBoolean closed = new AtomicBoolean();
vertx.close(ar -> {
closed.set(true);
});
Thread.sleep(500);
assertFalse(closed.get());
ref.get().complete();
assertWaitUntil(closed::get);
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class MetricsTest method testThreadPoolMetricsWithWorkerVerticle.
@Test
public void testThreadPoolMetricsWithWorkerVerticle() throws Exception {
AtomicInteger counter = new AtomicInteger();
Map<String, PoolMetrics> all = FakePoolMetrics.getPoolMetrics();
FakePoolMetrics metrics = (FakePoolMetrics) all.get("vert.x-worker-thread");
assertThat(metrics.getPoolSize(), is(getOptions().getInternalBlockingPoolSize()));
assertThat(metrics.numberOfIdleThreads(), is(getOptions().getWorkerPoolSize()));
AtomicBoolean hadWaitingQueue = new AtomicBoolean();
AtomicBoolean hadIdle = new AtomicBoolean();
AtomicBoolean hadRunning = new AtomicBoolean();
int count = 100;
AtomicInteger msg = new AtomicInteger();
CountDownLatch latch1 = new CountDownLatch(1);
CountDownLatch latch2 = new CountDownLatch(1);
ContextInternal ctx = ((VertxInternal) vertx).createWorkerContext();
ctx.runOnContext(v -> {
vertx.eventBus().localConsumer("message", d -> {
msg.incrementAndGet();
try {
Thread.sleep(10);
if (metrics.numberOfWaitingTasks() > 0) {
hadWaitingQueue.set(true);
}
if (metrics.numberOfIdleThreads() > 0) {
hadIdle.set(true);
}
if (metrics.numberOfRunningTasks() > 0) {
hadRunning.set(true);
}
if (counter.incrementAndGet() == count) {
latch2.countDown();
}
} catch (InterruptedException e) {
Thread.currentThread().isInterrupted();
}
});
latch1.countDown();
});
awaitLatch(latch1);
for (int i = 0; i < count; i++) {
vertx.eventBus().send("message", i);
}
awaitLatch(latch2);
// The verticle deployment is also executed on the worker thread pool
assertWaitUntil(() -> count + 1 == metrics.numberOfCompletedTasks());
assertEquals(count + 1, metrics.numberOfSubmittedTask());
assertEquals(count + 1, metrics.numberOfCompletedTasks());
assertTrue("Had no idle threads", hadIdle.get());
assertTrue("Had no waiting tasks", hadWaitingQueue.get());
assertTrue("Had running tasks", hadRunning.get());
assertEquals(getOptions().getWorkerPoolSize(), metrics.numberOfIdleThreads());
assertEquals(0, metrics.numberOfRunningTasks());
assertEquals(0, metrics.numberOfWaitingTasks());
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class FileResolverFactoryTest method testResolver.
@Test
public void testResolver() {
FileResolver resolver = ((VertxInternal) vertx).fileResolver();
assertEquals(CustomFileResolver.class, resolver.getClass());
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class NettyCompatTest method testAddressResolver.
@Test
public void testAddressResolver() {
VertxInternal vertx = (VertxInternal) super.vertx;
vertx.resolveAddress("localhost", onSuccess(v -> testComplete()));
await();
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class SSLEngineTest method doTest.
private void doTest(SSLEngineOptions engine, boolean useAlpn, HttpVersion version, String error, String expectedSslContext, boolean expectCause) {
server.close();
HttpServerOptions options = new HttpServerOptions().setSslEngineOptions(engine).setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST).setKeyCertOptions(Cert.SERVER_PEM.get()).setSsl(true).setUseAlpn(useAlpn);
server = vertx.createHttpServer(options);
server.requestHandler(req -> {
assertEquals(req.version(), version);
assertTrue(req.isSSL());
req.response().end();
});
try {
startServer();
if (error != null) {
fail("Was expecting failure: " + error);
}
} catch (Exception e) {
if (error == null) {
fail(e);
} else {
assertEquals(error, e.getMessage());
if (expectCause) {
assertNotSame(e, e.getCause());
}
return;
}
}
SSLHelper sslHelper = ((HttpServerImpl) server).sslHelper();
SslContext ctx = sslHelper.getContext((VertxInternal) vertx);
switch(expectedSslContext != null ? expectedSslContext : "jdk") {
case "jdk":
assertTrue(ctx instanceof JdkSslContext);
break;
case "openssl":
assertTrue(ctx instanceof OpenSslContext);
break;
}
client = vertx.createHttpClient(new HttpClientOptions().setSslEngineOptions(engine).setSsl(true).setUseAlpn(useAlpn).setTrustAll(true).setProtocolVersion(version));
client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", onSuccess(req -> {
req.send(onSuccess(resp -> {
assertEquals(200, resp.statusCode());
testComplete();
}));
}));
await();
}
Aggregations