public void MultipleWritesToActiveStream() { _encoder.WriteSettingsAckAsync(_ctx.Object, NewPromise()); EncoderWriteHeaders(3, NewPromise()); Assert.Equal(0, _encoder.NumBufferedStreams()); var data = Data(); int expectedBytes = data.ReadableBytes * 3; _encoder.WriteDataAsync(_ctx.Object, 3, data, 0, false, NewPromise()); _encoder.WriteDataAsync(_ctx.Object, 3, Data(), 0, false, NewPromise()); _encoder.WriteDataAsync(_ctx.Object, 3, Data(), 0, false, NewPromise()); EncoderWriteHeaders(3, NewPromise()); WriteVerifyWriteHeaders(Times.Exactly(2), 3); // Contiguous data writes are coalesced var bufCaptor = new ArgumentCaptor <IByteBuffer>(); _writer.Verify( x => x.WriteDataAsync( It.Is <IChannelHandlerContext>(v => v == _ctx.Object), It.Is <int>(v => v == 3), It.Is <IByteBuffer>(v => bufCaptor.Capture(v)), It.Is <int>(v => v == 0), It.Is <bool>(v => v == false), It.IsAny <IPromise>()), Times.Once); Assert.Equal(expectedBytes, bufCaptor.GetValue().ReadableBytes); }
private int CaptureWrite(int streamId) { var captor = new ArgumentCaptor <int>(); this.writer.Verify( x => x.Write( It.Is <IHttp2Stream>(v => ReferenceEquals(v, this.Stream(streamId))), It.Is <int>(v => captor.Capture(v)))); return(captor.GetValue()); }
public void PingAckFrameShouldMatch() { writer.WritePingAsync(this.ctx.Object, true, 1234567, this.ctx.Object.NewPromise()); this.ReadFrames(); var captor = new ArgumentCaptor <long>(); this.listener.Verify( x => x.OnPingAckRead( It.Is <IChannelHandlerContext>(c => c == this.ctx.Object), It.Is <long>(v => captor.Capture(v)))); Assert.Equal(1234567, captor.GetValue()); }
public void PropagateSettings() { this.BootstrapEnv(1, 1, 2); Http2Settings settings = new Http2Settings().PushEnabled(true); Http2TestUtil.RunInChannel(this.clientChannel, () => { this.clientHandler.Encoder.WriteSettingsAsync(this.CtxClient(), settings, this.NewPromiseClient()); this.clientChannel.Flush(); }); Assert.True(this.settingsLatch.Wait(TimeSpan.FromSeconds(5))); var settingsCaptor = new ArgumentCaptor <Http2Settings>(); this.settingsListener.Verify(x => x.MessageReceived(It.Is <Http2Settings>(v => settingsCaptor.Capture(v))), Times.Exactly(2)); Assert.Equal(settings, settingsCaptor.GetValue()); }
public void ServerReceivingInvalidClientPrefaceStringShouldHandleException() { _connection.Setup(x => x.IsServer).Returns(true); _handler = NewHandler(); _handler.ChannelRead(_ctx.Object, Unpooled.CopiedBuffer("BAD_PREFACE", Encoding.UTF8)); var captor = new ArgumentCaptor <IByteBuffer>(); _frameWriter.Verify( x => x.WriteGoAwayAsync( It.Is <IChannelHandlerContext>(v => v == _ctx.Object), It.Is <int>(v => v == 0), It.Is <Http2Error>(v => v == Http2Error.ProtocolError), It.Is <IByteBuffer>(v => captor.Capture(v)), It.Is <IPromise>(v => v == _promise))); Assert.Equal(0, captor.GetValue().ReferenceCount); }
public void ServerReceivingHttp1ClientPrefaceStringShouldIncludePreface() { _connection.Setup(x => x.IsServer).Returns(true); _handler = NewHandler(); _handler.ChannelRead(_ctx.Object, Unpooled.CopiedBuffer("GET /path HTTP/1.1", Encoding.ASCII)); var captor = new ArgumentCaptor <IByteBuffer>(); _frameWriter.Verify( x => x.WriteGoAwayAsync( It.Is <IChannelHandlerContext>(v => v == _ctx.Object), It.Is <int>(v => v == 0), It.Is <Http2Error>(v => v == Http2Error.ProtocolError), It.Is <IByteBuffer>(v => captor.Capture(v)), It.Is <IPromise>(v => v == _promise))); Assert.Equal(0, captor.GetValue().ReferenceCount); Assert.Contains("/path", _goAwayDebugCap); }
public void GoAwayFrameShouldMatch() { string text = "test"; var data = Buf(Encoding.UTF8.GetBytes(text)); writer.WriteGoAwayAsync(this.ctx.Object, STREAM_ID, ERROR_CODE, data.Slice(), this.ctx.Object.NewPromise()); this.ReadFrames(); var captor = new ArgumentCaptor <IByteBuffer>(); this.listener.Verify( x => x.OnGoAwayRead( It.Is <IChannelHandlerContext>(c => c == this.ctx.Object), It.Is <int>(id => id == STREAM_ID), It.Is <Http2Error>(v => v == ERROR_CODE), It.Is <IByteBuffer>(v => captor.Capture(v)))); Assert.Equal(data, captor.GetValue()); }
public void ServerShouldSend431OnHeaderSizeErrorWhenDecodingInitialHeaders() { int padding = 0; _handler = NewHandler(); Http2Exception e = new HeaderListSizeException(STREAM_ID, Http2Error.ProtocolError, "Header size exceeded max allowed size 8196", true); _stream.Setup(x => x.Id).Returns(STREAM_ID); _connection.Setup(x => x.IsServer).Returns(true); _stream.Setup(x => x.IsHeadersSent).Returns(false); _remote.Setup(x => x.LastStreamCreated).Returns(STREAM_ID); _frameWriter .Setup(x => x.WriteRstStreamAsync( It.Is <IChannelHandlerContext>(v => v == _ctx.Object), It.Is <int>(v => v == STREAM_ID), It.Is <Http2Error>(v => v == Http2Error.ProtocolError), It.Is <IPromise>(v => v == _promise))) .Returns(_future); _handler.ExceptionCaught(_ctx.Object, e); var captor = new ArgumentCaptor <IHttp2Headers>(); _encoder.Verify( x => x.WriteHeadersAsync( It.Is <IChannelHandlerContext>(v => v == _ctx.Object), It.Is <int>(v => v == STREAM_ID), It.Is <IHttp2Headers>(v => captor.Capture(v)), It.Is <int>(v => v == padding), It.Is <bool>(v => v == true), It.Is <IPromise>(v => v == _promise))); IHttp2Headers headers = captor.GetValue(); Assert.Equal(HttpResponseStatus.RequestHeaderFieldsTooLarge.CodeAsText, headers.Status); _frameWriter.Verify( x => x.WriteRstStreamAsync( It.Is <IChannelHandlerContext>(v => v == _ctx.Object), It.Is <int>(v => v == STREAM_ID), It.Is <Http2Error>(v => v == Http2Error.ProtocolError), It.Is <IPromise>(v => v == _promise))); }
public void ServerReceivingClientPrefaceStringFollowedByNonSettingsShouldHandleException() { _connection.Setup(x => x.IsServer).Returns(true); _handler = NewHandler(); // Create a connection preface followed by a bunch of zeros (i.e. not a settings frame). IByteBuffer buf = Unpooled.Buffer().WriteBytes(Http2CodecUtil.ConnectionPrefaceBuf()).WriteZero(10); _handler.ChannelRead(_ctx.Object, buf); var captor = new ArgumentCaptor <IByteBuffer>(); _frameWriter.Verify( x => x.WriteGoAwayAsync( It.Is <IChannelHandlerContext>(v => v == _ctx.Object), It.Is <int>(v => v == 0), It.Is <Http2Error>(v => v == Http2Error.ProtocolError), It.Is <IByteBuffer>(v => captor.Capture(v)), It.Is <IPromise>(v => v == _promise)), Times.AtLeastOnce); Assert.Equal(0, captor.GetValue().ReferenceCount); }
public void ConnectionErrorShouldStartShutdown() { _handler = NewHandler(); Http2Exception e = new Http2Exception(Http2Error.ProtocolError); _remote.Setup(x => x.LastStreamCreated).Returns(STREAM_ID); _handler.ExceptionCaught(_ctx.Object, e); var captor = new ArgumentCaptor <IByteBuffer>(); _frameWriter.Verify( x => x.WriteGoAwayAsync( It.Is <IChannelHandlerContext>(v => v == _ctx.Object), It.Is <int>(v => v == STREAM_ID), It.Is <Http2Error>(v => v == Http2Error.ProtocolError), It.Is <IByteBuffer>(v => captor.Capture(v)), It.Is <IPromise>(v => v == _promise))); var buf = captor.GetValue(); Assert.Equal(0, buf.ReferenceCount); // netty future.addListener 只配置了 ChannelFutureListener 的监听,而且isDone返回的值为false // 所以 processGoAwayWriteResult 没有执行 //Assert.Equal(1, buf.ReferenceCount); //buf.Release(); }
public void EntityRequestEntityResponse() { _frameInboundWriter.WriteInboundHeaders(1, _request, 0, false); IHttp2Stream stream = _frameCodec.Connection.Stream(1); Assert.NotNull(stream); Assert.Equal(Http2StreamState.Open, stream.State); IHttp2HeadersFrame inboundHeaders = _inboundHandler.ReadInbound <IHttp2HeadersFrame>(); IHttp2FrameStream stream2 = inboundHeaders.Stream; Assert.NotNull(stream2); Assert.Equal(1, stream2.Id); Assert.Equal(new DefaultHttp2HeadersFrame(_request, false) { Stream = stream2 }, inboundHeaders); Assert.Null(_inboundHandler.ReadInbound()); IByteBuffer hello = Http2TestUtil.BB("hello"); _frameInboundWriter.WriteInboundData(1, hello, 31, true); IHttp2DataFrame inboundData = _inboundHandler.ReadInbound <IHttp2DataFrame>(); IHttp2DataFrame expected = new DefaultHttp2DataFrame(Http2TestUtil.BB("hello"), true, 31) { Stream = stream2 }; Http2TestUtil.AssertEqualsAndRelease(expected, inboundData); Assert.Null(_inboundHandler.ReadInbound()); _channel.WriteOutbound(new DefaultHttp2HeadersFrame(_response, false) { Stream = stream2 }); _frameWriter.Verify( x => x.WriteHeadersAsync( It.Is <IChannelHandlerContext>(v => v == _frameCodec._ctx), It.Is <int>(v => v == 1), It.Is <IHttp2Headers>(v => v.Equals(_response)), It.Is <int>(v => v == 0), It.Is <bool>(v => v == false), It.IsAny <IPromise>())); _channel.WriteOutbound(new DefaultHttp2DataFrame(Http2TestUtil.BB("world"), true, 27) { Stream = stream2 }); var outboundData = new ArgumentCaptor <IByteBuffer>(); _frameWriter.Verify( x => x.WriteDataAsync( It.Is <IChannelHandlerContext>(v => v == _frameCodec._ctx), It.Is <int>(v => v == 1), It.Is <IByteBuffer>(v => outboundData.Capture(v)), It.Is <int>(v => v == 27), It.Is <bool>(v => v == true), It.IsAny <IPromise>())); IByteBuffer bb = Http2TestUtil.BB("world"); Assert.Equal(bb, outboundData.GetValue()); Assert.Equal(1, outboundData.GetValue().ReferenceCount); bb.Release(); outboundData.GetValue().Release(); _frameWriter.Verify( x => x.WriteRstStreamAsync( It.Is <IChannelHandlerContext>(v => v == _frameCodec._ctx), It.IsAny <int>(), It.IsAny <Http2Error>(), It.IsAny <IPromise>()), Times.Never()); Assert.True(_channel.IsActive); }