Search in sources :

Example 1 with Http2RemoteFlowController

use of io.netty.handler.codec.http2.Http2RemoteFlowController in project netty by netty.

the class DefaultHttp2ConnectionTest method removeAllStreamsWhileIteratingActiveStreamsAndExceptionOccurs.

@Test
public void removeAllStreamsWhileIteratingActiveStreamsAndExceptionOccurs() throws InterruptedException, Http2Exception {
    final Endpoint<Http2RemoteFlowController> remote = client.remote();
    final Endpoint<Http2LocalFlowController> local = client.local();
    for (int c = 3, s = 2; c < 5000; c += 2, s += 2) {
        local.createStream(c, false);
        remote.createStream(s, false);
    }
    final Promise<Void> promise = group.next().newPromise();
    final CountDownLatch latch = new CountDownLatch(1);
    try {
        client.forEachActiveStream(new Http2StreamVisitor() {

            @Override
            public boolean visit(Http2Stream stream) throws Http2Exception {
                // This close call is basically a noop, because the following statement will throw an exception.
                client.close(promise);
                // Do an invalid operation while iterating.
                remote.createStream(3, false);
                return true;
            }
        });
    } catch (Http2Exception ignored) {
        client.close(promise).addListener(new FutureListener<Void>() {

            @Override
            public void operationComplete(Future<Void> future) throws Exception {
                assertTrue(promise.isDone());
                latch.countDown();
            }
        });
    }
    assertTrue(latch.await(5, TimeUnit.SECONDS));
}
Also used : FutureListener(io.netty.util.concurrent.FutureListener) CountDownLatch(java.util.concurrent.CountDownLatch) Endpoint(io.netty.handler.codec.http2.Http2Connection.Endpoint) Future(io.netty.util.concurrent.Future) Test(org.junit.Test)

Example 2 with Http2RemoteFlowController

use of io.netty.handler.codec.http2.Http2RemoteFlowController in project netty by netty.

the class Http2FrameWriterBenchmark method boostrapEnvWithTransport.

private static Environment boostrapEnvWithTransport(final EnvironmentType environmentType) {
    final EnvironmentParameters params = environmentType.params();
    ServerBootstrap sb = new ServerBootstrap();
    Bootstrap cb = new Bootstrap();
    final TransportEnvironment environment = new TransportEnvironment(cb, sb);
    EventLoopGroup serverEventLoopGroup = params.newEventLoopGroup();
    sb.group(serverEventLoopGroup, serverEventLoopGroup);
    sb.channel(params.serverChannelClass());
    sb.option(ChannelOption.ALLOCATOR, params.serverAllocator());
    sb.childOption(ChannelOption.ALLOCATOR, params.serverAllocator());
    sb.childHandler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
        }
    });
    cb.group(params.newEventLoopGroup());
    cb.channel(params.clientChannelClass());
    cb.option(ChannelOption.ALLOCATOR, params.clientAllocator());
    final CountDownLatch latch = new CountDownLatch(1);
    cb.handler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            Http2Connection connection = new DefaultHttp2Connection(false);
            Http2RemoteFlowController remoteFlowController = params.remoteFlowController();
            if (remoteFlowController != null) {
                connection.remote().flowController(params.remoteFlowController());
            }
            Http2LocalFlowController localFlowController = params.localFlowController();
            if (localFlowController != null) {
                connection.local().flowController(localFlowController);
            }
            environment.writer(new DefaultHttp2FrameWriter());
            Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(connection, environment.writer());
            Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(connection, encoder, new DefaultHttp2FrameReader());
            Http2ConnectionHandler connectionHandler = new Http2ConnectionHandlerBuilder().encoderEnforceMaxConcurrentStreams(false).frameListener(new Http2FrameAdapter()).codec(decoder, encoder).build();
            p.addLast(connectionHandler);
            environment.context(p.lastContext());
            // Must wait for context to be set.
            latch.countDown();
        }
    });
    environment.serverChannel(sb.bind(params.address()));
    params.address(environment.serverChannel().localAddress());
    environment.clientChannel(cb.connect(params.address()));
    try {
        if (!latch.await(5, SECONDS)) {
            throw new RuntimeException("Channel did not initialize in time");
        }
    } catch (InterruptedException ie) {
        throw new RuntimeException(ie);
    }
    return environment;
}
Also used : Http2FrameAdapter(io.netty.handler.codec.http2.Http2FrameAdapter) DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) Http2Connection(io.netty.handler.codec.http2.Http2Connection) Http2ConnectionHandler(io.netty.handler.codec.http2.Http2ConnectionHandler) DefaultHttp2ConnectionEncoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder) Http2RemoteFlowController(io.netty.handler.codec.http2.Http2RemoteFlowController) Http2ConnectionDecoder(io.netty.handler.codec.http2.Http2ConnectionDecoder) DefaultHttp2ConnectionDecoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder) Http2ConnectionHandlerBuilder(io.netty.handler.codec.http2.Http2ConnectionHandlerBuilder) Bootstrap(io.netty.bootstrap.Bootstrap) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) DefaultHttp2FrameReader(io.netty.handler.codec.http2.DefaultHttp2FrameReader) DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) OioServerSocketChannel(io.netty.channel.socket.oio.OioServerSocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) ServerChannel(io.netty.channel.ServerChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) EpollSocketChannel(io.netty.channel.epoll.EpollSocketChannel) EpollServerSocketChannel(io.netty.channel.epoll.EpollServerSocketChannel) OioSocketChannel(io.netty.channel.socket.oio.OioSocketChannel) Channel(io.netty.channel.Channel) DefaultHttp2ConnectionDecoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultHttp2FrameWriter(io.netty.handler.codec.http2.DefaultHttp2FrameWriter) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelPipeline(io.netty.channel.ChannelPipeline) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) EventLoopGroup(io.netty.channel.EventLoopGroup) OioEventLoopGroup(io.netty.channel.oio.OioEventLoopGroup) Http2LocalFlowController(io.netty.handler.codec.http2.Http2LocalFlowController) Http2ConnectionEncoder(io.netty.handler.codec.http2.Http2ConnectionEncoder) DefaultHttp2ConnectionEncoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder)

Example 3 with Http2RemoteFlowController

use of io.netty.handler.codec.http2.Http2RemoteFlowController in project netty by netty.

the class DefaultHttp2ConnectionTest method removeAllStreamsWithManyActiveStreams.

@Test
public void removeAllStreamsWithManyActiveStreams() throws InterruptedException, Http2Exception {
    Endpoint<Http2RemoteFlowController> remote = client.remote();
    Endpoint<Http2LocalFlowController> local = client.local();
    for (int c = 3, s = 2; c < 5000; c += 2, s += 2) {
        local.createStream(c, false);
        remote.createStream(s, false);
    }
    testRemoveAllStreams();
}
Also used : Endpoint(io.netty.handler.codec.http2.Http2Connection.Endpoint) Test(org.junit.Test)

Example 4 with Http2RemoteFlowController

use of io.netty.handler.codec.http2.Http2RemoteFlowController in project vert.x by eclipse.

the class VertxHttp2ConnectionHandler method _writeData.

private void _writeData(Http2Stream stream, ByteBuf chunk, boolean end) {
    encoder().writeData(ctx, stream.id(), chunk, 0, end, ctx.newPromise());
    Http2RemoteFlowController controller = encoder().flowController();
    if (!controller.isWritable(stream) || end) {
        try {
            encoder().flowController().writePendingBytes();
        } catch (Http2Exception e) {
            onError(ctx, e);
        }
    }
    ctx.channel().flush();
}
Also used : Http2Exception(io.netty.handler.codec.http2.Http2Exception) Http2RemoteFlowController(io.netty.handler.codec.http2.Http2RemoteFlowController)

Example 5 with Http2RemoteFlowController

use of io.netty.handler.codec.http2.Http2RemoteFlowController in project netty by netty.

the class DefaultHttp2ConnectionTest method removeAllStreamsWhileIteratingActiveStreams.

@Test
public void removeAllStreamsWhileIteratingActiveStreams() throws InterruptedException, Http2Exception {
    final Endpoint<Http2RemoteFlowController> remote = client.remote();
    final Endpoint<Http2LocalFlowController> local = client.local();
    for (int c = 3, s = 2; c < 5000; c += 2, s += 2) {
        local.createStream(c, false);
        remote.createStream(s, false);
    }
    final Promise<Void> promise = group.next().newPromise();
    final CountDownLatch latch = new CountDownLatch(client.numActiveStreams());
    client.forEachActiveStream(new Http2StreamVisitor() {

        @Override
        public boolean visit(Http2Stream stream) {
            client.close(promise).addListener(new FutureListener<Void>() {

                @Override
                public void operationComplete(Future<Void> future) throws Exception {
                    assertTrue(promise.isDone());
                    latch.countDown();
                }
            });
            return true;
        }
    });
    assertTrue(latch.await(5, TimeUnit.SECONDS));
}
Also used : FutureListener(io.netty.util.concurrent.FutureListener) CountDownLatch(java.util.concurrent.CountDownLatch) Endpoint(io.netty.handler.codec.http2.Http2Connection.Endpoint) Future(io.netty.util.concurrent.Future) Test(org.junit.Test)

Aggregations

Endpoint (io.netty.handler.codec.http2.Http2Connection.Endpoint)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Test (org.junit.Test)3 Http2RemoteFlowController (io.netty.handler.codec.http2.Http2RemoteFlowController)2 Future (io.netty.util.concurrent.Future)2 FutureListener (io.netty.util.concurrent.FutureListener)2 Bootstrap (io.netty.bootstrap.Bootstrap)1 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 Channel (io.netty.channel.Channel)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 ServerChannel (io.netty.channel.ServerChannel)1 EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)1 EpollServerSocketChannel (io.netty.channel.epoll.EpollServerSocketChannel)1 EpollSocketChannel (io.netty.channel.epoll.EpollSocketChannel)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 OioEventLoopGroup (io.netty.channel.oio.OioEventLoopGroup)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 OioServerSocketChannel (io.netty.channel.socket.oio.OioServerSocketChannel)1