use of io.vertx.core.net.impl.ConnectionBase in project vert.x by eclipse.
the class Http2Test method testConnectionCloseEvictsConnectionFromThePoolBeforeStreamsAreClosed.
/**
* Test that socket close (without an HTTP/2 go away frame) removes the connection from the pool
* before the streams are notified. Otherwise a notified stream might reuse a stale connection from
* the pool.
*/
@Test
public void testConnectionCloseEvictsConnectionFromThePoolBeforeStreamsAreClosed() throws Exception {
Set<HttpConnection> serverConnections = new HashSet<>();
server.requestHandler(req -> {
serverConnections.add(req.connection());
switch(req.path()) {
case "/1":
req.response().end();
break;
case "/2":
assertEquals(1, serverConnections.size());
// Socket close without HTTP/2 go away
Channel ch = ((ConnectionBase) req.connection()).channel();
ChannelPromise promise = ch.newPromise();
ch.unsafe().close(promise);
break;
case "/3":
assertEquals(2, serverConnections.size());
req.response().end();
break;
}
});
startServer(testAddress);
Future<Buffer> f1 = client.request(new RequestOptions(requestOptions).setURI("/1")).compose(req -> req.send().compose(HttpClientResponse::body));
f1.onComplete(onSuccess(v -> {
Future<Buffer> f2 = client.request(new RequestOptions(requestOptions).setURI("/2")).compose(req -> {
System.out.println(req.connection());
return req.send().compose(HttpClientResponse::body);
});
f2.onComplete(onFailure(v2 -> {
Future<Buffer> f3 = client.request(new RequestOptions(requestOptions).setURI("/3")).compose(req -> {
System.out.println(req.connection());
return req.send().compose(HttpClientResponse::body);
});
f3.onComplete(onSuccess(vvv -> {
testComplete();
}));
}));
}));
await();
}
Aggregations