Ejemplo n.º 1
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);
            });
        }
Ejemplo n.º 2
0
        public void CanSetExclusiveLock()
        {
            _lockTable = new LockTable(TimeSpan.FromSeconds(10), TimeSpan.FromMilliseconds(300));

            Assert.DoesNotThrow(() =>
            {
                var block = new Block(RandomFilename, 0);
                _lockTable.ExclusiveLock(block);
            });
        }
Ejemplo n.º 3
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);
            });
        }
Ejemplo n.º 4
0
        public void ThrowsExceptionIfSharedLockWasNotReceivedBecauseAlreadHadExclusive()
        {
            _lockTable = new LockTable(TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(100));

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

                _lockTable.ExclusiveLock(block);
                _lockTable.SharedLock(block);
            });
        }
Ejemplo n.º 5
0
        public void NotThrowsExceptionIfExclusiveLockWasNotReceivedBecauseAlreadHadShared()
        {
            _lockTable = new LockTable(TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(100));

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

                // The only way to receive a exclusive lock is only after contesting an shared lock
                _lockTable.SharedLock(block);
                _lockTable.ExclusiveLock(block);
            });
        }