예제 #1
0
        public Http2MultiplexCodecBuilderTest(EventLoopGroupFixture fixture)
        {
            this.fixture = fixture;

            var          serverChannelLatch = new CountdownEvent(1);
            LocalAddress serverAddress      = new LocalAddress(this.GetType().Name);

            this.serverLastInboundHandler = new SharableLastInboundHandler();
            ServerBootstrap sb = new ServerBootstrap()
                                 .Channel <LocalServerChannel>()
                                 .Group(fixture.Group)
                                 .ChildHandler(new ActionChannelInitializer <IChannel>(ch =>
            {
                this.serverConnectedChannel = ch;
                ch.Pipeline.AddLast(new Http2MultiplexCodecBuilder(true, new ActionChannelInitializer <IChannel>(ch0 =>
                {
                    ch0.Pipeline.AddLast(new TestServerChannelHandler());
                    ch0.Pipeline.AddLast(this.serverLastInboundHandler);
                })).Build());
                serverChannelLatch.SafeSignal();
            }));

            this.serverChannel = sb.BindAsync(serverAddress).GetAwaiter().GetResult();
            Bootstrap cb = new Bootstrap()
                           .Channel <LocalChannel>()
                           .Group(fixture.Group)
                           .Handler(new Http2MultiplexCodecBuilder(false, new ActionChannelInitializer <IChannel>(ch =>
            {
                Assert.False(true, "Should not be called for outbound streams");
            })).Build());

            this.clientChannel = cb.ConnectAsync(serverAddress).GetAwaiter().GetResult();
            Assert.True(serverChannelLatch.Wait(TimeSpan.FromSeconds(5)));
        }
예제 #2
0
        private void Dispose0()
        {
            if (_inboundHandler != null)
            {
                _inboundHandler.FinishAndReleaseAll();
                _inboundHandler = null;
            }
            var ch = _channel;

            if (ch != null)
            {
                _channel = null;
                ch.FinishAndReleaseAll();
                ch.CloseAsync();
            }
        }
예제 #3
0
        private void SetUp(Http2FrameCodecBuilder frameCodecBuilder, Http2Settings initialRemoteSettings)
        {
            // Some tests call this method twice. Once with JUnit's @Before and once directly to pass special settings.
            // This call ensures that in case of two consecutive calls to setUp(), the previous channel is shutdown and
            // ByteBufs are released correctly.
            Dispose0();

            _frameWriter = Http2TestUtil.MockedFrameWriter();

            var builder = frameCodecBuilder.FrameWriter(_frameWriter.Object);

            builder.FrameLogger     = new Http2FrameLogger(Common.Internal.Logging.InternalLogLevel.TRACE);
            builder.InitialSettings = initialRemoteSettings;
            _frameCodec             = frameCodecBuilder.Build();
            _inboundHandler         = new LastInboundHandler();

            _channel            = new EmbeddedChannel();
            _frameInboundWriter = new Http2FrameInboundWriter(_channel);
            //channel.Connect(new InetSocketAddress(0));
            _channel.Pipeline.AddLast(_frameCodec);
            _channel.Pipeline.AddLast(_inboundHandler);
            _channel.Pipeline.FireChannelActive();

            // Handshake
            _frameWriter.Verify(
                x => x.WriteSettingsAsync(
                    It.Is <IChannelHandlerContext>(v => v == _frameCodec._ctx),
                    It.IsAny <Http2Settings>(),
                    It.IsAny <IPromise>()));
            _frameWriter.VerifyNoOtherCalls();
            _channel.WriteInbound(Http2CodecUtil.ConnectionPrefaceBuf());

            _frameInboundWriter.WriteInboundSettings(initialRemoteSettings);
            _frameWriter.Verify(
                x => x.WriteSettingsAckAsync(
                    It.Is <IChannelHandlerContext>(v => v == _frameCodec._ctx),
                    It.IsAny <IPromise>()));
            _frameInboundWriter.WriteInboundSettingsAck();

            var settingsFrame = _inboundHandler.ReadInbound <IHttp2SettingsFrame>();

            Assert.NotNull(settingsFrame);
            var settingsAckFrame = _inboundHandler.ReadInbound <IHttp2SettingsAckFrame>();

            Assert.NotNull(settingsAckFrame);
        }