예제 #1
0
        public void TestFailToLargeMessage()
        {
            var ch = new EmbeddedChannel(new FrameDecoder(2, _prepend, _append));

            for (var i = 0; i < 2; i++)
            {
                Assert.Throws <TooLongFrameException>(
                    () =>
                    ch.WriteInbound(
                        Unpooled.Buffer(5)
                        .WriteBytes(_prepend)
                        .WriteBytes(_iso.GetBytes("AAAA"))
                        .WriteBytes(_append)));

                ch.WriteInbound(Unpooled.Buffer(4)
                                .WriteBytes(_prepend)
                                .WriteBytes(_iso.GetBytes("A"))
                                .WriteBytes(_append));
                var buf = ch.ReadInbound <IByteBuffer>();
                ReferenceCountUtil.ReleaseLater(buf);
                Assert.Equal(1, buf.ReadableBytes);
                Assert.Equal("A", buf.ToString(_iso));
                buf.Release();
            }
        }
예제 #2
0
        public void FailSlowTooLongFrameRecovery()
        {
            var ch = new EmbeddedChannel(new LengthFieldBasedFrameDecoder(5, 0, 4, 0, 4, false));

            for (int i = 0; i < 2; i++)
            {
                Assert.False(ch.WriteInbound(Unpooled.WrappedBuffer(new byte[] { 0, 0, 0, 2 })));
                Assert.Throws <TooLongFrameException>(() => ch.WriteInbound(Unpooled.WrappedBuffer(new byte[] { 0, 0 })));
                ch.WriteInbound(Unpooled.WrappedBuffer(new byte[] { 0, 0, 0, 1, (byte)'A' }));
                var buf = ch.ReadInbound <IByteBuffer>();
                ReferenceCountUtil.ReleaseLater(buf);
                Encoding iso = Encoding.GetEncoding("ISO-8859-1");
                Assert.Equal("A", buf.ToString(iso));
                buf.Release();
            }
        }
예제 #3
0
        public void TestFullMessage()
        {
            var ch = new EmbeddedChannel(new FrameDecoder(1024, _prepend, _append));

            for (var i = 0; i < 2; i++)
            {
                ch.WriteInbound(Unpooled.Buffer(4)
                                .WriteBytes(_prepend)
                                .WriteBytes(_iso.GetBytes("A"))
                                .WriteBytes(_append));
                var buf = ch.ReadInbound <IByteBuffer>();
                ReferenceCountUtil.ReleaseLater(buf);
                Assert.Equal(1, buf.ReadableBytes);
                Assert.Equal("A", buf.ToString(_iso));
                buf.Release();
            }
        }