示例#1
0
        public void TestSimpleLeaseAndReturn()
        {
            var buffer = new ByteBufferPool(10, new int[] { 1, 2, 3, 4 });
            byte[] a = buffer.LeaseBytes(1);
            byte[] b = buffer.LeaseBytes(2);
            byte[] c = buffer.LeaseBytes(3);
            byte[] d = buffer.LeaseBytes(4);

            Assert.AreEqual(0, buffer.AllocatedBytes);

            buffer.ReturnBytes(a);

            Assert.AreEqual(1, buffer.AllocatedBytes);

            buffer.ReturnBytes(b);

            Assert.AreEqual(3, buffer.AllocatedBytes);

            buffer.ReturnBytes(c);

            Assert.AreEqual(6, buffer.AllocatedBytes);

            buffer.ReturnBytes(d);

            Assert.AreEqual(10, buffer.AllocatedBytes);
        }
示例#2
0
        public void TestServiceLargeBytes()
        {
            var buffer = new ByteBufferPool(10, new int[] { 10, 20, 30 });

            Assert.AreEqual(0, buffer.AllocatedBytes);

            var bytes = buffer.LeaseBytes(400);

            Assert.AreEqual(400, bytes.Length);

            buffer.ReturnBytes(bytes);

            Assert.AreEqual(0, buffer.AllocatedBytes);
        }
示例#3
0
        public void TestAging()
        {
            var buffer = new ByteBufferPool(10, new int[] { 1 }, 1);

            Assert.AreEqual(0, buffer.AllocatedBytes);

            var bytes = buffer.LeaseBytes(1);
            buffer.ReturnBytes(bytes);

            Assert.AreEqual(1, buffer.AllocatedBytes);

            System.Threading.Thread.Sleep(1000);

            buffer.Maintain();

            Assert.AreEqual(0, buffer.AllocatedBytes);
        }
示例#4
0
        public void TestInvalidByteReturnSize()
        {
            var buffer = new ByteBufferPool(10, new int[] { 10, 20, 30 });

            Assert.AreEqual(0, buffer.AllocatedBytes);

            buffer.ReturnBytes(new byte[40]);

            Assert.AreEqual(0, buffer.AllocatedBytes);

            buffer.ReturnBytes(new byte[5]);

            Assert.AreEqual(0, buffer.AllocatedBytes);
        }