Search in sources :

Example 41 with Health

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

the class DataSourceHealthIndicatorTests method healthIndicatorCloseConnection.

@Test
void healthIndicatorCloseConnection() throws Exception {
    DataSource dataSource = mock(DataSource.class);
    Connection connection = mock(Connection.class);
    given(connection.getMetaData()).willReturn(this.dataSource.getConnection().getMetaData());
    given(dataSource.getConnection()).willReturn(connection);
    this.indicator.setDataSource(dataSource);
    Health health = this.indicator.health();
    assertThat(health.getDetails().get("database")).isNotNull();
    then(connection).should(times(2)).close();
}
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)

Example 42 with Health

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

the class DataSourceHealthIndicatorTests method healthIndicatorWithCustomValidationQuery.

@Test
void healthIndicatorWithCustomValidationQuery() {
    String customValidationQuery = "SELECT COUNT(*) from FOO";
    new JdbcTemplate(this.dataSource).execute("CREATE TABLE FOO (id INTEGER IDENTITY PRIMARY KEY)");
    this.indicator.setDataSource(this.dataSource);
    this.indicator.setQuery(customValidationQuery);
    Health health = this.indicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
    assertThat(health.getDetails()).containsOnly(entry("database", "HSQL Database Engine"), entry("result", 0L), entry("validationQuery", customValidationQuery));
}
Also used : Health(org.springframework.boot.actuate.health.Health) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Test(org.junit.jupiter.api.Test)

Example 43 with Health

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

the class DataSourceHealthIndicatorTests method healthIndicatorWithInvalidValidationQuery.

@Test
void healthIndicatorWithInvalidValidationQuery() {
    String invalidValidationQuery = "SELECT COUNT(*) from BAR";
    this.indicator.setDataSource(this.dataSource);
    this.indicator.setQuery(invalidValidationQuery);
    Health health = this.indicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat(health.getDetails()).contains(entry("database", "HSQL Database Engine"), entry("validationQuery", invalidValidationQuery));
    assertThat(health.getDetails()).containsOnlyKeys("database", "error", "validationQuery");
}
Also used : Health(org.springframework.boot.actuate.health.Health) Test(org.junit.jupiter.api.Test)

Example 44 with Health

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

the class InfluxDbHealthIndicatorTests method influxDbIsUp.

@Test
void influxDbIsUp() {
    Pong pong = mock(Pong.class);
    given(pong.getVersion()).willReturn("0.9");
    InfluxDB influxDb = mock(InfluxDB.class);
    given(influxDb.ping()).willReturn(pong);
    InfluxDbHealthIndicator healthIndicator = new InfluxDbHealthIndicator(influxDb);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
    assertThat(health.getDetails().get("version")).isEqualTo("0.9");
    then(influxDb).should().ping();
}
Also used : Health(org.springframework.boot.actuate.health.Health) InfluxDB(org.influxdb.InfluxDB) Pong(org.influxdb.dto.Pong) Test(org.junit.jupiter.api.Test)

Example 45 with Health

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

the class InfluxDbHealthIndicatorTests method influxDbIsDown.

@Test
void influxDbIsDown() {
    InfluxDB influxDb = mock(InfluxDB.class);
    given(influxDb.ping()).willThrow(new InfluxDBException(new IOException("Connection failed")));
    InfluxDbHealthIndicator healthIndicator = new InfluxDbHealthIndicator(influxDb);
    Health health = healthIndicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat((String) health.getDetails().get("error")).contains("Connection failed");
    then(influxDb).should().ping();
}
Also used : InfluxDBException(org.influxdb.InfluxDBException) Health(org.springframework.boot.actuate.health.Health) InfluxDB(org.influxdb.InfluxDB) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Aggregations

Health (org.springframework.boot.actuate.health.Health)118 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 Test (org.junit.Test)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