Search in sources :

Example 66 with Health

use of org.springframework.boot.actuate.health.Health in project sofa-boot by alipay.

the class AfterHealthCheckCallbackProcessor method doApplicationAfterHealthCheckCallback.

/**
 * process application afterHealthCheckCallback
 * @return
 */
private boolean doApplicationAfterHealthCheckCallback() {
    boolean result = true;
    logger.info("Begin ApplicationAfterHealthCheckCallback startup health check");
    List<SofaBootApplicationAfterHealthCheckCallback> afterHealthCheckCallbacks = HealthCheckManager.getApplicationAfterHealthCheckCallbacks();
    for (SofaBootApplicationAfterHealthCheckCallback afterHealthCheckCallback : afterHealthCheckCallbacks) {
        try {
            Health health = afterHealthCheckCallback.onHealthy(HealthCheckManager.getApplicationContext());
            Status status = health.getStatus();
            if (!status.equals(Status.UP)) {
                result = false;
                logger.error("sofaboot application afterHealthCheck callback(" + afterHealthCheckCallback.getClass() + ") failed, the details is: " + JSON.toJSONString(health.getDetails()));
            } else {
                logger.info("sofaboot application afterHealthCheck callback(" + afterHealthCheckCallback.getClass() + ") ]success.");
            }
            StartUpHealthCheckStatus.putAfterHealthCheckCallbackDetail(getKey(afterHealthCheckCallback.getClass().getName()), health);
        } catch (Throwable t) {
            result = false;
            logger.error("Invoking  ApplicationAfterHealthCheckCallback " + afterHealthCheckCallback.getClass().getName() + " got an exception.", t);
        }
    }
    if (result) {
        logger.info("ApplicationAfterHealthCheckCallback startup health check result: success.");
    } else {
        logger.error("ApplicationAfterHealthCheckCallback startup health check result: failed.");
    }
    return result;
}
Also used : Status(org.springframework.boot.actuate.health.Status) StartUpHealthCheckStatus(com.alipay.sofa.healthcheck.startup.StartUpHealthCheckStatus) SofaBootApplicationAfterHealthCheckCallback(com.alipay.sofa.healthcheck.startup.SofaBootApplicationAfterHealthCheckCallback) Health(org.springframework.boot.actuate.health.Health)

Example 67 with Health

use of org.springframework.boot.actuate.health.Health in project resilience4j by resilience4j.

the class CircuitBreakerHealthIndicatorTest method health.

@Test
public void health() throws Exception {
    // given
    CircuitBreakerConfig config = mock(CircuitBreakerConfig.class);
    CircuitBreaker.Metrics metrics = mock(CircuitBreaker.Metrics.class);
    CircuitBreaker circuitBreaker = mock(CircuitBreaker.class);
    CircuitBreakerHealthIndicator healthIndicator = new CircuitBreakerHealthIndicator(circuitBreaker);
    // when
    when(config.getFailureRateThreshold()).thenReturn(0.3f);
    when(metrics.getFailureRate()).thenReturn(0.2f);
    when(metrics.getMaxNumberOfBufferedCalls()).thenReturn(100);
    when(metrics.getNumberOfBufferedCalls()).thenReturn(100);
    when(metrics.getNumberOfFailedCalls()).thenReturn(20);
    when(metrics.getNumberOfNotPermittedCalls()).thenReturn(0L);
    when(circuitBreaker.getCircuitBreakerConfig()).thenReturn(config);
    when(circuitBreaker.getMetrics()).thenReturn(metrics);
    when(circuitBreaker.getState()).thenReturn(CLOSED, OPEN, HALF_OPEN, CLOSED);
    // then
    Health health = healthIndicator.health();
    then(health.getStatus()).isEqualTo(Status.UP);
    health = healthIndicator.health();
    then(health.getStatus()).isEqualTo(Status.DOWN);
    health = healthIndicator.health();
    then(health.getStatus()).isEqualTo(Status.UNKNOWN);
    health = healthIndicator.health();
    then(health.getStatus()).isEqualTo(Status.UP);
    then(health.getDetails()).contains(entry("failureRate", "0.2%"), entry("failureRateThreshold", "0.3%"), entry("bufferedCalls", 100), entry("failedCalls", 20), entry("notPermittedCalls", 0L), entry("maxBufferedCalls", 100));
}
Also used : CircuitBreaker(io.github.resilience4j.circuitbreaker.CircuitBreaker) Health(org.springframework.boot.actuate.health.Health) CircuitBreakerConfig(io.github.resilience4j.circuitbreaker.CircuitBreakerConfig) Test(org.junit.Test)

Example 68 with Health

use of org.springframework.boot.actuate.health.Health in project resilience4j by resilience4j.

the class RateLimiterHealthIndicatorTest method health.

@Test
public void health() throws Exception {
    // given
    RateLimiterConfig config = mock(RateLimiterConfig.class);
    AtomicRateLimiter.AtomicRateLimiterMetrics metrics = mock(AtomicRateLimiter.AtomicRateLimiterMetrics.class);
    AtomicRateLimiter rateLimiter = mock(AtomicRateLimiter.class);
    // when
    when(rateLimiter.getRateLimiterConfig()).thenReturn(config);
    when(rateLimiter.getMetrics()).thenReturn(metrics);
    when(rateLimiter.getDetailedMetrics()).thenReturn(metrics);
    when(config.getTimeoutDuration()).thenReturn(Duration.ofNanos(30L));
    when(metrics.getAvailablePermissions()).thenReturn(5, -1, -2);
    when(metrics.getNumberOfWaitingThreads()).thenReturn(0, 1, 2);
    when(metrics.getNanosToWait()).thenReturn(20L, 40L);
    // then
    RateLimiterHealthIndicator healthIndicator = new RateLimiterHealthIndicator(rateLimiter);
    Health health = healthIndicator.health();
    then(health.getStatus()).isEqualTo(Status.UP);
    health = healthIndicator.health();
    then(health.getStatus()).isEqualTo(Status.UNKNOWN);
    health = healthIndicator.health();
    then(health.getStatus()).isEqualTo(Status.DOWN);
    then(health.getDetails()).contains(entry("availablePermissions", -2), entry("numberOfWaitingThreads", 2));
}
Also used : Health(org.springframework.boot.actuate.health.Health) RateLimiterConfig(io.github.resilience4j.ratelimiter.RateLimiterConfig) AtomicRateLimiter(io.github.resilience4j.ratelimiter.internal.AtomicRateLimiter) Test(org.junit.Test)

Example 69 with Health

use of org.springframework.boot.actuate.health.Health in project dubbo by alibaba.

the class DubboHealthIndicatorTest method testHealth.

@Test
public void testHealth() {
    Health health = dubboHealthIndicator.health();
    Assert.assertEquals(Status.UNKNOWN, health.getStatus());
}
Also used : Health(org.springframework.boot.actuate.health.Health) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 70 with Health

use of org.springframework.boot.actuate.health.Health in project spring-boot by spring-projects.

the class CloudFoundryHealthEndpointWebExtensionTests method healthComponentsAlwaysPresent.

@Test
void healthComponentsAlwaysPresent() {
    this.contextRunner.run((context) -> {
        CloudFoundryHealthEndpointWebExtension extension = context.getBean(CloudFoundryHealthEndpointWebExtension.class);
        HealthComponent body = extension.health(ApiVersion.V3).getBody();
        HealthComponent health = ((CompositeHealth) body).getComponents().entrySet().iterator().next().getValue();
        assertThat(((Health) health).getDetails()).containsEntry("spring", "boot");
    });
}
Also used : HealthComponent(org.springframework.boot.actuate.health.HealthComponent) CompositeHealth(org.springframework.boot.actuate.health.CompositeHealth) Health(org.springframework.boot.actuate.health.Health) CompositeHealth(org.springframework.boot.actuate.health.CompositeHealth) Test(org.junit.jupiter.api.Test)

Aggregations

Health (org.springframework.boot.actuate.health.Health)116 Test (org.junit.jupiter.api.Test)89 Status (org.springframework.boot.actuate.health.Status)23 CqlSession (com.datastax.oss.driver.api.core.CqlSession)20 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)18 BDDMockito.given (org.mockito.BDDMockito.given)18 Mockito.mock (org.mockito.Mockito.mock)18 Mono (reactor.core.publisher.Mono)18 StepVerifier (reactor.test.StepVerifier)18 Test (org.junit.Test)17 List (java.util.List)14 DriverTimeoutException (com.datastax.oss.driver.api.core.DriverTimeoutException)11 Metadata (com.datastax.oss.driver.api.core.metadata.Metadata)11 Node (com.datastax.oss.driver.api.core.metadata.Node)11 HashMap (java.util.HashMap)11 Version (com.datastax.oss.driver.api.core.Version)10 NodeState (com.datastax.oss.driver.api.core.metadata.NodeState)10 ArrayList (java.util.ArrayList)10 Collections (java.util.Collections)10 Map (java.util.Map)10