public async Task TestRemoveInstanceId() { IUpdateBlob updateBlob = await _updateBlobFactory.TryLockUpdateBlob("appId"); updateBlob.SetUpdateDomain("1"); updateBlob.AddInstance("instanceId1"); updateBlob.AddInstance("instanceId2"); await updateBlob.FlushAndRelease(); updateBlob = await _updateBlobFactory.TryLockUpdateBlob("appId"); updateBlob.RemoveInstance("instanceId1"); await updateBlob.FlushAndRelease(); await updateBlob.TryLock(); Assert.Equal("1", updateBlob.GetUpdateDomain()); AssertUtils.ContainsSameElementsInAnyOrder(new[] { "instanceId2" }, updateBlob.GetInstanceIds()); await updateBlob.Release(); updateBlob = await _updateBlobFactory.TryLockUpdateBlob("appId"); updateBlob.RemoveInstance("instanceId2"); await updateBlob.FlushAndRelease(); await updateBlob.TryLock(); Assert.True(string.IsNullOrEmpty(updateBlob.GetUpdateDomain())); Assert.Empty(updateBlob.GetInstanceIds()); }
public async Task <bool> TryStartUpdateSession(string applicationId) { using (IUpdateBlob updateBlob = await _updateBlobFactory.TryLockUpdateBlob(applicationId)) { string updateDomain = updateBlob.GetUpdateDomain(); if (string.IsNullOrEmpty(updateDomain) || _instanceUpdateDomain == updateDomain) { updateDomain = _instanceUpdateDomain; Trace.TraceInformation( $"Instance {_instanceId} will attempt to start update session for " + $"ApplicationId = {applicationId}, UpdateDomain = {updateDomain}"); updateBlob.SetUpdateDomain(updateDomain); updateBlob.AddInstance(_instanceId); await updateBlob.FlushAndRelease(); Trace.TraceInformation( $"Instance {_instanceId} successfully started the update session for " + $"ApplicationId = {applicationId}, UpdateDomain = {updateDomain}"); return(true); } } return(false); }
public async Task TestThatUpdateBlobMustBeLockedBeforeAnyOperation() { IUpdateBlob updateBlob = await _updateBlobFactory.TryLockUpdateBlob("appId"); await updateBlob.FlushAndRelease(); Assert.Throws<InvalidOperationException>(() => updateBlob.GetUpdateDomain()); Assert.Throws<InvalidOperationException>(() => updateBlob.GetInstanceIds()); Assert.Throws<InvalidOperationException>(() => updateBlob.AddInstance("1")); Assert.Throws<InvalidOperationException>(() => updateBlob.RemoveInstance("1")); Assert.Throws<InvalidOperationException>(() => updateBlob.SetUpdateDomain("1")); await Assert.ThrowsAsync<InvalidOperationException>(async () => await updateBlob.FlushAndRelease()); }
public async Task TestAddingMultipleInstanceIds() { IUpdateBlob updateBlob = await _updateBlobFactory.TryLockUpdateBlob("appId"); updateBlob.SetUpdateDomain("1"); updateBlob.AddInstance("instanceId1"); updateBlob.AddInstance("instanceId2"); await updateBlob.FlushAndRelease(); await updateBlob.TryLock(); Assert.Equal("1", updateBlob.GetUpdateDomain()); AssertUtils.ContainsSameElementsInAnyOrder(new[] { "instanceId1", "instanceId2" }, updateBlob.GetInstanceIds()); }
public async Task TestSetDataWhenBlobIsEmpty() { IUpdateBlob updateBlob = await _updateBlobFactory.TryLockUpdateBlob("appId"); const string instanceId = "instanceId"; const string updateDomain = "1"; updateBlob.SetUpdateDomain(updateDomain); updateBlob.AddInstance(instanceId); await updateBlob.FlushAndRelease(); await updateBlob.TryLock(); Assert.Equal(updateDomain, updateBlob.GetUpdateDomain()); AssertUtils.ContainsSameElementsInAnyOrder(new[] { instanceId }, updateBlob.GetInstanceIds()); }
public async Task TestGetUpdateDomainOnEmptyBlob() { IUpdateBlob updateBlob = await _updateBlobFactory.TryLockUpdateBlob("appId"); Assert.True(string.IsNullOrEmpty(updateBlob.GetUpdateDomain())); }