Example #1
0
        public virtual void TestSingleFrame()
        {
            RpcUtil.RpcFrameDecoder decoder = new RpcUtil.RpcFrameDecoder();
            // Test "Length field is not received yet"
            ByteBuffer    buffer        = ByteBuffer.Allocate(1);
            ChannelBuffer buf           = new ByteBufferBackedChannelBuffer(buffer);
            ChannelBuffer channelBuffer = (ChannelBuffer)decoder.Decode(Org.Mockito.Mockito.Mock
                                                                        <ChannelHandlerContext>(), Org.Mockito.Mockito.Mock <Org.Jboss.Netty.Channel.Channel
                                                                                                                             >(), buf);

            Assert.True(channelBuffer == null);
            // Test all bytes are not received yet
            byte[] fragment = new byte[4 + 9];
            fragment[0] = unchecked ((byte)(1 << 7));
            // final fragment
            fragment[1] = 0;
            fragment[2] = 0;
            fragment[3] = unchecked ((byte)10);
            // fragment size = 10 bytes
            Assert.True(XDR.IsLastFragment(fragment));
            Assert.True(XDR.FragmentSize(fragment) == 10);
            buffer = ByteBuffer.Allocate(4 + 9);
            buffer.Put(fragment);
            buffer.Flip();
            buf           = new ByteBufferBackedChannelBuffer(buffer);
            channelBuffer = (ChannelBuffer)decoder.Decode(Org.Mockito.Mockito.Mock <ChannelHandlerContext
                                                                                    >(), Org.Mockito.Mockito.Mock <Org.Jboss.Netty.Channel.Channel>(), buf);
            Assert.True(channelBuffer == null);
        }
Example #2
0
        public virtual void TestMultipleFrames()
        {
            RpcUtil.RpcFrameDecoder decoder = new RpcUtil.RpcFrameDecoder();
            // Test multiple frames
            byte[] fragment1 = new byte[4 + 10];
            fragment1[0] = 0;
            // not final fragment
            fragment1[1] = 0;
            fragment1[2] = 0;
            fragment1[3] = unchecked ((byte)10);
            // fragment size = 10 bytes
            NUnit.Framework.Assert.IsFalse(XDR.IsLastFragment(fragment1));
            Assert.True(XDR.FragmentSize(fragment1) == 10);
            // decoder should wait for the final fragment
            ByteBuffer buffer = ByteBuffer.Allocate(4 + 10);

            buffer.Put(fragment1);
            buffer.Flip();
            ChannelBuffer buf           = new ByteBufferBackedChannelBuffer(buffer);
            ChannelBuffer channelBuffer = (ChannelBuffer)decoder.Decode(Org.Mockito.Mockito.Mock
                                                                        <ChannelHandlerContext>(), Org.Mockito.Mockito.Mock <Org.Jboss.Netty.Channel.Channel
                                                                                                                             >(), buf);

            Assert.True(channelBuffer == null);
            byte[] fragment2 = new byte[4 + 10];
            fragment2[0] = unchecked ((byte)(1 << 7));
            // final fragment
            fragment2[1] = 0;
            fragment2[2] = 0;
            fragment2[3] = unchecked ((byte)10);
            // fragment size = 10 bytes
            Assert.True(XDR.IsLastFragment(fragment2));
            Assert.True(XDR.FragmentSize(fragment2) == 10);
            buffer = ByteBuffer.Allocate(4 + 10);
            buffer.Put(fragment2);
            buffer.Flip();
            buf           = new ByteBufferBackedChannelBuffer(buffer);
            channelBuffer = (ChannelBuffer)decoder.Decode(Org.Mockito.Mockito.Mock <ChannelHandlerContext
                                                                                    >(), Org.Mockito.Mockito.Mock <Org.Jboss.Netty.Channel.Channel>(), buf);
            Assert.True(channelBuffer != null);
            // Complete frame should have to total size 10+10=20
            Assert.Equal(20, channelBuffer.ReadableBytes());
        }