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.TryFreeSlab(); 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.TryFreeSlab(); 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.TryFreeSlab(); Assert.AreEqual<long>(SubsequentSlabs + InitialSlabs - 1, target.SlabCount); //Try to free a slab and do a recount //Free 1st buffer buff1.Dispose(); target.TryFreeSlab(); Assert.AreEqual<long>(SubsequentSlabs + InitialSlabs - 2, target.SlabCount); //Try to free a slab and do a recount -- slabcount shouldn't go below two target.TryFreeSlab(); 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.TryFreeSlab(); Assert.AreEqual<long>(SubsequentSlabs + InitialSlabs - 3, target.SlabCount); }
public void GetBufferTest2() { long SlabSize = 2 * 1024 * 1024; int InitialSlabs = 1; int SubsequentSlabs = 1; BufferPool target = new BufferPool(SlabSize, InitialSlabs, SubsequentSlabs); long length = -1; IBuffer actual; actual = target.GetBuffer(length); }
public void SubsequentSlabsTest() { long SlabSize = BufferPool.MinimumSlabSize; //Minimum Slab size int InitialSlabs = 1; int SubsequentSlabs = 41; BufferPool target = new BufferPool(SlabSize, InitialSlabs, SubsequentSlabs); target.GetBuffer(SlabSize); target.GetBuffer(SlabSize); Assert.AreEqual<long>(SubsequentSlabs, target.SubsequentSlabs); Assert.AreEqual<long>(SubsequentSlabs + InitialSlabs, target.SlabCount); }
public void GetBufferTest() { long SlabSize = 2 * 1024 * 1024; int InitialSlabs = 1; int SubsequentSlabs = 1; BufferPool target = new BufferPool(SlabSize, InitialSlabs, SubsequentSlabs); long length = 20 * 1024; IBuffer actual; actual = target.GetBuffer(length); Assert.AreEqual(length, actual.Size); //Confirm that zero-length buffers work long length2 = 0; actual = target.GetBuffer(length2); Assert.AreEqual(length2, actual.Size); //Get another buffer and confirm that it is contiguous from the first acquired buffer. //i.e. the zero buffer "in-between" didn't cause any harm long length3 = 100 * 1024; actual = target.GetBuffer(length3); Assert.AreEqual(length3, actual.Size); Assert.IsTrue(actual.GetSegments()[0].Offset == length); }