public void Renting_too_many_just_allocates() { const int middleSize = (ArrayPoolLimit + LargeBufferSize) / 2; const int size = 1; const int additional = 2; LargerArrayPool pool = new LargerArrayPool(ArrayPoolLimit, LargeBufferSize, size, _thrower); HashSet <byte[]> arrays = new HashSet <byte[]>(); // rent first size + additional for (int i = 0; i < size + additional; i++) { arrays.Add(pool.Rent(middleSize)); } // return all foreach (byte[] bytes in arrays) { pool.Return(bytes); } // try to train it all while (arrays.Remove(pool.Rent(middleSize))) { } Assert.AreEqual(additional, arrays.Count); }
public void Renting_bigger_uses_Larger_Pool() { const int middleSize = (ArrayPoolLimit + LargeBufferSize) / 2; LargerArrayPool pool = new LargerArrayPool(ArrayPoolLimit, LargeBufferSize, 1, _thrower); byte[] array1 = pool.Rent(middleSize); pool.Return(array1); byte[] array2 = pool.Rent(middleSize); Assert.True(ReferenceEquals(array1, array2)); }
public void Renting_above_Large_Buffer_Size_just_allocates() { const int tooBig = LargeBufferSize + 1; LargerArrayPool pool = new LargerArrayPool(ArrayPoolLimit, LargeBufferSize, 1, _thrower); byte[] array1 = pool.Rent(tooBig); pool.Return(array1); byte[] array2 = pool.Rent(tooBig); Assert.False(ReferenceEquals(array1, array2)); }
public void Renting_small_goes_to_Small_Buffer_Pool() { LargerArrayPool pool = new LargerArrayPool(ArrayPoolLimit, LargeBufferSize, 1, s_shared); byte[] array = pool.Rent(ArrayPoolLimit); try { Assert.AreEqual(s_shared._bytes, array); } finally { pool.Return(array); } }