public void BoundedObjectPoolDoesNotExceedMaxSizeForMultiThreadedCallsWithBlockingOperations() { double?[] values = new double?[10000]; Func <TestPoolObject> objGenerator = () => new TestPoolObject(); var pool = new BoundedObjectPool <TestPoolObject>(objGenerator, 5, 10); var loopResult = Parallel.For(0, 10000, i => { var item = pool.GetObject(); values[i] = item.GetValue(i); //simulate a blocking operation if (i % 1000 == 0) { Thread.Sleep(100); } pool.ReturnObjectToPool(item); }); while (!loopResult.IsCompleted || pool.PoolCount > 10) { Thread.Sleep(10); } Assert.IsTrue(pool.PoolCount <= 10); }
public void BoundedObjectPoolGetsObjectFromPool() { Func <TestPoolObject> objGenerator = () => new TestPoolObject(); var pool = new BoundedObjectPool <TestPoolObject>(objGenerator, 5, 10); var item = pool.GetObject(); Assert.IsNotNull(item); }
public void BoundedObjectPoolResetsObjectStateWhenReturningObjectToPool() { Func <TestPoolObject> objGenerator = () => new TestPoolObject(); var pool = new BoundedObjectPool <TestPoolObject>(objGenerator, 5, 10); var item = pool.GetObject(); pool.ReturnObjectToPool(item); Assert.IsTrue(item.StateReset); }
public void BoundedObjectPoolReturnObjectToPoolDoesNotExceedMaxSize() { Func <TestPoolObject> objGenerator = () => new TestPoolObject(); var pool = new BoundedObjectPool <TestPoolObject>(objGenerator, 5, 10); var item = pool.GetObject(); pool.ReturnObjectToPool(item); Assert.IsTrue(pool.PoolCount <= 10); }
public void BoundedObjectPoolGetsObjectFromPoolMultiThreaded() { double?[] values = new double?[10000]; Func <TestPoolObject> objGenerator = () => new TestPoolObject(); var pool = new BoundedObjectPool <TestPoolObject>(objGenerator, 5, 10); Parallel.For(0, 10000, i => { var item = pool.GetObject(); values[i] = item.GetValue(i); pool.ReturnObjectToPool(item); }); Assert.IsTrue(values.All(i => i.HasValue)); }
public void BoundedObjectPoolGetsObjectFromPoolMultiThreadedWithBlockingOperations() { double?[] values = new double?[10000]; Func <TestPoolObject> objGenerator = () => new TestPoolObject(); var pool = new BoundedObjectPool <TestPoolObject>(objGenerator, 5, 10); Parallel.For(0, 10000, i => { var item = pool.GetObject(); values[i] = item.GetValue(i); //simulate a blocking operation if (i % 1000 == 0) { Thread.Sleep(100); } pool.ReturnObjectToPool(item); }); Assert.IsTrue(values.All(i => i.HasValue)); }