Пример #1
0
        public void CanGetAnotherLockAfterDisposingLock()
        {
            var d = new SharedList <string>(LockingStrategy);
            ISharedCollectionLock l = d.GetReadLock();

            l.Dispose();

            l = d.GetReadLock();
            l.Dispose();
        }
Пример #2
0
        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");
        }
Пример #3
0
        public void DisposedWriteLockDeniesWrite()
        {
            var sharedList = new SharedList <string>(LockingStrategy);

            ISharedCollectionLock l = sharedList.GetWriteLock();

            l.Dispose();

            sharedList[0] = "foo";
        }
Пример #4
0
        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";
        }
Пример #7
0
        public void DisposedWriteLockDeniesWrite()
        {
            var d = new SharedDictionary <string, string>(this.LockingStrategy);

            ISharedCollectionLock l = d.GetWriteLock();

            l.Dispose();

            Assert.Throws <WriteLockRequiredException>(() => d["ke"] = "foo");
        }
Пример #8
0
        public void DisposedWriteLockDeniesRead()
        {
            var d = new SharedDictionary <string, string>(this.LockingStrategy);

            ISharedCollectionLock l = d.GetWriteLock();

            l.Dispose();

            Assert.Throws <ReadLockRequiredException>(() => d.ContainsKey("foo"));
        }
Пример #9
0
        public void DisposedWriteLockDeniesWrite()
        {
            var sharedList = new SharedList <string>(this.LockingStrategy);

            ISharedCollectionLock l = sharedList.GetWriteLock();

            l.Dispose();

            Assert.Throws <WriteLockRequiredException>(() => sharedList[0] = "foo");
        }
Пример #10
0
            protected virtual void Dispose(bool disposing)
            {
                if (!_isDisposed)
                {
                    if (disposing)
                    {
                        //dispose managed resrources here
                        _enumerator.Dispose();
                        _readLock.Dispose();
                    }

                    //dispose unmanaged resrources here
                    _isDisposed = true;
                }
            }