Search in sources :

Example 1 with Health

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

the class HealthMvcEndpoint method invoke.

@ActuatorGetMapping
@ResponseBody
public Object invoke(HttpServletRequest request, Principal principal) {
    if (!getDelegate().isEnabled()) {
        // Shouldn't happen because the request mapping should not be registered
        return getDisabledResponse();
    }
    Health health = getHealth(request, principal);
    HttpStatus status = getStatus(health);
    if (status != null) {
        return new ResponseEntity<>(health, status);
    }
    return health;
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) Health(org.springframework.boot.actuate.health.Health) HttpStatus(org.springframework.http.HttpStatus) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with Health

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

the class EndpointAutoConfigurationTests method healthEndpointWithDefaultHealthIndicator.

@Test
public void healthEndpointWithDefaultHealthIndicator() {
    load(EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class);
    HealthEndpoint bean = this.context.getBean(HealthEndpoint.class);
    assertThat(bean).isNotNull();
    Health result = bean.invoke();
    assertThat(result).isNotNull();
}
Also used : HealthEndpoint(org.springframework.boot.actuate.endpoint.HealthEndpoint) Health(org.springframework.boot.actuate.health.Health) Test(org.junit.Test)

Example 3 with Health

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

the class HealthMvcEndpointTests method newValueIsReturnedOnceTtlExpires.

@Test
public void newValueIsReturnedOnceTtlExpires() throws InterruptedException {
    given(this.endpoint.getTimeToLive()).willReturn(50L);
    given(this.endpoint.invoke()).willReturn(new Health.Builder().up().withDetail("foo", "bar").build());
    Object result = this.mvc.invoke(this.request, null);
    assertThat(result instanceof Health).isTrue();
    assertThat(((Health) result).getStatus() == Status.UP).isTrue();
    Thread.sleep(100);
    given(this.endpoint.invoke()).willReturn(new Health.Builder().down().build());
    result = this.mvc.invoke(this.request, null);
    @SuppressWarnings("unchecked") Health health = ((ResponseEntity<Health>) result).getBody();
    assertThat(health.getStatus() == Status.DOWN).isTrue();
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) Health(org.springframework.boot.actuate.health.Health) Test(org.junit.Test)

Example 4 with Health

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

the class CamelHealthTest method shouldHaveHealth.

@Test
public void shouldHaveHealth() throws Exception {
    Health health = indicator.health();
    assertNotNull(health);
    String code = health.getStatus().getCode();
    assertEquals("UP", code);
    String version = (String) health.getDetails().get("version");
    assertEquals(camelContext.getVersion(), version);
}
Also used : Health(org.springframework.boot.actuate.health.Health) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 5 with Health

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

the class StatusController method handleRequestInternal.

/**
 * Handle request.
 *
 * @param request  the request
 * @param response the response
 * @throws Exception the exception
 */
@GetMapping
@ResponseBody
protected void handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    ensureEndpointAccessIsAuthorized(request, response);
    final StringBuilder sb = new StringBuilder();
    final Health health = this.healthEndpoint.invoke();
    final Status status = health.getStatus();
    if (status.equals(Status.DOWN) || status.equals(Status.OUT_OF_SERVICE)) {
        response.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value());
    }
    sb.append("Health: ").append(status.getCode());
    sb.append("\n\nHost:\t\t").append(StringUtils.isBlank(casProperties.getHost().getName()) ? InetAddressUtils.getCasServerHostName() : casProperties.getHost().getName());
    sb.append("\nServer:\t\t").append(casProperties.getServer().getName());
    sb.append("\nVersion:\t").append(CasVersion.getVersion());
    response.setContentType(MediaType.TEXT_PLAIN_VALUE);
    try (Writer writer = response.getWriter()) {
        IOUtils.copy(new ByteArrayInputStream(sb.toString().getBytes(response.getCharacterEncoding())), writer, StandardCharsets.UTF_8);
        writer.flush();
    }
}
Also used : Status(org.springframework.boot.actuate.health.Status) HttpStatus(org.springframework.http.HttpStatus) Health(org.springframework.boot.actuate.health.Health) ByteArrayInputStream(java.io.ByteArrayInputStream) Writer(java.io.Writer) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Health (org.springframework.boot.actuate.health.Health)122 Test (org.junit.jupiter.api.Test)86 Test (org.junit.Test)26 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 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