org.springframework.boot.actuate.health.SimpleStatusAggregator Java Examples

The following examples show how to use org.springframework.boot.actuate.health.SimpleStatusAggregator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RateLimitersHealthIndicatorTest.java    From resilience4j with Apache License 2.0 4 votes vote down vote up
@Test
public void healthIndicatorMaxImpactCanBeOverridden() throws Exception {
    // given
    RateLimiterConfig config = mock(RateLimiterConfig.class);
    AtomicRateLimiter.AtomicRateLimiterMetrics metrics = mock(AtomicRateLimiter.AtomicRateLimiterMetrics.class);
    AtomicRateLimiter rateLimiter = mock(AtomicRateLimiter.class);
    RateLimiterRegistry rateLimiterRegistry = mock(RateLimiterRegistry.class);
    io.github.resilience4j.common.ratelimiter.configuration.RateLimiterConfigurationProperties.InstanceProperties instanceProperties =
            mock(io.github.resilience4j.common.ratelimiter.configuration.RateLimiterConfigurationProperties.InstanceProperties.class);
    RateLimiterConfigurationProperties rateLimiterProperties = mock(RateLimiterConfigurationProperties.class);

    //when
    when(rateLimiter.getRateLimiterConfig()).thenReturn(config);
    when(rateLimiter.getName()).thenReturn("test");
    when(rateLimiterProperties.findRateLimiterProperties("test")).thenReturn(Optional.of(instanceProperties));
    when(instanceProperties.getRegisterHealthIndicator()).thenReturn(true);

    boolean allowHealthIndicatorToFail = false; // do not allow health indicator to fail
    when(instanceProperties.getAllowHealthIndicatorToFail()).thenReturn(allowHealthIndicatorToFail);
    when(rateLimiter.getMetrics()).thenReturn(metrics);
    when(rateLimiter.getDetailedMetrics()).thenReturn(metrics);
    when(rateLimiterRegistry.getAllRateLimiters()).thenReturn(Array.of(rateLimiter));

    when(config.getTimeoutDuration()).thenReturn(Duration.ofNanos(30L));

    when(metrics.getAvailablePermissions())
            .thenReturn(-2);
    when(metrics.getNumberOfWaitingThreads())
            .thenReturn(2);
    when(metrics.getNanosToWait())
            .thenReturn(40L);

    // then
    RateLimitersHealthIndicator healthIndicator =
            new RateLimitersHealthIndicator(rateLimiterRegistry, rateLimiterProperties, new SimpleStatusAggregator());

    Health health = healthIndicator.health();
    then(health.getStatus()).isEqualTo(Status.UNKNOWN);
    then(((Health) health.getDetails().get("test")).getStatus()).isEqualTo(new Status("RATE_LIMITED"));

    then(health.getDetails().get("test")).isInstanceOf(Health.class);
    then(((Health) health.getDetails().get("test")).getDetails())
            .contains(
                    entry("availablePermissions", -2),
                    entry("numberOfWaitingThreads", 2)
            );
}
 
Example #2
Source File: EurekaHealthCheckHandlerTests.java    From spring-cloud-netflix with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {

	healthCheckHandler = new EurekaHealthCheckHandler(new SimpleStatusAggregator());
}