public void Rent_LargerThanLargestBufferPool() { var cache = new GenericArrayPoolCaches <byte>(); var item = cache.Rent(2000000); item.Length.Should().Be(2000000); }
public void Rent_Fail_WithNegativeSize() { var cache = new GenericArrayPoolCaches <byte>(); Action act = () => cache.Rent(-1); act.Should().Throw <ArgumentException>().WithMessage("Negative buffer size not permitted*"); }
public void Rent_ZeroBuffer() { var cache = new GenericArrayPoolCaches <byte>(); var item = cache.Rent(0); item.Length.Should().Be(0); }
public void Rent_Success_ExponentialSizes_WithReturn(int minSize) { var cache = new GenericArrayPoolCaches <byte>(); var item = cache.Rent(minSize); // The item rented is perfect power of two size so the size of the buffer should be exactly min size item.Length.Should().Be(minSize); cache.Return(ref item); item.Should().BeNull(); if (minSize > 2) { var item2 = cache.Rent(minSize - 1); // The item rented is one less than perfect power of two size so the size of the buffer should be exactly min size item2.Length.Should().Be(minSize); cache.Return(ref item2); item2.Should().BeNull(); var item3 = cache.Rent(minSize + 1); // The item rented is one less than perfect power of two size so the size of the buffer should be exactly twice min size item3.Length.Should().Be(minSize + 1 > GenericArrayPoolCaches <byte> .MAX_BUFFER_SIZE_CACHED ? minSize + 1 : 2 * minSize); cache.Return(ref item3); item3.Should().BeNull(); } }
public void Return_Fail_InvalidBufferSize() { var cache = new GenericArrayPoolCaches <byte>(); // This should not throw an exception but may record an item in the log var b = new byte[7]; cache.Return(ref b); }
public void Return_Fail_BufferTooLarge() { var cache = new GenericArrayPoolCaches <byte>(); var b = new byte[1 << 21]; // This should not throw an exception but may record an item in the log cache.Return(ref b); }
public void GlobalSetup() { _arrayPool = ArrayPool <byte> .Shared; DIBuilder.New().AddLogging() .Add(x => x.AddSingleton <IGenericArrayPoolCaches <byte> >(new GenericArrayPoolCaches <byte>())).Build() .Complete(); _genericArrayPoolIntf = GenericArrayPoolCacheHelper <byte> .Caches(); _genericArrayPoolObj = GenericArrayPoolCacheHelper <byte> .Caches() as GenericArrayPoolCaches <byte>; }
public void Return_Fail_PoolCacheIsFull() { var cache = new GenericArrayPoolCaches <byte>(); // Fill a small pool with returned elements of the correct size for (int i = 0; i < GenericArrayPoolCaches <byte> .DEFAULT_POOL_CACHE_SIZES[3]; i++) { var b = new byte[8]; cache.Return(ref b); } // Return an additional element. This should not throw an exception but may // record an item in the log var b2 = new byte[8]; cache.Return(ref b2); }
public void Creation() { var cache = new GenericArrayPoolCaches <byte>(); cache.Should().NotBeNull(); }