TryFreeSlabs() private method

Searches for empty slabs and frees one if there are more than InitialSlabs number of slabs.
private TryFreeSlabs ( ) : void
return void
Example #1
0
        public void TryFreeSlabTest()
        {
            long SlabSize = BufferPool.MinimumSlabSize;
            int InitialSlabs = 1;
            int SubsequentSlabs = 3;
            BufferPool target = new BufferPool(SlabSize, InitialSlabs, SubsequentSlabs);
            Assert.AreEqual<long>(InitialSlabs, target.SlabCount);

            //GetBuffer of slab size
            IBuffer buff1 = target.GetBuffer(SlabSize);
            //confirm that slabcount is 1
            Assert.AreEqual<long>(InitialSlabs, target.SlabCount);

            //Try to free a slab and do a recount -- slabcount should remain 1
            target.TryFreeSlabs();
            Assert.AreEqual<long>(InitialSlabs, target.SlabCount);

            //Get it again to force construction of 3 new slabs
            IBuffer buff2 = target.GetBuffer(SlabSize);
            Assert.AreEqual<long>(SubsequentSlabs + InitialSlabs, target.SlabCount);

            //Free a slab and do a recount
            target.TryFreeSlabs();
            Assert.AreEqual<long>(SubsequentSlabs + InitialSlabs - 1, target.SlabCount);

            //Free a slab and do a recount -- slabcount should not budge since only one slab is free
            target.TryFreeSlabs();
            Assert.AreEqual<long>(SubsequentSlabs + InitialSlabs - 1, target.SlabCount);

            //Try to free a slab and do a recount
            //Free 1st buffer
            buff1.Dispose();
            target.TryFreeSlabs();
            Assert.AreEqual<long>(SubsequentSlabs + InitialSlabs - 2, target.SlabCount);

            //Try to free a slab and do a recount -- slabcount shouldn't go below two
            target.TryFreeSlabs();
            Assert.AreEqual<long>(SubsequentSlabs + InitialSlabs - 2, target.SlabCount);

            //Free buffer, try to free a slab and do a recount -- slabcount should now be back to 1
            buff2.Dispose();
            target.TryFreeSlabs();
            Assert.AreEqual<long>(SubsequentSlabs + InitialSlabs - 3, target.SlabCount);
        }