public async Task TestThatStorageExceptionsAreRetried() { string appId = "appId"; var flushAndReleaseSequence = StubsUtils.Sequence <Func <Task> >() .Once(() => AsyncUtils.AsyncTaskThatThrows(new StorageException())) .Once(() => Task.CompletedTask) .Once(() => AsyncUtils.AsyncTaskThatThrows(new StorageException())) .Once(() => Task.CompletedTask); IUpdateBlob updateBlobStub = new StubIUpdateBlob() .FlushAndRelease(() => flushAndReleaseSequence.Next()) .Dispose(() => { }) .GetUpdateDomain(() => "1") .SetUpdateDomain(domain => { }) .AddInstance(id => { }) .RemoveInstance(id => { }); var updateBlobFactoryStub = new StubIUpdateBlobFactory() .TryLockUpdateBlob(id => AsyncUtils.AsyncTaskWithResult(updateBlobStub)); ContainerBuilder builder = AzureBlobStorageUpdateSessionDiModule.RegisterTypes("clusterId", "instanceId", "1", EmulatorConnectionString); builder.RegisterInstance(updateBlobFactoryStub).As <IUpdateBlobFactory>(); IUpdateSessionManager updateSessionManager = new AzureBlobStorageUpdateSessionDiModule(builder.Build()).UpdateSessionManager; Assert.True(await updateSessionManager.TryStartUpdateSession(appId)); await updateSessionManager.EndUpdateSession(appId); Assert.Equal(4, flushAndReleaseSequence.CallCount); }
public async Task TestThatLockFailsIfBlobLeaseReturnsNull() { var blobLeaseStub = new StubIBlobLease { TryAcquireLease = () => AsyncUtils.AsyncTaskWithResult<string>(null), IDisposable_Dispose = () => { } }; await TestThatLockFailsIfBlobLeaseCantBeAcquired(blobLeaseStub); }
public async Task TestThatExceptionIsThrownIfMaxRetryCountIsReached() { var sequence = StubsUtils.Sequence <StubIUpdateSessionManager.TryStartUpdateSession_Delegate>() .Twice(() => AsyncUtils.AsyncTaskThatThrows <bool>(new StorageException())) .Once(() => AsyncUtils.AsyncTaskWithResult(true)); var updateSessionStub = new StubIUpdateSessionManager() .TryStartUpdateSession(() => sequence.Next()); IUpdateSessionManager retryDecorator = new StorageExceptionUpdateSessionRetryDecorator( updateSessionStub, new FixedInterval(1, TimeSpan.Zero), new StorageExceptionErrorDetectionStrategy()); await Assert.ThrowsAsync <StorageException>(async() => await retryDecorator.TryStartUpdateSession()); }
public async Task TestThatExceptionIsThrownIfMaxRetryCountIsReached() { string appId = "appId"; IUpdateBlob updateBlob = new StubIUpdateBlob(); var sequence = StubsUtils.Sequence <StubIUpdateBlobFactory.TryLockUpdateBlob_String_Delegate>() .Twice(id => AsyncUtils.AsyncTaskThatThrows <IUpdateBlob>(new UpdateBlobUnavailableException())) .Once(id => AsyncUtils.AsyncTaskWithResult(updateBlob)); var updateBlobFactoryStub = new StubIUpdateBlobFactory() .TryLockUpdateBlob(id => sequence.Next(appId)); UpdateBlobFactoryRetryLockDecorator retryDecorator = new UpdateBlobFactoryRetryLockDecorator(updateBlobFactoryStub, new FixedInterval(1, TimeSpan.Zero)); await Assert.ThrowsAsync <UpdateBlobUnavailableException>( async() => await retryDecorator.TryLockUpdateBlob(appId)); }
public async Task TestSuccessfullRetry() { string appId = "appId"; IUpdateBlob updateBlob = new StubIUpdateBlob(); var sequence = StubsUtils.Sequence <StubIUpdateBlobFactory.TryLockUpdateBlob_String_Delegate>() .Twice(id => AsyncUtils.AsyncTaskThatThrows <IUpdateBlob>(new UpdateBlobUnavailableException())) .Once(id => AsyncUtils.AsyncTaskWithResult(updateBlob)); var updateBlobFactoryStub = new StubIUpdateBlobFactory() .TryLockUpdateBlob(id => sequence.Next(appId)); UpdateBlobFactoryRetryLockDecorator retryDecorator = new UpdateBlobFactoryRetryLockDecorator(updateBlobFactoryStub, new FixedInterval(2, TimeSpan.Zero)); Assert.Equal(updateBlob, await retryDecorator.TryLockUpdateBlob(appId)); }
public async Task TestThatStartUpdateSessionIsRetried() { string appId = "appId"; var sequence = StubsUtils.Sequence <StubIUpdateSessionManager.TryStartUpdateSession_String_Delegate>() .Once(id => AsyncUtils.AsyncTaskThatThrows <bool>(new StorageException())) .Once(id => AsyncUtils.AsyncTaskWithResult(true)); var updateSessionStub = new StubIUpdateSessionManager() .TryStartUpdateSession(id => sequence.Next(id)); IUpdateSessionManager retryDecorator = new StorageExceptionUpdateSessionRetryDecorator( updateSessionStub, new FixedInterval(1, TimeSpan.Zero), new StorageExceptionErrorDetectionStrategy()); Assert.True(await retryDecorator.TryStartUpdateSession(appId)); }