public void CanGetAnotherLockAfterDisposingLock() { var d = new SharedList <string>(LockingStrategy); ISharedCollectionLock l = d.GetReadLock(); l.Dispose(); l = d.GetReadLock(); l.Dispose(); }
public void TwoDictsShareALockWriteTest() { var lockStrategy = LockingStrategyFactory.Create(this.LockingStrategy); var dict1 = new SharedDictionary <string, string>(lockStrategy); var dict2 = new SharedDictionary <string, string>(lockStrategy); using (dict1.GetReadLock()) { ISharedCollectionLock writeLock = null; try { writeLock = dict2.GetWriteLock(); } catch (LockRecursionException) { Assert.Pass(); } catch (Exception exception) { Assert.Fail("Expected LockRecursionException, got {0}", exception); } finally { writeLock?.Dispose(); } } Assert.Fail("Expected LockRecursionException, did not throw"); }
public void DisposedWriteLockDeniesWrite() { var sharedList = new SharedList <string>(LockingStrategy); ISharedCollectionLock l = sharedList.GetWriteLock(); l.Dispose(); sharedList[0] = "foo"; }
public void DisposedWriteLockDeniesRead() { var d = new SharedList <string>(LockingStrategy); ISharedCollectionLock l = d.GetWriteLock(); l.Dispose(); d.Contains("foo"); }
public void DisposedReadLockDeniesRead() { var d = new SharedDictionary <string, string>(LockingStrategy); ISharedCollectionLock l = d.GetReadLock(); l.Dispose(); d.ContainsKey("foo"); }
public void DisposedWriteLockDeniesWrite() { var d = new SharedDictionary <string, string>(LockingStrategy); ISharedCollectionLock l = d.GetWriteLock(); l.Dispose(); d["ke"] = "foo"; }
public void DisposedWriteLockDeniesWrite() { var d = new SharedDictionary <string, string>(this.LockingStrategy); ISharedCollectionLock l = d.GetWriteLock(); l.Dispose(); Assert.Throws <WriteLockRequiredException>(() => d["ke"] = "foo"); }
public void DisposedWriteLockDeniesRead() { var d = new SharedDictionary <string, string>(this.LockingStrategy); ISharedCollectionLock l = d.GetWriteLock(); l.Dispose(); Assert.Throws <ReadLockRequiredException>(() => d.ContainsKey("foo")); }
public void DisposedWriteLockDeniesWrite() { var sharedList = new SharedList <string>(this.LockingStrategy); ISharedCollectionLock l = sharedList.GetWriteLock(); l.Dispose(); Assert.Throws <WriteLockRequiredException>(() => sharedList[0] = "foo"); }
protected virtual void Dispose(bool disposing) { if (!_isDisposed) { if (disposing) { //dispose managed resrources here _enumerator.Dispose(); _readLock.Dispose(); } //dispose unmanaged resrources here _isDisposed = true; } }