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();
}
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));
}
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");
}
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();
}
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();
}
Aggregations