Search in sources :

Example 1 with ConnectionBase

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();
}
Also used : Buffer(io.vertx.core.buffer.Buffer) java.util(java.util) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) ConnectionBase(io.vertx.core.net.impl.ConnectionBase) Context(io.vertx.core.Context) PfxOptions(io.vertx.core.net.PfxOptions) BooleanSupplier(java.util.function.BooleanSupplier) OpenSSLEngineOptions(io.vertx.core.net.OpenSSLEngineOptions) ChannelPromise(io.netty.channel.ChannelPromise) TestUtils(io.vertx.test.core.TestUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DuplexChannel(io.netty.channel.socket.DuplexChannel) Http2ServerConnection(io.vertx.core.http.impl.Http2ServerConnection) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) Promise(io.vertx.core.Promise) TooLongFrameException(io.netty.handler.codec.TooLongFrameException) Test(org.junit.Test) Future(io.vertx.core.Future) Collectors(java.util.stream.Collectors) Channel(io.netty.channel.Channel) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Repeat(io.vertx.test.core.Repeat) Stream(java.util.stream.Stream) Buffer(io.vertx.core.buffer.Buffer) Ignore(org.junit.Ignore) AsyncTestBase(io.vertx.test.core.AsyncTestBase) Cert(io.vertx.test.tls.Cert) Http2CodecUtil(io.netty.handler.codec.http2.Http2CodecUtil) DuplexChannel(io.netty.channel.socket.DuplexChannel) Channel(io.netty.channel.Channel) CompletableFuture(java.util.concurrent.CompletableFuture) Future(io.vertx.core.Future) ChannelPromise(io.netty.channel.ChannelPromise) ConnectionBase(io.vertx.core.net.impl.ConnectionBase) Test(org.junit.Test)

Aggregations

Channel (io.netty.channel.Channel)1 ChannelPromise (io.netty.channel.ChannelPromise)1 DuplexChannel (io.netty.channel.socket.DuplexChannel)1 TooLongFrameException (io.netty.handler.codec.TooLongFrameException)1 Http2CodecUtil (io.netty.handler.codec.http2.Http2CodecUtil)1 Context (io.vertx.core.Context)1 Future (io.vertx.core.Future)1 Promise (io.vertx.core.Promise)1 Buffer (io.vertx.core.buffer.Buffer)1 Http2ServerConnection (io.vertx.core.http.impl.Http2ServerConnection)1 OpenSSLEngineOptions (io.vertx.core.net.OpenSSLEngineOptions)1 PfxOptions (io.vertx.core.net.PfxOptions)1 ConnectionBase (io.vertx.core.net.impl.ConnectionBase)1 AsyncTestBase (io.vertx.test.core.AsyncTestBase)1 Repeat (io.vertx.test.core.Repeat)1 TestUtils (io.vertx.test.core.TestUtils)1 Cert (io.vertx.test.tls.Cert)1 java.util (java.util)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CountDownLatch (java.util.concurrent.CountDownLatch)1