Search in sources :

Example 86 with Health

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

the class DiskSpaceHealthIndicatorTests method whenPathDoesNotExistDiskSpaceIsDown.

@Test
void whenPathDoesNotExistDiskSpaceIsDown() {
    Health health = new DiskSpaceHealthIndicator(new File("does/not/exist"), THRESHOLD).health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat(health.getDetails().get("free")).isEqualTo(0L);
    assertThat(health.getDetails().get("total")).isEqualTo(0L);
    assertThat(health.getDetails().get("exists")).isEqualTo(false);
}
Also used : Health(org.springframework.boot.actuate.health.Health) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 87 with Health

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

the class Neo4jHealthContributorAutoConfigurationTests method defaultIndicatorCanBeReplaced.

@Test
void defaultIndicatorCanBeReplaced() {
    this.contextRunner.withUserConfiguration(Neo4jConfiguration.class, CustomIndicatorConfiguration.class).run((context) -> {
        assertThat(context).hasBean("neo4jHealthIndicator");
        Health health = context.getBean("neo4jHealthIndicator", HealthIndicator.class).health();
        assertThat(health.getDetails()).containsOnly(entry("test", true));
    });
}
Also used : Health(org.springframework.boot.actuate.health.Health) HealthIndicator(org.springframework.boot.actuate.health.HealthIndicator) AbstractHealthIndicator(org.springframework.boot.actuate.health.AbstractHealthIndicator) Neo4jHealthIndicator(org.springframework.boot.actuate.neo4j.Neo4jHealthIndicator) Neo4jReactiveHealthIndicator(org.springframework.boot.actuate.neo4j.Neo4jReactiveHealthIndicator) Test(org.junit.jupiter.api.Test)

Example 88 with Health

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

the class HazelcastHealthIndicatorTests method hazelcastUp.

@Test
void hazelcastUp() {
    new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class)).withPropertyValues("spring.hazelcast.config=hazelcast.xml").run((context) -> {
        HazelcastInstance hazelcast = context.getBean(HazelcastInstance.class);
        Health health = new HazelcastHealthIndicator(hazelcast).health();
        assertThat(health.getStatus()).isEqualTo(Status.UP);
        assertThat(health.getDetails()).containsOnlyKeys("name", "uuid").containsEntry("name", "actuator-hazelcast");
        assertThat(health.getDetails().get("uuid")).asString().isNotEmpty();
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Health(org.springframework.boot.actuate.health.Health) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) HazelcastAutoConfiguration(org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration) Test(org.junit.jupiter.api.Test)

Example 89 with Health

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

the class DataSourceHealthIndicatorTests method healthIndicatorWithDefaultSettings.

@Test
void healthIndicatorWithDefaultSettings() {
    this.indicator.setDataSource(this.dataSource);
    Health health = this.indicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
    assertThat(health.getDetails()).containsOnly(entry("database", "HSQL Database Engine"), entry("validationQuery", "isValid()"));
}
Also used : Health(org.springframework.boot.actuate.health.Health) Test(org.junit.jupiter.api.Test)

Example 90 with Health

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

the class DataSourceHealthIndicatorTests method healthIndicatorWithConnectionValidationFailure.

@Test
void healthIndicatorWithConnectionValidationFailure() throws SQLException {
    DataSource dataSource = mock(DataSource.class);
    Connection connection = mock(Connection.class);
    given(connection.isValid(0)).willReturn(false);
    given(connection.getMetaData()).willReturn(this.dataSource.getConnection().getMetaData());
    given(dataSource.getConnection()).willReturn(connection);
    this.indicator.setDataSource(dataSource);
    Health health = this.indicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat(health.getDetails()).containsOnly(entry("database", "HSQL Database Engine"), entry("validationQuery", "isValid()"));
}
Also used : Health(org.springframework.boot.actuate.health.Health) EmbeddedDatabaseConnection(org.springframework.boot.jdbc.EmbeddedDatabaseConnection) Connection(java.sql.Connection) SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) DataSource(javax.sql.DataSource) 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