private static void UseObjectsInPool(GitIndexProjection.ObjectPool <object> pool, int count) { for (int i = 0; i < count; i++) { pool.GetNew().ShouldNotBeNull(); } }
private static GitIndexProjection.ObjectPool <object> CreateExpandedPool() { GitIndexProjection.ObjectPool <object> pool = new GitIndexProjection.ObjectPool <object>(new MockTracer(), AllocationSize, objectCreator: () => new object()); UseObjectsInPool(pool, DefaultObjectsToUse); pool.Size.ShouldEqual(PoolSizeAfterUsingDefault); return(pool); }
public void ShrinkKeepsUsedObjectsPlusPercent() { GitIndexProjection.ObjectPool <object> pool = new GitIndexProjection.ObjectPool <object>(new MockTracer(), AllocationSize, objectCreator: () => new object()); UseObjectsInPool(pool, 20); pool.Size.ShouldEqual(AllocationSize); pool.Shrink(); pool.Size.ShouldEqual(Convert.ToInt32(20 * 1.1)); }
public void FreeToZeroAllocatesMinimumSizeNextGet() { GitIndexProjection.ObjectPool <object> pool = new GitIndexProjection.ObjectPool <object>(new MockTracer(), AllocationSize, objectCreator: () => new object()); pool.FreeAll(); pool.Shrink(); pool.Size.ShouldEqual(0); UseObjectsInPool(pool, 1); pool.Size.ShouldEqual(AllocationSize); }
public void FreeKeepsPoolSize() { GitIndexProjection.ObjectPool <object> pool = CreateExpandedPool(); pool.FreeAll(); pool.Size.ShouldEqual(DefaultShrinkSize); UseObjectsInPool(pool, DefaultObjectsToUse); UseObjectsInPool(pool, 15); pool.Size.ShouldEqual(PoolSizeAfterExpandingAfterShrinking); pool.FreeAll(); pool.Size.ShouldEqual(PoolSizeAfterExpandingAfterShrinking); }