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 TestThatStorageExceptionsAreRetried() { var fetchUpdateSessionStatusStub = StubsUtils.Sequence <Func <Task <UpdateSessionStatus> > >() .Once(() => AsyncUtils.AsyncTaskThatThrows <UpdateSessionStatus>(new StorageException())) .Once(() => Task.FromResult(new UpdateSessionStatus(Enumerable.Empty <UpdateDomainEntity>(), null, null))); IUpdateSessionTable updateSessionTableStub = new StubIUpdateSessionTable() .FetchUpdateSessionStatus((superClusterId) => fetchUpdateSessionStatusStub.Next()) .TryExecuteTransaction(transaction => Task.FromResult(true)) .DeleteInstanceEntity((superClusterId, instanceId) => Task.FromResult(true)) .GetActiveUpdateDomain((superClusterId) => Task.FromResult("1")); ContainerBuilder builder = AzureStorageUpdateSessionDiModule.RegisterTypes("superClusterId", "superClusterId", "instanceId", "1", EmulatorConnectionString, Ttl); builder.RegisterInstance(updateSessionTableStub); IUpdateSessionManager updateSessionManager = new AzureStorageUpdateSessionDiModule(builder.Build()) .UpdateSessionManager; Assert.True(await updateSessionManager.TryStartUpdateSession()); await updateSessionManager.EndUpdateSession(); Assert.Equal(2, fetchUpdateSessionStatusStub.CallCount); }
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 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 TestThatEndUpdateSessionIsRetried() { var sequence = StubsUtils.Sequence <StubIUpdateSessionManager.EndUpdateSession_Delegate>() .Once(() => AsyncUtils.AsyncTaskThatThrows(new StorageException())) .Once(() => Task.CompletedTask); var updateSessionStub = new StubIUpdateSessionManager() .EndUpdateSession(() => sequence.Next()); IUpdateSessionManager retryDecorator = new StorageExceptionUpdateSessionRetryDecorator( updateSessionStub, new FixedInterval(1, TimeSpan.Zero), new StorageExceptionErrorDetectionStrategy()); await retryDecorator.EndUpdateSession(); }
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)); }