示例#1
0
        public void CanUnlockExclusiveLock()
        {
            _lockTable = new LockTable(TimeSpan.FromSeconds(10), TimeSpan.FromMilliseconds(300));

            Assert.DoesNotThrow(() =>
            {
                var block = new Block(RandomFilename, 0);
                _lockTable.ExclusiveLock(block);
                _lockTable.Unlock(block);
            });
        }
示例#2
0
        public void CanWaitForExclusiveLockIfHaveExclusive()
        {
            _lockTable = new LockTable(TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(100));

            Assert.DoesNotThrow(() =>
            {
                var block = new Block(RandomFilename, 0);

                _lockTable.ExclusiveLock(block);

                Task.Run(async() =>
                {
                    await Task.Delay(500);
                    _lockTable.Unlock(block);
                });

                _lockTable.ExclusiveLock(block);
                _lockTable.Unlock(block);
            });
        }
示例#3
0
        public void CanHaveMultipleSharedLocks()
        {
            _lockTable = new LockTable(TimeSpan.FromSeconds(10), TimeSpan.FromMilliseconds(300));

            Assert.DoesNotThrow(() =>
            {
                var block = new Block(RandomFilename, 0);
                _lockTable.SharedLock(block);
                _lockTable.SharedLock(block);
                _lockTable.SharedLock(block);
                _lockTable.Unlock(block);
            });
        }
示例#4
0
        public void CannotWaitForExclusiveLockIfHaveExclusive()
        {
            _lockTable = new LockTable(TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(100));

            Assert.Throws <LockAbortException>(() =>
            {
                var block = new Block(RandomFilename, 0);

                _lockTable.ExclusiveLock(block);
                _lockTable.ExclusiveLock(block);
                _lockTable.Unlock(block);
            });
        }