use of io.vertx.core.Handler in project vert.x by eclipse.
the class Http2ServerTest method testShutdownOverride.
@Test
public void testShutdownOverride() throws Exception {
AtomicLong shutdown = new AtomicLong();
Handler<HttpServerRequest> requestHandler = req -> {
HttpConnection conn = req.connection();
shutdown.set(System.currentTimeMillis());
conn.shutdown(10000);
vertx.setTimer(300, v -> {
conn.shutdown(300);
});
};
server.requestHandler(requestHandler);
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
request.channel.closeFuture().addListener(v1 -> {
vertx.runOnContext(v2 -> {
assertTrue(shutdown.get() - System.currentTimeMillis() < 1200);
testComplete();
});
});
Http2ConnectionEncoder encoder = request.encoder;
int id = request.nextStreamId();
encoder.writeHeaders(request.context, id, GET("/"), 0, true, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.vertx.core.Handler in project vert.x by eclipse.
the class Http2ServerTest method testServerSendGoAway.
private void testServerSendGoAway(Handler<HttpServerRequest> requestHandler, int expectedError) throws Exception {
server.requestHandler(requestHandler);
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
request.decoder.frameListener(new Http2EventAdapter() {
@Override
public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData) throws Http2Exception {
vertx.runOnContext(v -> {
assertEquals(expectedError, errorCode);
complete();
});
}
});
Http2ConnectionEncoder encoder = request.encoder;
int id1 = request.nextStreamId();
encoder.writeHeaders(request.context, id1, GET("/"), 0, true, request.context.newPromise());
int id2 = request.nextStreamId();
encoder.writeHeaders(request.context, id2, GET("/"), 0, true, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.vertx.core.Handler in project vert.x by eclipse.
the class HttpTest method testClientConnectionClose.
@Test
public void testClientConnectionClose() throws Exception {
// Test client connection close + server close handler
CountDownLatch latch = new CountDownLatch(1);
server.requestHandler(req -> {
AtomicInteger len = new AtomicInteger();
req.handler(buff -> {
if (len.addAndGet(buff.length()) == 1024) {
latch.countDown();
}
});
req.connection().closeHandler(v -> {
testComplete();
});
});
CountDownLatch listenLatch = new CountDownLatch(1);
server.listen(onSuccess(s -> listenLatch.countDown()));
awaitLatch(listenLatch);
HttpClientRequest req = client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> {
fail();
});
req.setChunked(true);
req.write(TestUtils.randomBuffer(1024));
awaitLatch(latch);
req.connection().close();
await();
}
use of io.vertx.core.Handler in project vert.x by eclipse.
the class VertxTest method testCloseHookFailure1.
@Test
public void testCloseHookFailure1() throws Exception {
AtomicInteger closedCount = new AtomicInteger();
class Hook implements Closeable {
@Override
public void close(Handler<AsyncResult<Void>> completionHandler) {
if (closedCount.incrementAndGet() == 1) {
throw new RuntimeException();
} else {
completionHandler.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.Handler in project vert.x by eclipse.
the class TimerTest method timer.
private void timer(long delay) throws Exception {
final AtomicLong id = new AtomicLong(-1);
id.set(vertx.setTimer(delay, new Handler<Long>() {
int count;
boolean fired;
public void handle(Long timerID) {
assertFalse(fired);
fired = true;
assertEquals(id.get(), timerID.longValue());
assertEquals(0, count);
count++;
setEndTimer();
}
}));
await();
}
Aggregations