use of io.vertx.core.http.HttpConnection in project vert.x by eclipse.
the class Http2ClientTest method testConnectionHandler.
@Test
public void testConnectionHandler() throws Exception {
waitFor(2);
server.requestHandler(req -> {
req.response().end();
});
startServer();
AtomicReference<HttpConnection> connection = new AtomicReference<>();
HttpClientRequest req1 = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath");
req1.connectionHandler(conn -> {
Context ctx = Vertx.currentContext();
assertOnIOContext(ctx);
assertTrue(connection.compareAndSet(null, conn));
});
req1.handler(resp -> {
assertSame(connection.get(), req1.connection());
complete();
});
HttpClientRequest req2 = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath");
req2.connectionHandler(conn -> {
fail();
});
req2.handler(resp -> {
assertSame(connection.get(), req2.connection());
complete();
});
req1.end();
req2.end();
await();
}
use of io.vertx.core.http.HttpConnection in project vert.x by eclipse.
the class Http2ServerTest method testClientSendGoAwayNoError.
@Test
public void testClientSendGoAwayNoError() throws Exception {
Future<Void> abc = Future.future();
Context ctx = vertx.getOrCreateContext();
Handler<HttpServerRequest> requestHandler = req -> {
HttpConnection conn = req.connection();
AtomicInteger numShutdown = new AtomicInteger();
AtomicBoolean completed = new AtomicBoolean();
conn.shutdownHandler(v -> {
assertOnIOContext(ctx);
numShutdown.getAndIncrement();
vertx.setTimer(100, timerID -> {
completed.set(true);
testComplete();
});
});
conn.goAwayHandler(ga -> {
assertOnIOContext(ctx);
assertEquals(0, numShutdown.get());
req.response().end();
});
conn.closeHandler(v -> {
assertTrue(completed.get());
});
abc.complete();
};
server.requestHandler(requestHandler);
startServer(ctx);
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
Http2ConnectionEncoder encoder = request.encoder;
int id = request.nextStreamId();
encoder.writeHeaders(request.context, id, GET("/"), 0, true, request.context.newPromise());
request.context.flush();
abc.setHandler(ar -> {
encoder.writeGoAway(request.context, id, 0, Unpooled.EMPTY_BUFFER, request.context.newPromise());
request.context.flush();
});
});
fut.sync();
await();
}
use of io.vertx.core.http.HttpConnection in project vert.x by eclipse.
the class Http2ClientTest method testServerShutdownConnection.
@Test
public void testServerShutdownConnection() throws Exception {
waitFor(2);
server.connectionHandler(HttpConnection::shutdown);
server.requestHandler(req -> fail());
startServer();
HttpClientRequest req1 = client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath");
req1.connectionHandler(conn -> {
Context ctx = Vertx.currentContext();
conn.goAwayHandler(ga -> {
assertOnIOContext(ctx);
complete();
});
});
AtomicInteger count = new AtomicInteger();
req1.exceptionHandler(err -> {
if (count.getAndIncrement() == 0) {
complete();
}
});
req1.handler(resp -> {
fail();
});
req1.end();
await();
}
Aggregations