use of reactor.test.StepVerifier in project spring-boot by spring-projects.
the class ConnectionFactoryHealthIndicatorTests method healthIndicatorWhenConnectionValidationFails.
@Test
void healthIndicatorWhenConnectionValidationFails() {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
given(connectionFactory.getMetadata()).willReturn(() -> "mock");
Connection connection = mock(Connection.class);
given(connection.validate(ValidationDepth.REMOTE)).willReturn(Mono.just(false));
given(connection.close()).willReturn(Mono.empty());
given(connectionFactory.create()).willAnswer((invocation) -> Mono.just(connection));
ConnectionFactoryHealthIndicator healthIndicator = new ConnectionFactoryHealthIndicator(connectionFactory);
healthIndicator.health().as(StepVerifier::create).assertNext((actual) -> {
assertThat(actual.getStatus()).isEqualTo(Status.DOWN);
assertThat(actual.getDetails()).containsOnly(entry("database", "mock"), entry("validationQuery", "validate(REMOTE)"));
}).verifyComplete();
}
use of reactor.test.StepVerifier 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 reactor.test.StepVerifier 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 reactor.test.StepVerifier in project spring-boot by spring-projects.
the class ConnectionPoolMetricsTests method connectionFactoryIsInstrumented.
@Test
void connectionFactoryIsInstrumented() {
SimpleMeterRegistry registry = new SimpleMeterRegistry();
ConnectionPool connectionPool = new ConnectionPool(ConnectionPoolConfiguration.builder(this.connectionFactory).initialSize(3).maxSize(7).build());
ConnectionPoolMetrics metrics = new ConnectionPoolMetrics(connectionPool, "test-pool", Tags.of(testTag, regionTag));
metrics.bindTo(registry);
// acquire two connections
connectionPool.create().as(StepVerifier::create).expectNextCount(1).verifyComplete();
connectionPool.create().as(StepVerifier::create).expectNextCount(1).verifyComplete();
assertGauge(registry, "r2dbc.pool.acquired", 2);
assertGauge(registry, "r2dbc.pool.allocated", 3);
assertGauge(registry, "r2dbc.pool.idle", 1);
assertGauge(registry, "r2dbc.pool.pending", 0);
assertGauge(registry, "r2dbc.pool.max.allocated", 7);
assertGauge(registry, "r2dbc.pool.max.pending", Integer.MAX_VALUE);
}
use of reactor.test.StepVerifier in project spring-boot by spring-projects.
the class Neo4jReactiveHealthIndicatorTests method neo4jIsDown.
@Test
void neo4jIsDown() {
Driver driver = mock(Driver.class);
given(driver.rxSession(any(SessionConfig.class))).willThrow(ServiceUnavailableException.class);
Neo4jReactiveHealthIndicator healthIndicator = new Neo4jReactiveHealthIndicator(driver);
healthIndicator.health().as(StepVerifier::create).consumeNextWith((health) -> {
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat(health.getDetails()).containsKeys("error");
}).verifyComplete();
}
Aggregations