public void TestChunks()
        {
            ObjectPool <byte[]> pool = new ObjectPool <byte[]>(() => { return(new byte[1024]); });

            DummySockNetChannel channel = new DummySockNetChannel()
            {
                State      = null,
                IsActive   = true,
                BufferPool = pool
            };

            channel.Pipe = new SockNetChannelPipe(channel);

            GdsSockNetChannelModule module = new GdsSockNetChannelModule(true);

            channel.AddModule(module);
            channel.Connect();

            uint streamId = 1;

            ChunkedBuffer body = new ChunkedBuffer(pool);

            body.OfferRaw(Encoding.UTF8.GetBytes("This "), 0, Encoding.UTF8.GetByteCount("This "));

            GdsFrame chunk1 = GdsFrame.NewContentFrame(streamId, new Dictionary <string, byte[]>()
            {
                { "test1", new byte[] { 1 } },
                { "test", new byte[] { 1 } },
            },
                                                       false, body, false);
            ChunkedBuffer buffer          = ToBuffer(chunk1);
            object        receiveResponse = buffer;

            channel.Receive(ref receiveResponse);
            buffer.Close();

            Assert.IsTrue(receiveResponse is ChunkedBuffer);

            body = new ChunkedBuffer(pool);
            body.OfferRaw(Encoding.UTF8.GetBytes("is "), 0, Encoding.UTF8.GetByteCount("is "));

            GdsFrame chunk2 = GdsFrame.NewContentFrame(streamId, new Dictionary <string, byte[]>()
            {
                { "test2", new byte[] { 2 } },
                { "test", new byte[] { 2 } },
            },
                                                       false, body, false);

            buffer          = ToBuffer(chunk2);
            receiveResponse = buffer;
            channel.Receive(ref receiveResponse);
            buffer.Close();

            Assert.IsTrue(receiveResponse is ChunkedBuffer);

            body = new ChunkedBuffer(pool);
            body.OfferRaw(Encoding.UTF8.GetBytes("awesome!"), 0, Encoding.UTF8.GetByteCount("awesome!"));

            GdsFrame chunk3 = GdsFrame.NewContentFrame(streamId, new Dictionary <string, byte[]>()
            {
                { "test3", new byte[] { 3 } },
                { "test", new byte[] { 3 } },
            },
                                                       false, body, true);

            buffer          = ToBuffer(chunk3);
            receiveResponse = buffer;
            channel.Receive(ref receiveResponse);
            buffer.Close();

            Assert.IsTrue(receiveResponse is GdsFrame);
            Assert.AreEqual("This is awesome!", ((GdsFrame)receiveResponse).Body.ToString(Encoding.UTF8));
            Assert.AreEqual(1, ((GdsFrame)receiveResponse).Headers["test1"][0]);
            Assert.AreEqual(2, ((GdsFrame)receiveResponse).Headers["test2"][0]);
            Assert.AreEqual(3, ((GdsFrame)receiveResponse).Headers["test3"][0]);
            Assert.AreEqual(3, ((GdsFrame)receiveResponse).Headers["test"][0]);

            body.Dispose();
            chunk1.Dispose();
            chunk2.Dispose();
            chunk3.Dispose();

            Console.WriteLine("Pool stats: " + pool.ObjectsInPool + "/" + pool.TotalNumberOfObjects);
        }
        public void TestChunks()
        {
            ObjectPool<byte[]> pool = new ObjectPool<byte[]>(() => { return new byte[1024]; });

            DummySockNetChannel channel = new DummySockNetChannel()
            {
                State = null,
                IsActive = true,
                BufferPool = pool
            };
            channel.Pipe = new SockNetChannelPipe(channel);

            GdsSockNetChannelModule module = new GdsSockNetChannelModule(true);
            channel.AddModule(module);
            channel.Connect();

            uint streamId = 1;

            ChunkedBuffer body = new ChunkedBuffer(pool);
            body.OfferRaw(Encoding.UTF8.GetBytes("This "), 0, Encoding.UTF8.GetByteCount("This "));

            GdsFrame chunk1 = GdsFrame.NewContentFrame(streamId, new Dictionary<string, byte[]>()
                {
                    { "test1", new byte[] { 1 } } ,
                    { "test", new byte[] { 1 } } ,
                },
                false, body, false);
            ChunkedBuffer buffer = ToBuffer(chunk1);
            object receiveResponse = buffer;
            channel.Receive(ref receiveResponse);
            buffer.Close();

            Assert.IsTrue(receiveResponse is ChunkedBuffer);

            body = new ChunkedBuffer(pool);
            body.OfferRaw(Encoding.UTF8.GetBytes("is "), 0, Encoding.UTF8.GetByteCount("is "));

            GdsFrame chunk2 = GdsFrame.NewContentFrame(streamId, new Dictionary<string, byte[]>()
                {
                    { "test2", new byte[] { 2 } } ,
                    { "test", new byte[] { 2 } } ,
                },
                false, body, false);
            buffer = ToBuffer(chunk2);
            receiveResponse = buffer;
            channel.Receive(ref receiveResponse);
            buffer.Close();

            Assert.IsTrue(receiveResponse is ChunkedBuffer);

            body = new ChunkedBuffer(pool);
            body.OfferRaw(Encoding.UTF8.GetBytes("awesome!"), 0, Encoding.UTF8.GetByteCount("awesome!"));

            GdsFrame chunk3 = GdsFrame.NewContentFrame(streamId, new Dictionary<string, byte[]>()
                {
                    { "test3", new byte[] { 3 } } ,
                    { "test", new byte[] { 3 } } ,
                },
                false, body, true);
            buffer = ToBuffer(chunk3);
            receiveResponse = buffer;
            channel.Receive(ref receiveResponse);
            buffer.Close();

            Assert.IsTrue(receiveResponse is GdsFrame);
            Assert.AreEqual("This is awesome!", ((GdsFrame)receiveResponse).Body.ToString(Encoding.UTF8));
            Assert.AreEqual(1, ((GdsFrame)receiveResponse).Headers["test1"][0]);
            Assert.AreEqual(2, ((GdsFrame)receiveResponse).Headers["test2"][0]);
            Assert.AreEqual(3, ((GdsFrame)receiveResponse).Headers["test3"][0]);
            Assert.AreEqual(3, ((GdsFrame)receiveResponse).Headers["test"][0]);

            body.Dispose();
            chunk1.Dispose();
            chunk2.Dispose();
            chunk3.Dispose();

            Console.WriteLine("Pool stats: " + pool.ObjectsInPool + "/" + pool.TotalNumberOfObjects);
        }