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); }); }
public void CanSetExclusiveLock() { _lockTable = new LockTable(TimeSpan.FromSeconds(10), TimeSpan.FromMilliseconds(300)); Assert.DoesNotThrow(() => { var block = new Block(RandomFilename, 0); _lockTable.ExclusiveLock(block); }); }
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); }); }
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); }); }
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); }); }