private void GracefulShutdownTimeoutWhenConnectionErrorTest0(ShutdownHint hint) { _handler = NewHandler(); long expectedMillis = 1234; _handler.GracefulShutdownTimeout = TimeSpan.FromMilliseconds(expectedMillis); Http2Exception exception = new Http2Exception(Http2Error.ProtocolError, "Test error", hint); _handler.OnConnectionError(_ctx.Object, false, exception, exception); if (hint == ShutdownHint.GracefulShutdown) { _executor.Verify( x => x.Schedule( It.IsAny <Action <object> >(), It.IsAny <object>(), It.Is <TimeSpan>(v => v == TimeSpan.FromMilliseconds(expectedMillis))), Times.AtLeastOnce()); } else { _executor.Verify( x => x.Schedule( It.IsAny <Action <object, object> >(), It.IsAny <object>(), It.IsAny <object>(), It.Is <TimeSpan>(v => v == TimeSpan.FromMilliseconds(expectedMillis))), Times.AtLeastOnce()); } }
public override void ExceptionCaught(IChannelHandlerContext context, Exception cause) { Http2Exception e = Http2CodecUtil.GetEmbeddedHttp2Exception(cause); if (e != null) { self.clientException = e; self.clientLatch.SafeSignal(); } else { base.ExceptionCaught(context, cause); } }
public void ConnectionErrorForWriterException() { this.InitState(STREAM_A, 1, true); this.InitState(STREAM_B, 2, true); this.InitState(STREAM_C, 3, true); this.InitState(STREAM_D, 4, true); Exception fakeException = new Http2RuntimeException("Fake exception"); this.writer .Setup(x => x.Write( It.Is <IHttp2Stream>(v => ReferenceEquals(v, this.Stream(STREAM_C))), It.Is <int>(v => v == 3))) .Throws(fakeException); try { this.Write(10); Assert.False(true, "Expected an exception"); } catch (Http2Exception e) { Assert.False(Http2Exception.IsStreamError(e)); Assert.Equal(Http2Error.InternalError, e.Error); Assert.Same(fakeException, e.InnerException); } this.VerifyWrite(Times.AtMost(1), STREAM_A, 1); this.VerifyWrite(Times.AtMost(1), STREAM_B, 2); this.VerifyWrite(STREAM_C, 3); this.VerifyWrite(Times.AtMost(1), STREAM_D, 4); this.writer .Setup(x => x.Write( It.Is <IHttp2Stream>(v => ReferenceEquals(v, this.Stream(STREAM_C))), It.Is <int>(v => v == 3))) .Callback <IHttp2Stream, int>((stream, numBytes) => this.WriteAnswer(stream, numBytes, false)); Assert.False(this.Write(10)); this.VerifyWrite(STREAM_A, 1); this.VerifyWrite(STREAM_B, 2); this.VerifyWrite(Times.Exactly(2), STREAM_C, 3); this.VerifyWrite(STREAM_D, 4); }
public void ClientRequestSingleHeaderNonAsciiShouldThrow() { this.BootstrapEnv(1, 1, 1); var http2Headers = new DefaultHttp2Headers() { Method = new AsciiString("GET"), Scheme = new AsciiString("https"), Authority = new AsciiString("example.org"), Path = new AsciiString("/some/path/resource2"), }; http2Headers.Add(new AsciiString(Encoding.UTF8.GetBytes("çã"), true), new AsciiString(Encoding.UTF8.GetBytes("Ãã"), true)); Http2TestUtil.RunInChannel(this.clientChannel, () => { this.clientHandler.Encoder.WriteHeadersAsync(this.CtxClient(), 3, http2Headers, 0, true, this.NewPromiseClient()); this.clientChannel.Flush(); }); this.AwaitResponses(); Assert.True(Http2Exception.IsStreamError(this.clientException)); }
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(); }