use of io.vertx.core.Context in project vert.x by eclipse.
the class HttpTestBase method startServer.
protected void startServer(Context context, HttpServer server) throws Exception {
CountDownLatch latch = new CountDownLatch(1);
context.runOnContext(v -> {
server.listen(onSuccess(s -> latch.countDown()));
});
awaitLatch(latch);
}
use of io.vertx.core.Context in project vert.x by eclipse.
the class HttpTest method testSendNonExistingFile.
@Test
public void testSendNonExistingFile() throws Exception {
server.requestHandler(req -> {
final Context ctx = vertx.getOrCreateContext();
req.response().sendFile("/not/existing/path", event -> {
assertEquals(ctx, vertx.getOrCreateContext());
if (event.failed()) {
req.response().end("failed");
}
});
});
server.listen(onSuccess(s -> {
client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> {
resp.bodyHandler(buff -> {
assertEquals("failed", buff.toString());
testComplete();
});
}).end();
}));
await();
}
use of io.vertx.core.Context in project vert.x by eclipse.
the class ContextTest method testRunOnContext.
@Test
public void testRunOnContext() throws Exception {
vertx.runOnContext(v -> {
Thread th = Thread.currentThread();
Context ctx = Vertx.currentContext();
ctx.runOnContext(v2 -> {
assertEquals(th, Thread.currentThread());
for (int i = 0; i < 10; i++) {
Context c = Vertx.currentContext();
assertEquals(ctx, c);
}
new Thread() {
public void run() {
ctx.runOnContext(v3 -> {
assertEquals(th, Thread.currentThread());
assertEquals(ctx, Vertx.currentContext());
testComplete();
});
}
}.start();
});
});
await();
}
use of io.vertx.core.Context in project vert.x by eclipse.
the class ContextTest method testExecuteOrderedBlocking.
@Test
public void testExecuteOrderedBlocking() throws Exception {
Context context = vertx.getOrCreateContext();
context.executeBlocking(f -> {
assertTrue(Context.isOnWorkerThread());
f.complete(1 + 2);
}, r -> {
assertTrue(Context.isOnEventLoopThread());
assertEquals(r.result(), 3);
testComplete();
});
await();
}
use of io.vertx.core.Context in project vert.x by eclipse.
the class ContextTest method testExceptionHandlerOnAsyncDeploymentAsyncResultHandlerFailure.
@Test
public void testExceptionHandlerOnAsyncDeploymentAsyncResultHandlerFailure() {
RuntimeException failure = new RuntimeException();
Context ctx = vertx.getOrCreateContext();
ctx.exceptionHandler(err -> {
assertSame(failure, err);
testComplete();
});
ctx.runOnContext(v -> {
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start(Future<Void> startFuture) throws Exception {
context.runOnContext(startFuture::complete);
}
}, ar -> {
throw failure;
});
});
await();
}
Aggregations