public async Task ToStringSubClassAsync() { var lockBase = new LockBase(); _col.Add(lockBase); var dataStore = new SharpLockInMemoryStringIdDataStore <LockBase, InnerLock>(_col, _logger, TimeSpan.FromSeconds(30)); var lck = new DistributedLock <LockBase, InnerLock, string>(dataStore, x => x.SingularInnerLock); Assert.IsNotNull(await lck.AcquireLockAsync(lockBase, lockBase.SingularInnerLock), "Failed to acquire lock."); Assert.IsTrue(lck.LockAcquired, "Lock should be acquired but it doesn't appear to be."); Assert.AreEqual(lck.ToString(), $"LockId: {lck.LockedObjectLockId}, Locked ObjectId: {lck.LockedObjectId}."); Assert.IsTrue(await lck.ReleaseLockAsync(), "await lck.ReleaseLockAsync()"); Assert.AreEqual(lck.ToString(), "No lock acquired."); await lck.DisposeAsync().ConfigureAwait(false); Assert.IsTrue(lck.Disposed, "Failed to mark object as disposed"); }
public async Task AcquireOneListSubClassAndGetLockedObjectAsync() { var lockBase = new LockBase(); await _col.InsertOneAsync(lockBase); var dataStore = new SharpLockMongoDataStore <LockBase, InnerLock>(_col, _logger, TimeSpan.FromSeconds(30)); var lck = new DistributedLock <LockBase, InnerLock, ObjectId>(dataStore, x => x.ListOfLockables); Assert.IsNotNull(await lck.AcquireLockAsync(lockBase, lockBase.ListOfLockables.First()), "Failed to acquire lock."); Assert.IsTrue(lck.LockAcquired, "Lock should be acquired but it doesn't appear to be."); Assert.IsNotNull(await lck.GetObjectAsync(), "Failed to get a copy of the locked object."); Assert.IsTrue(await lck.RefreshLockAsync(), "Failed to refresh lock."); Assert.IsTrue(await lck.ReleaseLockAsync(), "Failed to release lock."); await lck.DisposeAsync().ConfigureAwait(false); Assert.IsTrue(lck.Disposed, "Failed to mark object as disposed"); }
public async Task AcquireOneBaseClassAsync() { var lockBase = new LockBase(); _col.Add(lockBase); var dataStore = new SharpLockInMemoryStringIdDataStore <LockBase>(_col, _logger, TimeSpan.FromSeconds(30)); var lck = new DistributedLock <LockBase, string>(dataStore); Assert.IsTrue(await lck.AcquireLockAsync(lockBase) != null, "Failed to acquire lock."); Assert.IsTrue(lockBase.Id == lck.LockedObjectId, "Locked Object is not the expected object."); Assert.IsTrue(lck.LockAcquired, "Lock should be acquired but it doesn't appear to be."); Assert.IsTrue(await lck.RefreshLockAsync(), "Failed to refresh lock."); Assert.IsTrue(await lck.ReleaseLockAsync(), "Failed to release lock."); await lck.DisposeAsync().ConfigureAwait(false); Assert.IsTrue(lck.Disposed, "Failed to mark object as disposed"); }
public async Task AcquireOneSingularSubClassAndGetLockedObjectAsync() { var lockBase = new LockBase(); _col.Add(lockBase); var dataStore = new SharpLockInMemoryStringIdDataStore <LockBase, InnerLock>(_col, _logger, TimeSpan.FromSeconds(30)); var lck = new DistributedLock <LockBase, InnerLock, string>(dataStore, x => x.SingularInnerLock); Assert.IsNotNull(await lck.AcquireLockAsync(lockBase, lockBase.SingularInnerLock), "Failed to acquire lock."); Assert.IsTrue(lck.LockAcquired, "Lock should be acquired but it doesn't appear to be."); Assert.IsNotNull(await lck.GetObjectAsync(), "Failed to get a copy of the locked object."); Assert.IsTrue(await lck.RefreshLockAsync(), "Failed to refresh lock."); Assert.IsTrue(await lck.ReleaseLockAsync(), "Failed to release lock."); await lck.DisposeAsync().ConfigureAwait(false); Assert.IsTrue(lck.Disposed, "Failed to mark object as disposed"); }
public async Task RefreshAlreadyReleasedSubClassAsync() { var lockBase = new LockBase(); await _col.InsertOneAsync(lockBase); var dataStore = new SharpLockMongoDataStore <LockBase, InnerLock>(_col, _sharpLockLogger, TimeSpan.FromSeconds(30)); var lck = new DistributedLock <LockBase, InnerLock, ObjectId>(dataStore, x => x.SingularInnerLock); Assert.IsNotNull(await lck.AcquireLockAsync(lockBase, lockBase.SingularInnerLock), "Failed to acquire lock."); Assert.IsTrue(lck.LockAcquired, "Lock should be acquired but it doesn't appear to be."); Assert.IsTrue(await lck.ReleaseLockAsync(), "await lck.ReleaseLockAsync()"); Assert.IsFalse(await lck.RefreshLockAsync(), "await lck.RefreshLockAsync()"); await Assert.ThrowsExceptionAsync <RefreshDistributedLockException>(async() => await lck.RefreshLockAsync(true), "async () => await lck.RefreshLockAsync()"); Assert.AreEqual(lck.ToString(), "No lock acquired."); lck.Dispose(); Assert.IsTrue(lck.Disposed, "Failed to mark object as disposed"); }
public async Task AcquireOneBaseClassAndGetLockedObjectAsync() { var lockBase = new LockBase(); await _col.InsertOneAsync(lockBase); var dataStore = new SharpLockMongoDataStore <LockBase>(_col, _sharpLockLogger, TimeSpan.FromSeconds(30)); var lck = new DistributedLock <LockBase, ObjectId>(dataStore); Assert.IsTrue(await lck.AcquireLockAsync(lockBase) != null, "Failed to acquire lock."); Assert.IsTrue(lockBase.Id == lck.LockedObjectId, "Locked Object is not the expected object."); Assert.IsTrue(lck.LockAcquired, "Lock should be acquired but it doesn't appear to be."); Assert.IsNotNull(await lck.GetObjectAsync(), "Failed to get a copy of the locked object."); Assert.IsTrue(await lck.RefreshLockAsync(), "Failed to refresh lock."); Assert.IsTrue(await lck.ReleaseLockAsync(), "Failed to release lock."); lck.Dispose(); Assert.IsTrue(lck.Disposed, "Failed to mark object as disposed"); }
public async Task RefreshAlreadyReleasedBaseClassAsync() { var lockBase = new LockBase(); _col.Add(lockBase); var dataStore = new SharpLockInMemoryStringIdDataStore <LockBase>(_col, _logger, TimeSpan.FromSeconds(30)); var lck = new DistributedLock <LockBase, string>(dataStore); Assert.IsNotNull(await lck.AcquireLockAsync(lockBase), "Failed to acquire lock."); Assert.IsTrue(lck.LockAcquired, "Lock should be acquired but it doesn't appear to be."); Assert.IsTrue(await lck.ReleaseLockAsync(), "await lck.ReleaseLockAsync()"); Assert.IsFalse(await lck.RefreshLockAsync(), "await lck.RefreshLockAsync()"); await Assert.ThrowsExceptionAsync <RefreshDistributedLockException>(async() => await lck.RefreshLockAsync(true), "async () => await lck.RefreshLockAsync()"); Assert.AreEqual(lck.ToString(), "No lock acquired."); await lck.DisposeAsync().ConfigureAwait(false); Assert.IsTrue(lck.Disposed, "Failed to mark object as disposed"); }