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); }); }
public void CanSetSharedLock() { _lockTable = new LockTable(TimeSpan.FromSeconds(10), TimeSpan.FromMilliseconds(300)); Assert.DoesNotThrow(() => { _lockTable.SharedLock(new Block(RandomFilename, 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); }); }
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); }); }
public void CanWaitForSharedLockIfHaveExclusive() { _lockTable = new LockTable(TimeSpan.FromSeconds(10), 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.SharedLock(block); _lockTable.Unlock(block); }); }