public void KnownTypesRequireMatchingType() { var availability = new ApplicationAvailability(_logger); Assert.Throws <InvalidOperationException>(() => availability.SetAvailabilityState(availability.LivenessKey, ReadinessState.AcceptingTraffic, null)); Assert.Throws <InvalidOperationException>(() => availability.SetAvailabilityState(availability.ReadinessKey, LivenessState.Correct, null)); }
public void HandlesAccepting() { // arrange availability.SetAvailabilityState(availability.ReadinessKey, ReadinessState.AcceptingTraffic, "tests"); var contributor = new ReadinessHealthContributor(availability); // act var result = contributor.Health(); // assert Assert.Equal(HealthStatus.UP, result.Status); }
public void HandlesCorrect() { // arrange availability.SetAvailabilityState(availability.LivenessKey, LivenessState.Correct, "tests"); var contributor = new LivenessHealthContributor(availability); // act var result = contributor.Health(); // assert Assert.Equal(HealthStatus.UP, result.Status); }
public void TracksAndReturnsState() { var availability = new ApplicationAvailability(_logger); availability.SetAvailabilityState("Test", LivenessState.Broken, GetType().Name); availability.SetAvailabilityState(availability.LivenessKey, LivenessState.Correct, GetType().Name); availability.SetAvailabilityState(availability.ReadinessKey, ReadinessState.AcceptingTraffic, GetType().Name); Assert.Equal(LivenessState.Broken, availability.GetAvailabilityState("Test")); Assert.Equal(LivenessState.Correct, availability.GetLivenessState()); Assert.Equal(ReadinessState.AcceptingTraffic, availability.GetReadinessState()); }
public void InvokeWithReadinessGroupReturnsGroupResults() { using (var tc = new TestContext(_output)) { var appAvailability = new ApplicationAvailability(); var contributors = new List <IHealthContributor>() { new UnknownContributor(), new UpContributor(), new ReadinessHealthContributor(appAvailability) }; tc.AdditionalServices = (services, configuration) => { services.AddSingleton <IEnumerable <IHealthContributor> >(contributors); services.AddSingleton <IHealthAggregator>(new DefaultHealthAggregator()); services.AddHealthActuatorServices(configuration); }; var ep = tc.GetService <IHealthEndpoint>(); var context = Substitute.For <ISecurityContext>(); context.GetRequestComponents().Returns(new string[] { "actuator", "health", "readiness" }); appAvailability.SetAvailabilityState(appAvailability.ReadinessKey, ReadinessState.AcceptingTraffic, null); var result = ep.Invoke(context); Assert.Equal(HealthStatus.UP, result.Status); Assert.True(result.Details.Keys.Count == 1); Assert.True(result.Groups.Count() == 2); } }
public void FiresEventsOnKnownTypeStateChange() { var availability = new ApplicationAvailability(_logger); availability.LivenessChanged += Availability_LivenessChanged; availability.ReadinessChanged += Availability_ReadinessChanged; availability.SetAvailabilityState(availability.LivenessKey, LivenessState.Broken, null); Assert.Equal(LivenessState.Broken, lastLivenessState); availability.SetAvailabilityState(availability.ReadinessKey, ReadinessState.RefusingTraffic, null); Assert.Equal(ReadinessState.RefusingTraffic, lastReadinessState); availability.SetAvailabilityState(availability.LivenessKey, LivenessState.Correct, null); availability.SetAvailabilityState(availability.ReadinessKey, ReadinessState.AcceptingTraffic, null); Assert.Equal(2, livenessChanges); Assert.Equal(LivenessState.Correct, lastLivenessState); Assert.Equal(2, readinessChanges); Assert.Equal(ReadinessState.AcceptingTraffic, lastReadinessState); }
public void InvokeWithReadinessGroupReturnsGroupResults2() { var appAvailability = new ApplicationAvailability(); var contribs = new List <IHealthContributor>() { new UnknownContributor(), new UpContributor(), new ReadinessHealthContributor(appAvailability) }; var ep = new HealthEndpointCore(options, aggregator, contribs, ServiceProviderWithMSFTHealth(), provider); var context = Substitute.For <ISecurityContext>(); context.GetRequestComponents().Returns(new string[] { "actuator", "health", "readiness" }); appAvailability.SetAvailabilityState(appAvailability.ReadinessKey, ReadinessState.AcceptingTraffic, null); var result = ep.Invoke(context); Assert.Equal(HealthStatus.UP, result.Status); Assert.Single(result.Details.Keys); Assert.Equal(2, result.Groups.Count()); }
public void InvokeWithLivenessGroupReturnsGroupResults() { var appAvailability = new ApplicationAvailability(); var contribs = new List <IHealthContributor>() { new DiskSpaceContributor(), new LivenessHealthContributor(appAvailability) }; var ep = new HealthEndpointCore(options, aggregator, contribs, ServiceOptions(), provider); var context = Substitute.For <ISecurityContext>(); context.GetRequestComponents().Returns(new string[] { "cloudfoundryapplication", "health", "liVeness" }); appAvailability.SetAvailabilityState(appAvailability.LivenessKey, LivenessState.Correct, null); var result = ep.Invoke(context); Assert.Equal(HealthStatus.UP, result.Status); Assert.Single(result.Details.Keys); Assert.Equal(2, result.Groups.Count()); }
public void InvokeWithReadinessGroupReturnsGroupResults() { // arrange var opts = new HealthEndpointOptions(); var appAvailability = new ApplicationAvailability(); var contribs = new List <IHealthContributor>() { new UnknownContributor(), new UpContributor(), new ReadinessHealthContributor(appAvailability) }; var ep = new HealthEndpoint(opts, new DefaultHealthAggregator(), contribs); var context = Substitute.For <ISecurityContext>(); context.GetRequestComponents().Returns(new string[] { "actuator", "health", "readiness" }); appAvailability.SetAvailabilityState(appAvailability.ReadinessKey, ReadinessState.AcceptingTraffic, null); // act var result = ep.Invoke(context); // assert Assert.Equal(HealthStatus.UP, result.Status); Assert.True(result.Details.Keys.Count == 1); Assert.True(result.Groups.Count() == 2); }
public void InvokeWithLivenessGroupReturnsGroupResults() { // arrange var opts = new HealthEndpointOptions(); var appAvailability = new ApplicationAvailability(); var contribs = new List <IHealthContributor>() { new DiskSpaceContributor(), new LivenessHealthContributor(appAvailability) }; var ep = new HealthEndpoint(opts, new DefaultHealthAggregator(), contribs); var context = Substitute.For <ISecurityContext>(); context.GetRequestComponents().Returns(new string[] { "cloudfoundryapplication", "health", "liVeness" }); appAvailability.SetAvailabilityState(appAvailability.LivenessKey, LivenessState.Correct, null); // act var result = ep.Invoke(context); // assert Assert.Equal(HealthStatus.UP, result.Status); Assert.True(result.Details.Keys.Count == 1); Assert.True(result.Groups.Count() == 2); }