/// <inheritdoc/> public void RemoveLock(IIxInstanceLock instanceLock) { if (instanceLock == null) { throw new ArgumentNullException(nameof(instanceLock)); } EnsureTreeLocked(); if (ReferenceEquals(instanceLock, _initTempLock)) { Critical.Assert( _objectCreationTask != null, "You need to setup instance object factory before releasing creator lock."); Critical.Assert( _objectCreationTask.Value.IsCompleted, "Creator lock should be removed only after object instantiation completes."); _initTempLock = null; } // --------- We are under tree lock -------------- if (!_locks.Remove(instanceLock)) { Critical.Assert(false, "Lock was not registered in the target or already removed."); } UpdateDisposeSuspendState(); UpdateChildrenDisposeCompleteSuspendState(); }
public void StressTest() { List <Dummy> originalList = Enumerable.Range(0, 10000).Select(x => new Dummy()).ToList(); var rnd = new Random(0); var checkHashSet = new HashSet <Dummy>( rnd.RandomUniqueSet(0, originalList.Count, originalList.Count / 2).Select(x => originalList[x])); var setToTest = new ProcessableSet <Dummy>(); foreach (Dummy dummy in checkHashSet) { setToTest.Add(dummy); } setToTest.ForEach( x => { if (rnd.NextDouble() < 0.3) { int itemIndex = rnd.Next(0, originalList.Count); Dummy testItem = originalList[itemIndex]; bool goodResult; bool testResult; if (rnd.NextBool()) { goodResult = checkHashSet.Add(testItem); testResult = setToTest.Add(testItem); testResult.Should().Be(goodResult, "Add operation wrong."); } else { goodResult = checkHashSet.Remove(testItem); testResult = setToTest.Remove(testItem); testResult.Should().Be(goodResult, "Remove operation wrong."); if (testResult) { // Forgetting that processed, if it was removed. testItem.ProcessedCount = 0; } } } x.ProcessedCount++; }); foreach (Dummy dummy in setToTest) { dummy.ProcessedCount.Should().Be(1, "Some element processed more than once."); } setToTest.Count.Should().Be(checkHashSet.Count); foreach (Dummy dummy in checkHashSet) { setToTest.Should().Contain(dummy); } }
/// <inheritdoc/> public void RemoveOwnedLock(IIxInstanceLock instanceLock) { if (instanceLock == null) { throw new ArgumentNullException(nameof(instanceLock)); } EnsureTreeLocked(); // --------- We are under tree lock -------------- if (!_ownedLocks.Remove(instanceLock)) { Critical.Assert(false, "Owned lock was not registered in the owner or already removed."); } }