Exemple #1
0
        public void TestPassThroughOther()
        {
            EmbeddedChannel   ch     = new EmbeddedChannel(new Http2StreamFrameToHttpObjectCodec(true));
            IHttp2ResetFrame  reset  = new DefaultHttp2ResetFrame(Http2Error.NoError);
            IHttp2GoAwayFrame goaway = new DefaultHttp2GoAwayFrame(Http2Error.NoError);

            Assert.True(ch.WriteInbound(reset));
            Assert.True(ch.WriteInbound(goaway.Retain()));

            Assert.Equal(reset, ch.ReadInbound <IHttp2ResetFrame>());

            var frame = ch.ReadInbound <IHttp2GoAwayFrame>();

            try
            {
                Assert.Equal(goaway, frame);
                Assert.Null(ch.ReadInbound <object>());
                Assert.False(ch.Finish());
            }
            finally
            {
                goaway.Release();
                frame.Release();
            }
        }
Exemple #2
0
        public void GoAwayLastStreamIdOverflowed()
        {
            _frameInboundWriter.WriteInboundHeaders(5, _request, 31, false);

            IHttp2Stream stream = _frameCodec.Connection.Stream(5);

            Assert.NotNull(stream);
            Assert.Equal(Http2StreamState.Open, stream.State);

            var debugData = Http2TestUtil.BB("debug");
            IHttp2GoAwayFrame goAwayFrame = new DefaultHttp2GoAwayFrame(Http2Error.NoError, debugData.RetainedDuplicate());

            goAwayFrame.ExtraStreamIds = int.MaxValue;

            _channel.WriteOutbound(goAwayFrame);
            // When the last stream id computation overflows, the last stream id should just be set to 2^31 - 1.
            _frameWriter.Verify(
                x => x.WriteGoAwayAsync(
                    It.Is <IChannelHandlerContext>(v => v == _frameCodec._ctx),
                    It.Is <int>(v => v == int.MaxValue),
                    It.Is <Http2Error>(v => v == Http2Error.NoError),
                    It.Is <IByteBuffer>(v => v.Equals(debugData)),
                    It.IsAny <IPromise>()));
            debugData.Release();
            Assert.Equal(Http2StreamState.Open, stream.State);
            Assert.True(_channel.IsActive);
        }
Exemple #3
0
        public void SendGoAway()
        {
            _frameInboundWriter.WriteInboundHeaders(3, _request, 31, false);

            IHttp2Stream stream = _frameCodec.Connection.Stream(3);

            Assert.NotNull(stream);
            Assert.Equal(Http2StreamState.Open, stream.State);

            IByteBuffer debugData = Http2TestUtil.BB("debug");
            IByteBuffer expected  = debugData.Copy();

            IHttp2GoAwayFrame goAwayFrame = new DefaultHttp2GoAwayFrame(Http2Error.NoError, debugData.RetainedDuplicate());

            goAwayFrame.ExtraStreamIds = 2;

            _channel.WriteOutbound(goAwayFrame);
            _frameWriter.Verify(
                x => x.WriteGoAwayAsync(
                    It.Is <IChannelHandlerContext>(v => v == _frameCodec._ctx),
                    It.Is <int>(v => v == 7),
                    It.Is <Http2Error>(v => v == Http2Error.NoError),
                    It.Is <IByteBuffer>(v => v.Equals(expected)),
                    It.IsAny <IPromise>()));
            Assert.Equal(Http2StreamState.Open, stream.State);
            Assert.True(_channel.IsActive);
            expected.Release();
            debugData.Release();
        }
Exemple #4
0
        public void ReceiveGoaway()
        {
            IByteBuffer debugData = Http2TestUtil.BB("foo");

            _frameInboundWriter.WriteInboundGoAway(2, Http2Error.NoError, debugData);
            IHttp2GoAwayFrame expectedFrame = new DefaultHttp2GoAwayFrame(2, Http2Error.NoError, Http2TestUtil.BB("foo"));
            IHttp2GoAwayFrame actualFrame   = _inboundHandler.ReadInbound <IHttp2GoAwayFrame>();

            Http2TestUtil.AssertEqualsAndRelease(expectedFrame, actualFrame);
            Assert.Null(_inboundHandler.ReadInbound());
        }
        public void TestEqualOperation()
        {
            // in this case, 'goAwayFrame' and 'unknownFrame' will also have an EMPTY_BUFFER data
            // so we want to check that 'dflt' will not consider them equal.
            DefaultHttp2GoAwayFrame  goAwayFrame  = new DefaultHttp2GoAwayFrame(Http2Error.ProtocolError);
            DefaultHttp2UnknownFrame unknownFrame = new DefaultHttp2UnknownFrame(Http2FrameTypes.Headers, new Http2Flags(1));
            var dflt = new DefaultByteBufferHolder(Unpooled.Empty);

            try
            {
                // not using 'assertNotEquals' to be explicit about which object we are calling .equals() on
                Assert.False(dflt.Equals(goAwayFrame));
                Assert.False(dflt.Equals(unknownFrame));
            }
            finally
            {
                goAwayFrame.Release();
                unknownFrame.Release();
                dflt.Release();
            }
        }