public async Task TestForGettingReadLockInCaseWriteLocksExistBeforeRetryTimeOut_Success() { var key = new Random().Next().ToString(); var redisSettings = GetSettingsProvider(); var lockProvider = new RedisLockProvider(new RedisClientFactory(), redisSettings); var writeLockAcquireStatus = await lockProvider.TryGetLockAsync(key, LockType.Write, CancellationToken.None); Assert.True(writeLockAcquireStatus); var readLockAcquiresStatus = await lockProvider.TryGetLockAsync(key, LockType.Read, CancellationToken.None); Assert.True(readLockAcquiresStatus); }
public async Task TestRetryTimeOutExceptionForGettingWriteLockInCaseReadLocksExist_Failure() { var key = new Random().Next().ToString(); var settingsProvider = new Mock <ILockSettingsProvider>(); settingsProvider.Setup(x => x.GetSettings()).ReturnsAsync(new RedisLockSettings { Hosts = { "qa-redis.oski.tavisca.com:6379" }, QueueName = "QA-LoggingQueue", LockTimeOut = 20, RetryTimeOut = 10 }); var lockProvider = new RedisLockProvider(new RedisClientFactory(), settingsProvider.Object); var readLockAcquireStatus = await lockProvider.TryGetLockAsync(key, LockType.Read, CancellationToken.None); Assert.True(readLockAcquireStatus); var ex = await Assert.ThrowsAsync <RedisProviderException>(() => lockProvider.TryGetLockAsync(key, LockType.Write, CancellationToken.None)); Assert.NotNull(ex); Assert.Equal("Error occured in redis Provider", ex.Message); }
public async Task TestAcquireAndReleaseWriteLock_Success() { var key = new Random().Next().ToString(); var lockProvider = new RedisLockProvider(new RedisClientFactory(), GetSettingsProvider()); var lockAcquireStatus = await lockProvider.TryGetLockAsync(key, LockType.Write, CancellationToken.None); Assert.True(lockAcquireStatus); var value = GetKeyValue(key); Assert.NotNull(value); await lockProvider.ReleaseLockAsync(key, LockType.Write, CancellationToken.None); value = GetKeyValue(key); Assert.Null(value); }