use of io.r2dbc.h2.CloseableConnectionFactory in project spring-boot by spring-projects.
the class ConnectionFactoryHealthIndicatorTests method healthIndicatorWhenDatabaseUpWithSuccessValidationQuery.
@Test
void healthIndicatorWhenDatabaseUpWithSuccessValidationQuery() {
CloseableConnectionFactory connectionFactory = createTestDatabase();
try {
String customValidationQuery = "SELECT COUNT(*) from HEALTH_TEST";
String createTableStatement = "CREATE TABLE HEALTH_TEST (id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY)";
Mono.from(connectionFactory.create()).flatMapMany((it) -> Flux.from(it.createStatement(createTableStatement).execute()).flatMap(Result::getRowsUpdated).thenMany(it.close())).as(StepVerifier::create).verifyComplete();
ReactiveHealthIndicator healthIndicator = new ConnectionFactoryHealthIndicator(connectionFactory, customValidationQuery);
healthIndicator.health().as(StepVerifier::create).assertNext((actual) -> {
assertThat(actual.getStatus()).isEqualTo(Status.UP);
assertThat(actual.getDetails()).containsOnly(entry("database", "H2"), entry("result", 0L), entry("validationQuery", customValidationQuery));
}).verifyComplete();
} finally {
StepVerifier.create(connectionFactory.close()).verifyComplete();
}
}
use of io.r2dbc.h2.CloseableConnectionFactory in project spring-boot by spring-projects.
the class ConnectionFactoryHealthIndicatorTests method healthIndicatorWhenDatabaseUpWithConnectionValidation.
@Test
void healthIndicatorWhenDatabaseUpWithConnectionValidation() {
CloseableConnectionFactory connectionFactory = createTestDatabase();
try {
ConnectionFactoryHealthIndicator healthIndicator = new ConnectionFactoryHealthIndicator(connectionFactory);
healthIndicator.health().as(StepVerifier::create).assertNext((actual) -> {
assertThat(actual.getStatus()).isEqualTo(Status.UP);
assertThat(actual.getDetails()).containsOnly(entry("database", "H2"), entry("validationQuery", "validate(REMOTE)"));
}).verifyComplete();
} finally {
StepVerifier.create(connectionFactory.close()).verifyComplete();
}
}
use of io.r2dbc.h2.CloseableConnectionFactory in project spring-boot by spring-projects.
the class ConnectionFactoryHealthIndicatorTests method healthIndicatorWhenDatabaseUpWithFailureValidationQuery.
@Test
void healthIndicatorWhenDatabaseUpWithFailureValidationQuery() {
CloseableConnectionFactory connectionFactory = createTestDatabase();
try {
String invalidValidationQuery = "SELECT COUNT(*) from DOES_NOT_EXIST";
ReactiveHealthIndicator healthIndicator = new ConnectionFactoryHealthIndicator(connectionFactory, invalidValidationQuery);
healthIndicator.health().as(StepVerifier::create).assertNext((actual) -> {
assertThat(actual.getStatus()).isEqualTo(Status.DOWN);
assertThat(actual.getDetails()).contains(entry("database", "H2"), entry("validationQuery", invalidValidationQuery));
assertThat(actual.getDetails()).containsOnlyKeys("database", "error", "validationQuery");
}).verifyComplete();
} finally {
StepVerifier.create(connectionFactory.close()).verifyComplete();
}
}
Aggregations