Search in sources :

Example 81 with Health

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

the class RedisReactiveHealthIndicatorTests method redisIsUp.

@Test
void redisIsUp() {
    Properties info = new Properties();
    info.put("redis_version", "2.8.9");
    ReactiveRedisConnection redisConnection = mock(ReactiveRedisConnection.class);
    given(redisConnection.closeLater()).willReturn(Mono.empty());
    ReactiveServerCommands commands = mock(ReactiveServerCommands.class);
    given(commands.info("server")).willReturn(Mono.just(info));
    RedisReactiveHealthIndicator healthIndicator = createHealthIndicator(redisConnection, commands);
    Mono<Health> health = healthIndicator.health();
    StepVerifier.create(health).consumeNextWith((h) -> {
        assertThat(h.getStatus()).isEqualTo(Status.UP);
        assertThat(h.getDetails()).containsOnlyKeys("version");
        assertThat(h.getDetails().get("version")).isEqualTo("2.8.9");
    }).verifyComplete();
    then(redisConnection).should().closeLater();
}
Also used : Status(org.springframework.boot.actuate.health.Status) Properties(java.util.Properties) StepVerifier(reactor.test.StepVerifier) RedisConnectionFailureException(org.springframework.data.redis.RedisConnectionFailureException) ReactiveServerCommands(org.springframework.data.redis.connection.ReactiveServerCommands) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ReactiveRedisClusterConnection(org.springframework.data.redis.connection.ReactiveRedisClusterConnection) BDDMockito.then(org.mockito.BDDMockito.then) Mono(reactor.core.publisher.Mono) Health(org.springframework.boot.actuate.health.Health) Test(org.junit.jupiter.api.Test) RedisConnectionException(io.lettuce.core.RedisConnectionException) BDDMockito.given(org.mockito.BDDMockito.given) ReactiveRedisConnection(org.springframework.data.redis.connection.ReactiveRedisConnection) ReactiveRedisConnectionFactory(org.springframework.data.redis.connection.ReactiveRedisConnectionFactory) ClusterInfo(org.springframework.data.redis.connection.ClusterInfo) Mockito.mock(org.mockito.Mockito.mock) Health(org.springframework.boot.actuate.health.Health) ReactiveRedisConnection(org.springframework.data.redis.connection.ReactiveRedisConnection) Properties(java.util.Properties) ReactiveServerCommands(org.springframework.data.redis.connection.ReactiveServerCommands) Test(org.junit.jupiter.api.Test)

Example 82 with Health

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

the class SolrHealthIndicatorTests method assertHealth.

private void assertHealth(SolrHealthIndicator healthIndicator, Status expectedStatus, int expectedStatusCode, String expectedPathType) {
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(expectedStatus);
    assertThat(health.getDetails().get("status")).isEqualTo(expectedStatusCode);
    assertThat(health.getDetails().get("detectedPathType")).isEqualTo(expectedPathType);
}
Also used : Health(org.springframework.boot.actuate.health.Health)

Example 83 with Health

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

the class SolrHealthIndicatorTests method healthWhenSolrConnectionFailsReturnsDown.

@Test
void healthWhenSolrConnectionFailsReturnsDown() throws Exception {
    SolrClient solrClient = mock(SolrClient.class);
    given(solrClient.request(any(CoreAdminRequest.class), isNull())).willThrow(new IOException("Connection failed"));
    SolrHealthIndicator healthIndicator = new SolrHealthIndicator(solrClient);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat((String) health.getDetails().get("error")).contains("Connection failed");
    then(solrClient).should().request(any(CoreAdminRequest.class), isNull());
    then(solrClient).shouldHaveNoMoreInteractions();
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) Health(org.springframework.boot.actuate.health.Health) CoreAdminRequest(org.apache.solr.client.solrj.request.CoreAdminRequest) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 84 with Health

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

the class DiskSpaceHealthIndicatorTests method diskSpaceIsUp.

@Test
void diskSpaceIsUp() {
    given(this.fileMock.exists()).willReturn(true);
    long freeSpace = THRESHOLD.toBytes() + 10;
    given(this.fileMock.getUsableSpace()).willReturn(freeSpace);
    given(this.fileMock.getTotalSpace()).willReturn(TOTAL_SPACE.toBytes());
    Health health = this.healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
    assertThat(health.getDetails().get("threshold")).isEqualTo(THRESHOLD.toBytes());
    assertThat(health.getDetails().get("free")).isEqualTo(freeSpace);
    assertThat(health.getDetails().get("total")).isEqualTo(TOTAL_SPACE.toBytes());
    assertThat(health.getDetails().get("exists")).isEqualTo(true);
}
Also used : Health(org.springframework.boot.actuate.health.Health) Test(org.junit.jupiter.api.Test)

Example 85 with Health

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

the class DiskSpaceHealthIndicatorTests method diskSpaceIsDown.

@Test
void diskSpaceIsDown() {
    given(this.fileMock.exists()).willReturn(true);
    long freeSpace = THRESHOLD.toBytes() - 10;
    given(this.fileMock.getUsableSpace()).willReturn(freeSpace);
    given(this.fileMock.getTotalSpace()).willReturn(TOTAL_SPACE.toBytes());
    Health health = this.healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat(health.getDetails().get("threshold")).isEqualTo(THRESHOLD.toBytes());
    assertThat(health.getDetails().get("free")).isEqualTo(freeSpace);
    assertThat(health.getDetails().get("total")).isEqualTo(TOTAL_SPACE.toBytes());
    assertThat(health.getDetails().get("exists")).isEqualTo(true);
}
Also used : Health(org.springframework.boot.actuate.health.Health) 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