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); }); }
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 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 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); }); }