public void TestThatSequenceLockedUnlockedAndLockedAgainIsSuccessfull() { var dlm = new RedLock(ConnectionMultiplexer.Connect("127.0.0.1:6379")); Lock lockObject; Lock newLockObject; var locked = dlm.Lock(resourceName, new TimeSpan(0, 0, 10), out lockObject); Assert.IsTrue(locked, "Unable to get lock"); dlm.Unlock(lockObject); locked = dlm.Lock(resourceName, new TimeSpan(0, 0, 10), out newLockObject); Assert.IsTrue(locked, "Unable to get lock"); dlm.Unlock(newLockObject); }
public void TestWhenLockedAnotherLockRequestIsRejected() { var dlm = new RedLock(ConnectionMultiplexer.Connect("127.0.0.1:6379"), ConnectionMultiplexer.Connect("127.0.0.1:6380"), ConnectionMultiplexer.Connect("127.0.0.1:6381")); Lock lockObject; Lock newLockObject; var locked = dlm.Lock(resourceName, new TimeSpan(0, 0, 10), out lockObject); Assert.IsTrue(locked, "Unable to get lock"); locked = dlm.Lock(resourceName, new TimeSpan(0, 0, 10), out newLockObject); Assert.IsFalse(locked, "lock taken, it shouldn't be possible"); dlm.Unlock(lockObject); }