Search in sources :

Example 21 with Http2Stream

use of org.glassfish.grizzly.http2.Http2Stream in project grpc-java by grpc.

the class NettyClientHandler method goingAway.

/**
   * Handler for a GOAWAY being either sent or received. Fails any streams created after the
   * last known stream.
   */
private void goingAway(Status status) {
    lifecycleManager.notifyShutdown(status);
    final Status goAwayStatus = lifecycleManager.getShutdownStatus();
    final int lastKnownStream = connection().local().lastStreamKnownByPeer();
    try {
        connection().forEachActiveStream(new Http2StreamVisitor() {

            @Override
            public boolean visit(Http2Stream stream) throws Http2Exception {
                if (stream.id() > lastKnownStream) {
                    NettyClientStream.TransportState clientStream = clientStream(stream);
                    if (clientStream != null) {
                        clientStream.transportReportStatus(goAwayStatus, false, new Metadata());
                    }
                    stream.close();
                }
                return true;
            }
        });
    } catch (Http2Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Status(io.grpc.Status) Http2Exception(io.netty.handler.codec.http2.Http2Exception) Http2StreamVisitor(io.netty.handler.codec.http2.Http2StreamVisitor) Metadata(io.grpc.Metadata) Http2Stream(io.netty.handler.codec.http2.Http2Stream)

Example 22 with Http2Stream

use of org.glassfish.grizzly.http2.Http2Stream 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)

Example 23 with Http2Stream

use of org.glassfish.grizzly.http2.Http2Stream 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 24 with Http2Stream

use of org.glassfish.grizzly.http2.Http2Stream 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 25 with Http2Stream

use of org.glassfish.grizzly.http2.Http2Stream in project grpc-java by grpc.

the class NettyClientHandlerTest method newHandler.

@Override
protected NettyClientHandler newHandler() throws Http2Exception {
    Http2Connection connection = new DefaultHttp2Connection(false);
    // Create and close a stream previous to the nextStreamId.
    Http2Stream stream = connection.local().createStream(streamId - 2, true);
    stream.close();
    Ticker ticker = new Ticker() {

        @Override
        public long read() {
            return nanoTime;
        }
    };
    return NettyClientHandler.newHandler(connection, frameReader(), frameWriter(), lifecycleManager, mockKeepAliveManager, flowControlWindow, maxHeaderListSize, ticker);
}
Also used : DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) Http2Connection(io.netty.handler.codec.http2.Http2Connection) Ticker(com.google.common.base.Ticker) Http2Stream(io.netty.handler.codec.http2.Http2Stream)

Aggregations

Http2Stream (io.netty.handler.codec.http2.Http2Stream)21 Http2Exception (io.netty.handler.codec.http2.Http2Exception)8 Test (org.junit.Test)8 Http2StreamVisitor (io.netty.handler.codec.http2.Http2StreamVisitor)5 Metadata (io.grpc.Metadata)4 Http2LocalFlowController (io.netty.handler.codec.http2.Http2LocalFlowController)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 HttpFields (org.eclipse.jetty.http.HttpFields)4 HTTP2Session (org.eclipse.jetty.http2.HTTP2Session)4 HTTP2Stream (org.eclipse.jetty.http2.HTTP2Stream)4 Session (org.eclipse.jetty.http2.api.Session)4 Stream (org.eclipse.jetty.http2.api.Stream)4 ServerSessionListener (org.eclipse.jetty.http2.api.server.ServerSessionListener)4 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)4 FuturePromise (org.eclipse.jetty.util.FuturePromise)4 Status (io.grpc.Status)2 ByteBuf (io.netty.buffer.ByteBuf)2 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)2 ChannelFuture (io.netty.channel.ChannelFuture)2 DefaultHttp2Connection (io.netty.handler.codec.http2.DefaultHttp2Connection)2