Search in sources :

Example 6 with Http2LocalFlowController

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

the class NettyHandlerTestBase method windowUpdateMatchesTarget.

@Test
public void windowUpdateMatchesTarget() throws Exception {
    Http2Stream connectionStream = connection().connectionStream();
    Http2LocalFlowController localFlowController = connection().local().flowController();
    makeStream();
    AbstractNettyHandler handler = (AbstractNettyHandler) handler();
    handler.setAutoTuneFlowControl(true);
    ByteBuf data = ctx().alloc().buffer(1024);
    while (data.isWritable()) {
        data.writeLong(1111);
    }
    int length = data.readableBytes();
    ByteBuf frame = dataFrame(3, false, data.copy());
    channelRead(frame);
    int accumulator = length;
    // 40 is arbitrary, any number large enough to trigger a window update would work
    for (int i = 0; i < 40; i++) {
        channelRead(dataFrame(3, false, data.copy()));
        accumulator += length;
    }
    long pingData = handler.flowControlPing().payload();
    ByteBuf buffer = handler.ctx().alloc().buffer(8);
    buffer.writeLong(pingData);
    channelRead(pingFrame(true, buffer));
    assertEquals(accumulator, handler.flowControlPing().getDataSincePing());
    assertEquals(2 * accumulator, 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 7 with Http2LocalFlowController

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

the class NettyClientHandlerTest 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);
    assertEquals(1048576, actualWindowSize);
}
Also used : Http2LocalFlowController(io.netty.handler.codec.http2.Http2LocalFlowController) Http2Stream(io.netty.handler.codec.http2.Http2Stream) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with Http2LocalFlowController

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

the class Http2FrameCodec method writeHeadersFrame.

private void writeHeadersFrame(Http2HeadersFrame headersFrame, ChannelPromise promise) {
    int streamId = headersFrame.streamId();
    if (!isStreamIdValid(streamId)) {
        final Endpoint<Http2LocalFlowController> localEndpoint = http2Handler.connection().local();
        streamId = localEndpoint.incrementAndGetNextStreamId();
        try {
            // Try to create a stream in OPEN state before writing headers, to catch errors on stream creation
            // early on i.e. max concurrent streams limit reached, stream id exhaustion, etc.
            localEndpoint.createStream(streamId, false);
        } catch (Http2Exception e) {
            promise.setFailure(e);
            return;
        }
        ctx.fireUserEventTriggered(new Http2StreamActiveEvent(streamId, headersFrame));
    }
    http2Handler.encoder().writeHeaders(http2HandlerCtx, streamId, headersFrame.headers(), headersFrame.padding(), headersFrame.isEndStream(), promise);
}
Also used : Endpoint(io.netty.handler.codec.http2.Http2Connection.Endpoint)

Example 9 with Http2LocalFlowController

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

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