NettyClientHandler extends AbstractNettyHandler { private void cancelStream(ChannelHandlerContext ctx, CancelClientStreamCommand cmd, ChannelPromise promise) { NettyClientStream stream = cmd.stream(); stream.transportReportStatus(cmd.reason(), true, new Metadata()); encoder().writeRstStream(ctx, stream.id(), Http2Error.CANCEL.code(), promise); } private  NettyClientHandler(Http2ConnectionDecoder decoder,
                             StreamBufferingEncoder encoder, Http2Settings settings,
                             ClientTransportLifecycleManager lifecycleManager,
                             Ticker ticker); @Override void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise); @Override void close(ChannelHandlerContext ctx, ChannelPromise promise); @Override void channelInactive(ChannelHandlerContext ctx);  }
@Test public void cancelBufferedStreamShouldChangeClientStreamStatus() throws Exception { receiveMaxConcurrentStreams(0); ChannelFuture createFuture = enqueue(new CreateStreamCommand(grpcHeaders, stream)); verify(stream).id(eq(3)); when(stream.id()).thenReturn(3); cancelStream(Status.CANCELLED); assertTrue(createFuture.isSuccess()); verify(stream).transportReportStatus(eq(Status.CANCELLED), eq(true), any(Metadata.class)); }
@Test public void cancelStreamShouldCreateAndThenFailBufferedStream() throws Exception { receiveMaxConcurrentStreams(0); enqueue(new CreateStreamCommand(grpcHeaders, stream)); verify(stream).id(3); when(stream.id()).thenReturn(3); cancelStream(Status.CANCELLED); verify(stream).transportReportStatus(eq(Status.CANCELLED), eq(true), any(Metadata.class)); }