public void TestIdempotentProcessId()
        {
            string a = DefaultChannelId.NewInstance().AsLongText().Substring(9, 4);
            string b = DefaultChannelId.NewInstance().AsLongText().Substring(9, 4);

            Assert.Equal(a, b);
        }
        public void TestIdempotentMachineId()
        {
            string a = DefaultChannelId.NewInstance().AsLongText().Substring(0, 8);
            string b = DefaultChannelId.NewInstance().AsLongText().Substring(0, 8);

            Assert.Equal(a, b);
        }
Example #3
0
        private static void TestUpgrade(Http2ConnectionHandler handler, IChannelHandler multiplexer)
        {
            IFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.Http11, HttpMethod.Options, "*");

            request.Headers.Set(HttpHeaderNames.Host, "netty.io");
            request.Headers.Set(HttpHeaderNames.Connection, "Upgrade, HTTP2-Settings");
            request.Headers.Set(HttpHeaderNames.Upgrade, "h2c");
            request.Headers.Set((AsciiString)"HTTP2-Settings", "AAMAAABkAAQAAP__");

            var                     parent  = new Mock <IServerChannel>();
            EmbeddedChannel         channel = new EmbeddedChannel(parent.Object, DefaultChannelId.NewInstance(), false, true, new ChannelHandlerAdapter());
            IChannelHandlerContext  ctx     = channel.Pipeline.FirstContext();
            Http2ServerUpgradeCodec codec;

            if (multiplexer == null)
            {
                codec = new Http2ServerUpgradeCodec(handler);
            }
            else
            {
                codec = new Http2ServerUpgradeCodec((Http2FrameCodec)handler, multiplexer);
            }
            Assert.True(codec.PrepareUpgradeResponse(ctx, request, new DefaultHttpHeaders()));
            codec.UpgradeTo(ctx, request);
            // Flush the channel to ensure we write out all buffered data
            channel.Flush();

            channel.WriteInbound(Http2CodecUtil.ConnectionPrefaceBuf());
            Http2FrameInboundWriter writer = new Http2FrameInboundWriter(channel);

            writer.WriteInboundSettings(new Http2Settings());
            writer.WriteInboundRstStream(Http2CodecUtil.HttpUpgradeStreamId, Http2Error.Cancel);

            Assert.Same(handler, channel.Pipeline.Remove <Http2ConnectionHandler>());
            Assert.Null(channel.Pipeline.Get <Http2ConnectionHandler>());
            Assert.True(channel.Finish());

            // Check that the preface was send (a.k.a the settings frame)
            var settingsBuffer = channel.ReadOutbound <IByteBuffer>();

            Assert.NotNull(settingsBuffer);
            settingsBuffer.Release();

            var buf = channel.ReadOutbound <IByteBuffer>();

            Assert.NotNull(buf);
            buf.Release();

            Assert.Null(channel.ReadOutbound());
        }
        public void TestLongText()
        {
            string text = DefaultChannelId.NewInstance().AsLongText();

            Assert.Matches(@"^[0-9a-f]{16}-[0-9a-f]{8}-[0-9a-f]{8}-[0-9a-f]{16}-[0-9a-f]{8}$", text);
        }
        public void TestLongText()
        {
            string text = DefaultChannelId.NewInstance().AsLongText();

            Assert.True(Regex.IsMatch(text, @"^[0-9a-f]{16}-[0-9a-f]{8}-[0-9a-f]{8}-[0-9a-f]{16}-[0-9a-f]{8}$"));
        }