use of io.vertx.core.Context in project vert.x by eclipse.
the class ContextTest method testContextExceptionHandler.
@Test
public void testContextExceptionHandler() {
RuntimeException failure = new RuntimeException();
Context context = vertx.getOrCreateContext();
context.exceptionHandler(err -> {
assertSame(context, Vertx.currentContext());
assertSame(failure, err);
testComplete();
});
context.runOnContext(v -> {
throw failure;
});
await();
}
use of io.vertx.core.Context in project vert.x by eclipse.
the class ContextTest method testDefaultContextExceptionHandler.
@Test
public void testDefaultContextExceptionHandler() {
RuntimeException failure = new RuntimeException();
Context context = vertx.getOrCreateContext();
vertx.exceptionHandler(err -> {
assertSame(failure, err);
testComplete();
});
context.runOnContext(v -> {
throw failure;
});
await();
}
use of io.vertx.core.Context in project vert.x by eclipse.
the class ContextTest method testExecuteUnorderedBlocking.
@Test
public void testExecuteUnorderedBlocking() throws Exception {
Context context = vertx.getOrCreateContext();
context.executeBlocking(f -> {
assertTrue(Context.isOnWorkerThread());
f.complete(1 + 2);
}, false, r -> {
assertTrue(Context.isOnEventLoopThread());
assertEquals(r.result(), 3);
testComplete();
});
await();
}
use of io.vertx.core.Context in project vert.x by eclipse.
the class Http2ServerTest method testPromiseStreamError.
@Test
public void testPromiseStreamError() throws Exception {
Context ctx = vertx.getOrCreateContext();
waitFor(3);
Future<Void> when = Future.future();
server.requestHandler(req -> {
req.response().push(HttpMethod.GET, "/wibble", ar -> {
assertTrue(ar.succeeded());
assertOnIOContext(ctx);
when.complete();
HttpServerResponse resp = ar.result();
resp.exceptionHandler(err -> {
assertSame(ctx, Vertx.currentContext());
complete();
});
resp.closeHandler(v -> {
assertSame(ctx, Vertx.currentContext());
complete();
});
resp.endHandler(v -> {
assertSame(ctx, Vertx.currentContext());
complete();
});
resp.setChunked(true).write("whatever");
});
});
startServer(ctx);
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
request.decoder.frameListener(new Http2EventAdapter() {
@Override
public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception {
when.setHandler(ar -> {
Http2ConnectionEncoder encoder = request.encoder;
encoder.frameWriter().writeHeaders(request.context, promisedStreamId, GET("/"), 0, false, request.context.newPromise());
request.context.flush();
});
}
});
int id = request.nextStreamId();
Http2ConnectionEncoder encoder = request.encoder;
encoder.writeHeaders(request.context, id, GET("/"), 0, false, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.vertx.core.Context in project vert.x by eclipse.
the class Http2ServerTest method testPost.
@Test
public void testPost() throws Exception {
Context ctx = vertx.getOrCreateContext();
Buffer expectedContent = TestUtils.randomBuffer(1000);
Buffer postContent = Buffer.buffer();
server.requestHandler(req -> {
assertOnIOContext(ctx);
req.handler(buff -> {
assertOnIOContext(ctx);
postContent.appendBuffer(buff);
});
req.endHandler(v -> {
assertOnIOContext(ctx);
req.response().putHeader("content-type", "text/plain").end("");
assertEquals(expectedContent, postContent);
testComplete();
});
});
startServer(ctx);
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
int id = request.nextStreamId();
request.encoder.writeHeaders(request.context, id, POST("/").set("content-type", "text/plain"), 0, false, request.context.newPromise());
request.encoder.writeData(request.context, id, expectedContent.getByteBuf(), 0, true, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
Aggregations