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 TestThatEndUpdateSessionThrowsIfBlobCannotBeLocked() { string appId = null; var updateBlobFactoryStub = new StubIUpdateBlobFactory().TryLockUpdateBlob( id => { appId = id; return AsyncUtils.AsyncTaskThatThrows<IUpdateBlob>(new UpdateBlobUnavailableException()); } ); BlobBasedUpdateSessionManager updateSessionManager = new BlobBasedUpdateSessionManager(updateBlobFactoryStub, "instanceId1", "1"); await Assert.ThrowsAnyAsync<Exception>(async () => await updateSessionManager.EndUpdateSession("app1")); Assert.Equal("app1", appId); }
public async Task TestThatNotAllExceptionsAreRetried() { string appId = "appId"; var sequence = StubsUtils.Sequence<StubIUpdateBlobFactory.TryLockUpdateBlob_String_Delegate>() .Twice(id => AsyncUtils.AsyncTaskThatThrows<IUpdateBlob>(new Exception())); var updateBlobFactoryStub = new StubIUpdateBlobFactory() .TryLockUpdateBlob(id => sequence.Next(appId)); UpdateBlobFactoryRetryLockDecorator retryDecorator = new UpdateBlobFactoryRetryLockDecorator(updateBlobFactoryStub, new FixedInterval(1, TimeSpan.Zero)); await Assert.ThrowsAsync<Exception>(async () => await retryDecorator.TryLockUpdateBlob(appId)); }
public async Task TestThatNotAllExceptionsAreRetried() { string appId = "appId"; var sequence = StubsUtils.Sequence <StubIUpdateBlobFactory.TryLockUpdateBlob_String_Delegate>() .Twice(id => AsyncUtils.AsyncTaskThatThrows <IUpdateBlob>(new Exception())); var updateBlobFactoryStub = new StubIUpdateBlobFactory() .TryLockUpdateBlob(id => sequence.Next(appId)); UpdateBlobFactoryRetryLockDecorator retryDecorator = new UpdateBlobFactoryRetryLockDecorator(updateBlobFactoryStub, new FixedInterval(1, TimeSpan.Zero)); await Assert.ThrowsAsync <Exception>(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 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 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)); }