本文整理汇总了C#中Pool.ReleasePooledValue方法的典型用法代码示例。如果您正苦于以下问题:C# Pool.ReleasePooledValue方法的具体用法?C# Pool.ReleasePooledValue怎么用?C# Pool.ReleasePooledValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pool
的用法示例。
在下文中一共展示了Pool.ReleasePooledValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AcquiredInstancesCanBeReturnedToOwningPoolTest
public async Task AcquiredInstancesCanBeReturnedToOwningPoolTest(int poolSize)
{
// given
var pool = new Pool<string>((token) => Guid.NewGuid().ToString(), poolSize);
var acquiredPooledItem = await pool.AcquirePooledValueAsync();
// when
Action returningToPoolAction = () => pool.ReleasePooledValue(acquiredPooledItem);
Action accessingPoolValueAfterReturningToPoolAction = () => { var pooledValue = acquiredPooledItem.Value; };
// then
// prior to returning poolsize should be down by one
pool.AvailableInstancesCount.Should().Be(poolSize -1);
returningToPoolAction.ShouldNotThrow();
// after returning poolsize should be back to expected size
pool.AvailableInstancesCount.Should().Be(poolSize);
acquiredPooledItem.HasBeenReleasedBackToPool.Should().Be(true);
acquiredPooledItem.HasBeenDetachedFromPool.Should().Be(false);
accessingPoolValueAfterReturningToPoolAction.ShouldThrow<InvalidOperationException>();
}
示例2: AcquiredInstancesCannotBeReturnedToDifferentPoolTest
public async Task AcquiredInstancesCannotBeReturnedToDifferentPoolTest()
{
// given
var owningPool = new Pool<string>((token) => Guid.NewGuid().ToString(), 1);
var secondPool = new Pool<string>((token) => Guid.NewGuid().ToString());
var acquiredPooledItem = await owningPool.AcquirePooledValueAsync();
// when
Action returningToPoolAction = () => secondPool.ReleasePooledValue(acquiredPooledItem);
Action accessingPoolValueAfterReturningToDifferentPoolAction = () => { var pooledValue = acquiredPooledItem.Value; };
// then
returningToPoolAction.ShouldThrow<ArgumentOutOfRangeException>().And.ParamName.Should().Be("pooledValue");
owningPool.AvailableInstancesCount.Should().Be(0);
acquiredPooledItem.HasBeenReleasedBackToPool.Should().Be(false);
acquiredPooledItem.HasBeenDetachedFromPool.Should().Be(false);
accessingPoolValueAfterReturningToDifferentPoolAction.ShouldNotThrow<InvalidOperationException>();
}
示例3: AcquiredInstancesCannotBeReturnedMultipleTimesTest
public async Task AcquiredInstancesCannotBeReturnedMultipleTimesTest()
{
// given
var pool = new Pool<string>((token) => Guid.NewGuid().ToString(), 1);
var acquiredPooledItem = await pool.AcquirePooledValueAsync();
// when
Action returningToPoolAction = () => pool.ReleasePooledValue(acquiredPooledItem);
// then
// prior to returning poolsize should be down by one
returningToPoolAction.ShouldNotThrow();
// however a second (or more) time(s) should not be allowed
returningToPoolAction.ShouldThrow<ArgumentOutOfRangeException>();
}