Search in sources :

Example 46 with Health

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

the class ElasticsearchRestHealthIndicatorTests method elasticsearchIsOutOfServiceByStatus.

@Test
void elasticsearchIsOutOfServiceByStatus() throws IOException {
    BasicHttpEntity httpEntity = new BasicHttpEntity();
    httpEntity.setContent(new ByteArrayInputStream(createJsonResult(200, "red").getBytes()));
    Response response = mock(Response.class);
    StatusLine statusLine = mock(StatusLine.class);
    given(statusLine.getStatusCode()).willReturn(200);
    given(response.getStatusLine()).willReturn(statusLine);
    given(response.getEntity()).willReturn(httpEntity);
    given(this.restClient.performRequest(any(Request.class))).willReturn(response);
    Health health = this.elasticsearchRestHealthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.OUT_OF_SERVICE);
    assertHealthDetailsWithStatus(health.getDetails(), "red");
}
Also used : Response(org.elasticsearch.client.Response) StatusLine(org.apache.http.StatusLine) ByteArrayInputStream(java.io.ByteArrayInputStream) Health(org.springframework.boot.actuate.health.Health) Request(org.elasticsearch.client.Request) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) Test(org.junit.jupiter.api.Test)

Example 47 with Health

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

the class ElasticsearchRestHealthIndicatorTests method elasticsearchIsDownByResponseCode.

@Test
void elasticsearchIsDownByResponseCode() throws IOException {
    Response response = mock(Response.class);
    StatusLine statusLine = mock(StatusLine.class);
    given(statusLine.getStatusCode()).willReturn(500);
    given(statusLine.getReasonPhrase()).willReturn("Internal server error");
    given(response.getStatusLine()).willReturn(statusLine);
    given(this.restClient.performRequest(any(Request.class))).willReturn(response);
    Health health = this.elasticsearchRestHealthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat(health.getDetails()).contains(entry("statusCode", 500), entry("reasonPhrase", "Internal server error"));
}
Also used : Response(org.elasticsearch.client.Response) StatusLine(org.apache.http.StatusLine) Health(org.springframework.boot.actuate.health.Health) Request(org.elasticsearch.client.Request) Test(org.junit.jupiter.api.Test)

Example 48 with Health

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

the class CassandraDriverHealthIndicatorTests method healthWithOneForcedDownNodeShouldReturnDown.

@Test
void healthWithOneForcedDownNodeShouldReturnDown() {
    CqlSession session = mockCqlSessionWithNodeState(NodeState.FORCED_DOWN);
    CassandraDriverHealthIndicator healthIndicator = new CassandraDriverHealthIndicator(session);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
}
Also used : Health(org.springframework.boot.actuate.health.Health) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.jupiter.api.Test)

Example 49 with Health

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

the class CassandraDriverHealthIndicatorTests method healthWithOneHealthyNodeAndOneUnknownNodeShouldReturnUp.

@Test
void healthWithOneHealthyNodeAndOneUnknownNodeShouldReturnUp() {
    CqlSession session = mockCqlSessionWithNodeState(NodeState.UP, NodeState.UNKNOWN);
    CassandraDriverHealthIndicator healthIndicator = new CassandraDriverHealthIndicator(session);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
}
Also used : Health(org.springframework.boot.actuate.health.Health) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.jupiter.api.Test)

Example 50 with Health

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

the class CassandraDriverHealthIndicatorTests method healthWithOneHealthyNodeShouldReturnUp.

@Test
void healthWithOneHealthyNodeShouldReturnUp() {
    CqlSession session = mockCqlSessionWithNodeState(NodeState.UP);
    CassandraDriverHealthIndicator healthIndicator = new CassandraDriverHealthIndicator(session);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
}
Also used : Health(org.springframework.boot.actuate.health.Health) CqlSession(com.datastax.oss.driver.api.core.CqlSession) 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