public async Task SetPassiveAsync_DestinationBecameUnhealthy_SetUnhealthyAndScheduleReactivation() { var destination = new DestinationState("destination0"); destination.Health.Active = DestinationHealth.Healthy; destination.Health.Passive = DestinationHealth.Healthy; var cluster = CreateCluster(passive: true, active: false, destination); using var timerFactory = new TestTimerFactory(); var updater = new DestinationHealthUpdater(timerFactory, GetClusterUpdater(), new Mock <ILogger <DestinationHealthUpdater> >().Object); await updater.SetPassiveAsync(cluster, destination, DestinationHealth.Unhealthy, TimeSpan.FromSeconds(2)); timerFactory.VerifyTimer(0, 2000); Assert.Empty(cluster.DestinationsState.AvailableDestinations); Assert.Equal(DestinationHealth.Healthy, destination.Health.Active); Assert.Equal(DestinationHealth.Unhealthy, destination.Health.Passive); timerFactory.FireAll(); Assert.Equal(DestinationHealth.Healthy, destination.Health.Active); Assert.Equal(DestinationHealth.Unknown, destination.Health.Passive); Assert.Equal(1, cluster.DestinationsState.AvailableDestinations.Count); Assert.Same(destination, cluster.DestinationsState.AvailableDestinations[0]); timerFactory.AssertTimerDisposed(0); }
public async Task SetPassiveAsync_HealthSateIsNotChanged_DoNothing(DestinationHealth health) { var destination = new DestinationState("destination0"); destination.Health.Active = DestinationHealth.Healthy; destination.Health.Passive = health; var cluster = CreateCluster(passive: true, active: false, destination); using var timerFactory = new TestTimerFactory(); var updater = new DestinationHealthUpdater(timerFactory, GetClusterUpdater(), new Mock <ILogger <DestinationHealthUpdater> >().Object); await updater.SetPassiveAsync(cluster, destination, health, TimeSpan.FromSeconds(2)); Assert.Equal(0, timerFactory.Count); Assert.Equal(DestinationHealth.Healthy, destination.Health.Active); Assert.Equal(health, destination.Health.Passive); }
public async Task SetPassiveAsync_DestinationBecameHealthy_SetNewState() { var destination = new DestinationState("destination0"); destination.Health.Active = DestinationHealth.Healthy; destination.Health.Passive = DestinationHealth.Unhealthy; var cluster = CreateCluster(passive: true, active: false, destination); using var timerFactory = new TestTimerFactory(); var updater = new DestinationHealthUpdater(timerFactory, GetClusterUpdater(), new Mock <ILogger <DestinationHealthUpdater> >().Object); await updater.SetPassiveAsync(cluster, destination, DestinationHealth.Healthy, TimeSpan.FromSeconds(2)); Assert.Equal(0, timerFactory.Count); Assert.Equal(DestinationHealth.Healthy, destination.Health.Active); Assert.Equal(DestinationHealth.Healthy, destination.Health.Passive); Assert.Equal(1, cluster.DestinationsState.AvailableDestinations.Count); Assert.Same(destination, cluster.DestinationsState.AvailableDestinations[0]); }
public void SetActive_ChangedAndUnchangedHealthStates_SetChangedStates() { var destination0 = new DestinationState("destination0"); destination0.Health.Active = DestinationHealth.Healthy; destination0.Health.Passive = DestinationHealth.Healthy; var destination1 = new DestinationState("destination1"); destination1.Health.Active = DestinationHealth.Healthy; destination1.Health.Passive = DestinationHealth.Healthy; var destination2 = new DestinationState("destination2"); destination2.Health.Active = DestinationHealth.Unhealthy; destination2.Health.Passive = DestinationHealth.Healthy; var destination3 = new DestinationState("destination3"); destination3.Health.Active = DestinationHealth.Unhealthy; destination3.Health.Passive = DestinationHealth.Healthy; var cluster = CreateCluster(passive: false, active: true, destination0, destination1, destination2, destination3); var updater = new DestinationHealthUpdater(new Mock <ITimerFactory>().Object, GetClusterUpdater(), new Mock <ILogger <DestinationHealthUpdater> >().Object); var newHealthStates = new[] { new NewActiveDestinationHealth(destination0, DestinationHealth.Unhealthy), new NewActiveDestinationHealth(destination1, DestinationHealth.Healthy), new NewActiveDestinationHealth(destination2, DestinationHealth.Unhealthy), new NewActiveDestinationHealth(destination3, DestinationHealth.Healthy) }; updater.SetActive(cluster, newHealthStates); foreach (var newHealthState in newHealthStates) { Assert.Equal(newHealthState.NewActiveHealth, newHealthState.Destination.Health.Active); Assert.Equal(DestinationHealth.Healthy, newHealthState.Destination.Health.Passive); } Assert.Equal(2, cluster.DestinationsState.AvailableDestinations.Count); Assert.Contains(cluster.DestinationsState.AvailableDestinations, d => d == destination1); Assert.Contains(cluster.DestinationsState.AvailableDestinations, d => d == destination3); }