use of org.eclipse.jetty.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();
final Ticker ticker = new Ticker() {
@Override
public long read() {
return nanoTime;
}
};
Supplier<Stopwatch> stopwatchSupplier = new Supplier<Stopwatch>() {
@Override
public Stopwatch get() {
return Stopwatch.createUnstarted(ticker);
}
};
return NettyClientHandler.newHandler(connection, frameReader(), frameWriter(), lifecycleManager, mockKeepAliveManager, false, flowControlWindow, maxHeaderListSize, stopwatchSupplier, tooManyPingsRunnable, transportTracer, Attributes.EMPTY, "someauthority", null);
}
use of org.eclipse.jetty.http2.HTTP2Stream in project grpc-java by grpc.
the class NettyServerHandlerTest method connectionWindowShouldBeOverridden.
@Test
public void connectionWindowShouldBeOverridden() throws Exception {
// 1MiB
flowControlWindow = 1048576;
manualSetUp();
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);
}
use of org.eclipse.jetty.http2.HTTP2Stream in project grpc-java by grpc.
the class NettyHandlerTestBase method windowUpdateMatchesTarget.
@Test
public void windowUpdateMatchesTarget() throws Exception {
manualSetUp();
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();
channelRead(pingFrame(true, pingData));
assertEquals(accumulator, handler.flowControlPing().getDataSincePing());
assertEquals(2 * accumulator, localFlowController.initialWindowSize(connectionStream));
}
use of org.eclipse.jetty.http2.HTTP2Stream in project grpc-java by grpc.
the class NettyClientHandler method createStreamTraced.
private void createStreamTraced(final int streamId, final NettyClientStream.TransportState stream, final Http2Headers headers, boolean isGet, final boolean shouldBeCountedForInUse, final ChannelPromise promise) {
// Create an intermediate promise so that we can intercept the failure reported back to the
// application.
ChannelPromise tempPromise = ctx().newPromise();
encoder().writeHeaders(ctx(), streamId, headers, 0, isGet, tempPromise).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()) {
// The http2Stream will be null in case a stream buffered in the encoder
// was canceled via RST_STREAM.
Http2Stream http2Stream = connection().stream(streamId);
if (http2Stream != null) {
stream.getStatsTraceContext().clientOutboundHeaders();
http2Stream.setProperty(streamKey, stream);
// be later than we would like.
if (shouldBeCountedForInUse) {
inUseState.updateObjectInUse(http2Stream, true);
}
// Attach the client stream to the HTTP/2 stream object as user data.
stream.setHttp2Stream(http2Stream);
}
// Otherwise, the stream has been cancelled and Netty is sending a
// RST_STREAM frame which causes it to purge pending writes from the
// flow-controller and delete the http2Stream. The stream listener has already
// been notified of cancellation so there is nothing to do.
// Just forward on the success status to the original promise.
promise.setSuccess();
} else {
Throwable cause = future.cause();
if (cause instanceof StreamBufferingEncoder.Http2GoAwayException) {
StreamBufferingEncoder.Http2GoAwayException e = (StreamBufferingEncoder.Http2GoAwayException) cause;
Status status = statusFromH2Error(Status.Code.UNAVAILABLE, "GOAWAY closed buffered stream", e.errorCode(), e.debugData());
cause = status.asRuntimeException();
stream.transportReportStatus(status, RpcProgress.MISCARRIED, true, new Metadata());
} else if (cause instanceof StreamBufferingEncoder.Http2ChannelClosedException) {
Status status = lifecycleManager.getShutdownStatus();
if (status == null) {
status = Status.UNAVAILABLE.withCause(cause).withDescription("Connection closed while stream is buffered");
}
stream.transportReportStatus(status, RpcProgress.MISCARRIED, true, new Metadata());
}
promise.setFailure(cause);
}
}
});
}
use of org.eclipse.jetty.http2.HTTP2Stream in project vert.x by eclipse.
the class Http2ConnectionBase method setWindowSize.
@Override
public HttpConnection setWindowSize(int windowSize) {
try {
Http2Stream stream = handler.encoder().connection().connectionStream();
int delta = windowSize - this.windowSize;
handler.decoder().flowController().incrementWindowSize(stream, delta);
this.windowSize = windowSize;
return this;
} catch (Http2Exception e) {
throw new VertxException(e);
}
}
Aggregations