コード例 #1
0
        public void ConstructorThrowsLockRecursionExceptionWhenLockIsNotUpdatableTest()
        {
            var _lock = new ReaderWriterLockSlim();
            var _readerLock = new ReaderLock(_lock);

            Assert.Throws<System.Threading.LockRecursionException>(() => new WriterLock(_readerLock));
            Assert.IsNotNull(_lock);
        }
コード例 #2
0
        public void ConstructorInitializesLockTest()
        {
            var _lock = new ReaderWriterLockSlim();
            using (var _readerLock = new ReaderLock(_lock))
            {
                Assert.AreEqual(_lock, _readerLock.Lock);
            }

            Assert.IsNotNull(_lock);
        }
コード例 #3
0
        public void ConstructorInitializesIsUpgradableTest()
        {
            const bool IS_UPGRADABLE = true;

            var _lock = new ReaderWriterLockSlim();
            using (var _readerLock = new ReaderLock(_lock, -1, IS_UPGRADABLE))
            {
                Assert.AreEqual(IS_UPGRADABLE, _readerLock.IsUpgradable);
            }
        }
コード例 #4
0
        public void ConstructorInitializesTimeoutTest()
        {
            const int TIMEOUT = 100;

            var _lock = new ReaderWriterLockSlim();
            using (var _readerLock = new ReaderLock(_lock, TIMEOUT))
            {
                Assert.AreEqual(TIMEOUT, _readerLock.Timeout);
            }

            Assert.IsNotNull(_lock);
        }
コード例 #5
0
        public void ConstructorAquiresLockWhenIsUpgradableTest()
        {
            var _lock = new ReaderWriterLockSlim();

            using (var _readerLock = new ReaderLock(_lock, -1, true))
            {
                Assert.AreEqual(_lock, _readerLock.Lock);
                Assert.IsTrue(_readerLock.Lock.IsUpgradeableReadLockHeld);
            }

            Assert.IsNotNull(_lock);
            Assert.IsFalse(_lock.IsUpgradeableReadLockHeld);
        }
コード例 #6
0
ファイル: WriterLock.cs プロジェクト: ikyaqoob/RabbitCache
 public WriterLock(ReaderLock _readerLock)
     : base(_readerLock.Lock, _readerLock.Timeout)
 {
     if (!this.Lock.IsUpgradeableReadLockHeld)
         throw new InvalidOperationException("!this.Lock.IsUpgradeableReadLockHeld");
 }
コード例 #7
0
        public void DisposeReleasesLockWhenIsUpgradableTest()
        {
            var _lock = new ReaderWriterLockSlim();

            using (var _readerLock = new ReaderLock(_lock))
            {
                Assert.AreEqual(_lock, _readerLock.Lock);
            }

            Assert.IsNotNull(_lock);
            Assert.IsFalse(_lock.IsUpgradeableReadLockHeld);
        }