public void BufferPoolConstructorTest3() { long SlabSize = -1; int InitialSlabs = 1; int SubsequentSlabs = 1; BufferPool target = new BufferPool(SlabSize, InitialSlabs, SubsequentSlabs); }
public void BufferPoolConstructorTest() { long SlabSize = 2 * 1024 * 1024; //2 MB int InitialSlabs = 1; int SubsequentSlabs = 1; BufferPool target = new BufferPool(SlabSize, InitialSlabs, SubsequentSlabs); Assert.AreEqual<long>(InitialSlabs, target.InitialSlabs); Assert.AreEqual<long>(SubsequentSlabs, target.SubsequentSlabs); Assert.AreEqual<long>(SlabSize, target.SlabSize); }
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 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 SlabSizeTest() { //Test for slab of minimum slab size long SlabSize = 1; //1 byte int InitialSlabs = 1; int SubsequentSlabs = 1; BufferPool target = new BufferPool(SlabSize, InitialSlabs, SubsequentSlabs); Assert.AreEqual<long>(Math.Max(SlabSize, BufferPool.MinimumSlabSize),target.SlabSize); //Test for slab of minimum slab size + 1 byte SlabSize = BufferPool.MinimumSlabSize + 1; InitialSlabs = 1; SubsequentSlabs = 1; target = new BufferPool(SlabSize, InitialSlabs, SubsequentSlabs); Assert.AreEqual<long>(Math.Max(SlabSize, BufferPool.MinimumSlabSize), target.SlabSize); }
public void InitialSlabsTest() { long SlabSize = 1024; //1 KB int InitialSlabs = 41; int SubsequentSlabs = 1; BufferPool target = new BufferPool(SlabSize, InitialSlabs, SubsequentSlabs); Assert.AreEqual<long>(InitialSlabs, target.InitialSlabs); }
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 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); }
/// <summary> /// Initializes a new instance of the MemorySlab class /// </summary> /// <param name="size">Size, in bytes, of slab</param> /// <param name="pool">BufferPool associated with the slab</param> internal MemorySlab(long size, BufferPool pool) { if (size < 1) { //Can't have zero length or -ve slabs throw new ArgumentOutOfRangeException("size"); } //NOTE: Pool parameter is allowed to be null for testing purposes if (System.IntPtr.Size > 4) { is64BitMachine = true; } else { is64BitMachine = false; } // lock is unnecessary in this instance constructor //lock (sync) //{ FreeSpace first; if (!dictStartLoc.TryGetValue(0, out first)) { AddFreeBlock(0, size, false); this.slabSize = size; this.pool = pool; // GC.Collect(); //Perform Garbage Collection before creating large array -- commented out but may be useful array = new byte[size]; } //} }