public void TryAdd() { const string value = "value"; var sharedList = new SharedList <string>(LockingStrategy); bool doInsert = false; using (ISharedCollectionLock l = sharedList.GetReadLock()) { if (!sharedList.Contains(value)) { doInsert = true; } } if (doInsert) { using (ISharedCollectionLock l = sharedList.GetWriteLock()) { if (!sharedList.Contains(value)) { sharedList.Add(value); } } } CollectionAssert.AreEqual(new List <string> { value }, sharedList.BackingList); }
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 DisposedWriteLockDeniesWrite() { var sharedList = new SharedList <string>(this.LockingStrategy); ISharedCollectionLock l = sharedList.GetWriteLock(); l.Dispose(); Assert.Throws <WriteLockRequiredException>(() => sharedList[0] = "foo"); }
public void DisposedWriteLockDeniesRead() { var d = new SharedList <string>(this.LockingStrategy); ISharedCollectionLock l = d.GetWriteLock(); l.Dispose(); Assert.Throws <ReadLockRequiredException>(() => d.Contains("foo")); }
public void TwoDictsShareALockWriteTest() { ILockStrategy ls = new ReaderWriterLockStrategy(); var d1 = new SharedList <string>(ls); var d2 = new SharedList <string>(ls); using (ISharedCollectionLock readLock = d1.GetReadLock()) { using (ISharedCollectionLock writeLock = d2.GetWriteLock()) { //do nothing } } }
public void TwoDictsShareALockWriteTest() { ILockStrategy ls = new ReaderWriterLockStrategy(); var d1 = new SharedList <string>(ls); var d2 = new SharedList <string>(ls); using (ISharedCollectionLock readLock = d1.GetReadLock()) { Assert.Throws <LockRecursionException>( () => { using (ISharedCollectionLock writeLock = d2.GetWriteLock()) { // do nothing } }); } }