public void Rent_Rail_WithNegativeSize() { var pool = new SlabAllocatedArrayPool <CellPass>(DEFAULT_TEST_SLAB_ALLOCATED_POOL_SIZE); Action act = () => pool.Rent(-1); act.Should().Throw <ArgumentException>().WithMessage("Negative buffer size not permitted*"); }
public void Return_LargerThanAvailablePools() { var pool = new SlabAllocatedArrayPool <CellPass>(DEFAULT_TEST_SLAB_ALLOCATED_POOL_SIZE); var rental = pool.Rent(DEFAULT_TEST_SLAB_ALLOCATED_POOL_SIZE + 1); rental.Capacity.Should().Be(DEFAULT_TEST_SLAB_ALLOCATED_POOL_SIZE + 1); pool.Return(ref rental); }
public void Statistics_DefaultEmptyPool() { var pool = new SlabAllocatedArrayPool <CellPass>(DEFAULT_TEST_SLAB_ALLOCATED_POOL_SIZE); var stats = pool.Statistics(); stats.Should().NotBeNull(); stats.Length.Should().Be(VSS.TRex.IO.Utilities.Log2(DEFAULT_TEST_SLAB_ALLOCATED_POOL_SIZE)); stats.ForEach(x => x.RentedItems.Should().Be(0)); }
public void Return_AllPools() { var pool = new SlabAllocatedArrayPool <CellPass>(DEFAULT_TEST_SLAB_ALLOCATED_POOL_SIZE); for (int i = 0; i < DEFAULT_TEST_SLAB_ALLOCATED_POOL_SIZE; i++) { var rental = pool.Rent(i); pool.Return(ref rental); } }
public void Rent_LargerThanAvailablePools() { var pool = new SlabAllocatedArrayPool <CellPass>(DEFAULT_TEST_SLAB_ALLOCATED_POOL_SIZE); var rental = pool.Rent(DEFAULT_TEST_SLAB_ALLOCATED_POOL_SIZE + 1); rental.Capacity.Should().Be(DEFAULT_TEST_SLAB_ALLOCATED_POOL_SIZE + 1); rental.Count.Should().Be(0); rental.Elements.Should().NotBeNull(); rental.Offset.Should().Be(0); rental.OffsetPlusCount.Should().BeGreaterOrEqualTo(0); }
public void Rent_AllPools() { var pool = new SlabAllocatedArrayPool <CellPass>(DEFAULT_TEST_SLAB_ALLOCATED_POOL_SIZE); for (int i = 0; i < DEFAULT_TEST_SLAB_ALLOCATED_POOL_SIZE; i++) { var rental = pool.Rent(i); rental.Capacity.Should().BeGreaterOrEqualTo(i); rental.Count.Should().Be(0); rental.Elements.Should().NotBeNull(); rental.Offset.Should().BeGreaterOrEqualTo(0); rental.OffsetPlusCount.Should().BeGreaterOrEqualTo(0); pool.Return(ref rental); // Release rental so as not to pollute expected pool allocated status } }
public void Rent_FreeOfRentedElements() { var cache = new GenericTwoDArrayCache <Cell_NonStatic>(SubGridTreeConsts.SubGridTreeDimension, SubGridTreeConsts.SubGridTreeDimension, 10); var rental = cache.Rent(); cache.Should().NotBeNull(); var pool = new SlabAllocatedArrayPool <CellPass>(); // Rent and use all cells SubGridUtilities.SubGridDimensionalIterator((x, y) => { rental[x, y].Passes = pool.Rent(5); rental[x, y].Passes.Add(new CellPass()); }); // Give all the cells back SubGridUtilities.SubGridDimensionalIterator((x, y) => { pool.Return(ref rental[x, y].Passes); }); // the 2D array back cache.Return(ref rental); rental.Should().BeNull(); // Use the RentEx call to validate the content of the rental element being returned before being supplied to the calling context rental = cache.RentEx(r => SubGridUtilities.SubGridDimensionalIterator((x, y) => { r[x, y].Passes.IsRented.Should().BeFalse(); r[x, y].Passes.Count.Should().Be(0); })); rental.Should().NotBeNull(); }
public void Creation_DefaultNumPools() { var pool = new SlabAllocatedArrayPool <CellPass>(DEFAULT_TEST_SLAB_ALLOCATED_POOL_SIZE); pool.Should().NotBeNull(); }