Search in sources :

Example 1 with Http2LocalFlowController

use of io.netty.handler.codec.http2.Http2LocalFlowController 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 Http2LocalFlowController

use of io.netty.handler.codec.http2.Http2LocalFlowController 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 Http2LocalFlowController

use of io.netty.handler.codec.http2.Http2LocalFlowController 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 Http2LocalFlowController

use of io.netty.handler.codec.http2.Http2LocalFlowController in project grpc-java by grpc.

the class NettyHandlerTestBase method windowShouldNotExceedMaxWindowSize.

@Test
public void windowShouldNotExceedMaxWindowSize() throws Exception {
    makeStream();
    AbstractNettyHandler handler = (AbstractNettyHandler) handler();
    handler.setAutoTuneFlowControl(true);
    Http2Stream connectionStream = connection().connectionStream();
    Http2LocalFlowController localFlowController = connection().local().flowController();
    int maxWindow = handler.flowControlPing().maxWindow();
    handler.flowControlPing().setDataSizeSincePing(maxWindow);
    int payload = handler.flowControlPing().payload();
    ByteBuf buffer = handler.ctx().alloc().buffer(8);
    buffer.writeLong(payload);
    channelRead(pingFrame(true, buffer));
    assertEquals(maxWindow, localFlowController.initialWindowSize(connectionStream));
}
Also used : Http2LocalFlowController(io.netty.handler.codec.http2.Http2LocalFlowController) Http2Stream(io.netty.handler.codec.http2.Http2Stream) ByteBuf(io.netty.buffer.ByteBuf) CompositeByteBuf(io.netty.buffer.CompositeByteBuf) Test(org.junit.Test)

Example 5 with Http2LocalFlowController

use of io.netty.handler.codec.http2.Http2LocalFlowController in project grpc-java by grpc.

the class NettyServerHandlerTest method connectionWindowShouldBeOverridden.

@Test
@Ignore("Re-enable once https://github.com/grpc/grpc-java/issues/1175 is fixed")
public void connectionWindowShouldBeOverridden() throws Exception {
    // 1MiB
    flowControlWindow = 1048576;
    setUp();
    Http2Stream connectionStream = connection().connectionStream();
    Http2LocalFlowController localFlowController = connection().local().flowController();
    int actualInitialWindowSize = localFlowController.initialWindowSize(connectionStream);
    int actualWindowSize = localFlowController.windowSize(connectionStream);
    assertEquals(flowControlWindow, actualWindowSize);
    assertEquals(flowControlWindow, actualInitialWindowSize);
}
Also used : Http2LocalFlowController(io.netty.handler.codec.http2.Http2LocalFlowController) Http2Stream(io.netty.handler.codec.http2.Http2Stream) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 Http2LocalFlowController (io.netty.handler.codec.http2.Http2LocalFlowController)5 Endpoint (io.netty.handler.codec.http2.Http2Connection.Endpoint)4 Http2Stream (io.netty.handler.codec.http2.Http2Stream)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 ByteBuf (io.netty.buffer.ByteBuf)2 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)2 Future (io.netty.util.concurrent.Future)2 FutureListener (io.netty.util.concurrent.FutureListener)2 Ignore (org.junit.Ignore)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