Ejemplo n.º 1
0
        public void CanSendGoAwayFramesWithDecreasingLastStreamIds()
        {
            _handler = NewHandler();
            IByteBuffer data      = DummyData();
            var         errorCode = Http2Error.InternalError;

            _handler.GoAwayAsync(_ctx.Object, STREAM_ID + 2, errorCode, (IByteBuffer)data.Retain(), _promise);
            _frameWriter.Verify(
                x => x.WriteGoAwayAsync(
                    It.Is <IChannelHandlerContext>(v => v == _ctx.Object),
                    It.Is <int>(v => v == STREAM_ID + 2),
                    It.Is <Http2Error>(v => v == errorCode),
                    It.Is <IByteBuffer>(v => v.Equals(data)),
                    It.Is <IPromise>(v => v == _promise)));
            _connection.Verify(
                x => x.GoAwaySent(
                    It.Is <int>(v => v == STREAM_ID + 2),
                    It.Is <Http2Error>(v => v == errorCode),
                    It.Is <IByteBuffer>(v => v.Equals(data))));
            _promise = new TaskCompletionSource();
            _handler.GoAwayAsync(_ctx.Object, STREAM_ID, errorCode, data, _promise);
            _frameWriter.Verify(
                x => x.WriteGoAwayAsync(
                    It.Is <IChannelHandlerContext>(v => v == _ctx.Object),
                    It.Is <int>(v => v == STREAM_ID),
                    It.Is <Http2Error>(v => v == errorCode),
                    It.Is <IByteBuffer>(v => v.Equals(data)),
                    It.Is <IPromise>(v => v == _promise)));
            _connection.Verify(
                x => x.GoAwaySent(
                    It.Is <int>(v => v == STREAM_ID),
                    It.Is <Http2Error>(v => v == errorCode),
                    It.Is <IByteBuffer>(v => v.Equals(data))));
            Assert.Equal(0, data.ReferenceCount);
        }
Ejemplo n.º 2
0
        public void CanSendGoAwayUsingVoidPromise()
        {
            _handler = NewHandler();
            IByteBuffer data      = DummyData();
            var         errorCode = Http2Error.InternalError;

            _handler = NewHandler();
            var cause = new Http2RuntimeException("fake exception");

            _frameWriter
            .Setup(x => x.WriteGoAwayAsync(
                       It.IsAny <IChannelHandlerContext>(),
                       It.IsAny <int>(),
                       It.IsAny <Http2Error>(),
                       It.IsAny <IByteBuffer>(),
                       It.IsAny <IPromise>()
                       ))
            .Returns <IChannelHandlerContext, int, Http2Error, IByteBuffer, IPromise>((c, id, err, buf, p) =>
            {
                Assert.False(p.IsVoid);
                // This is what DefaultHttp2FrameWriter does... I hate mocking :-(.
                var aggregatedPromise = new SimplePromiseAggregator(p);
                aggregatedPromise.NewPromise();
                aggregatedPromise.DoneAllocatingPromises();
                aggregatedPromise.SetException(cause);
                return(aggregatedPromise.Task);
            });
            _handler.GoAwayAsync(_ctx.Object, STREAM_ID, errorCode, data, Http2TestUtil.NewVoidPromise(_channel.Object));
            _pipeline.Verify(x => x.FireExceptionCaught(It.Is <Exception>(v => ReferenceEquals(v, cause))));
        }
Ejemplo n.º 3
0
        public void CannotSendGoAwayFrameWithIncreasingLastStreamIds()
        {
            _handler = NewHandler();
            IByteBuffer data      = DummyData();
            var         errorCode = Http2Error.InternalError;

            _handler.GoAwayAsync(_ctx.Object, STREAM_ID, errorCode, (IByteBuffer)data.Retain(), _promise);
            _connection.Verify(
                x => x.GoAwaySent(
                    It.Is <int>(v => v == STREAM_ID),
                    It.Is <Http2Error>(v => v == errorCode),
                    It.Is <IByteBuffer>(v => v.Equals(data))));
            _frameWriter.Verify(
                x => x.WriteGoAwayAsync(
                    It.Is <IChannelHandlerContext>(v => v == _ctx.Object),
                    It.Is <int>(v => v == STREAM_ID),
                    It.Is <Http2Error>(v => v == errorCode),
                    It.Is <IByteBuffer>(v => v.Equals(data)),
                    It.Is <IPromise>(v => v == _promise)));
            // The frameWriter is only mocked, so it should not have interacted with the promise.
            Assert.False(_promise.IsCompleted);

            _connection.Setup(x => x.GoAwaySent()).Returns(true);
            _remote.Setup(x => x.LastStreamKnownByPeer()).Returns(STREAM_ID);
            _connection
            .Setup(x => x.GoAwaySent(
                       It.IsAny <int>(),
                       It.IsAny <Http2Error>(),
                       It.IsAny <IByteBuffer>()))
            .Throws(new InvalidOperationException());
            _handler.GoAwayAsync(_ctx.Object, STREAM_ID + 2, errorCode, data, _promise);
            Assert.True(_promise.IsCompleted);
            Assert.False(_promise.IsSuccess);
            Assert.Equal(0, data.ReferenceCount);
            _frameWriter.VerifyNoOtherCalls();
        }
Ejemplo n.º 4
0
        public void CanSendGoAwayFrame()
        {
            IByteBuffer data      = DummyData();
            var         errorCode = Http2Error.InternalError;

            _future  = TaskUtil.Completed;
            _handler = NewHandler();
            _handler.GoAwayAsync(_ctx.Object, STREAM_ID, errorCode, data, _promise);

            _connection.Verify(
                x => x.GoAwaySent(
                    It.Is <int>(v => v == STREAM_ID),
                    It.Is <Http2Error>(v => v == errorCode),
                    It.Is <IByteBuffer>(v => v.Equals(data))));
            _frameWriter.Verify(
                x => x.WriteGoAwayAsync(
                    It.Is <IChannelHandlerContext>(v => v == _ctx.Object),
                    It.Is <int>(v => v == STREAM_ID),
                    It.Is <Http2Error>(v => v == errorCode),
                    It.Is <IByteBuffer>(v => v.Equals(data)),
                    It.Is <IPromise>(v => v == _promise)));
            _ctx.Verify(x => x.CloseAsync());
            Assert.Equal(0, data.ReferenceCount);
        }