Search in sources :

Example 1 with ReactiveHealthIndicator

use of org.springframework.boot.actuate.health.ReactiveHealthIndicator 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();
    }
}
Also used : ReactiveHealthIndicator(org.springframework.boot.actuate.health.ReactiveHealthIndicator) ConnectionFactory(io.r2dbc.spi.ConnectionFactory) Status(org.springframework.boot.actuate.health.Status) StepVerifier(reactor.test.StepVerifier) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) H2ConnectionOption(io.r2dbc.h2.H2ConnectionOption) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) ReactiveHealthIndicator(org.springframework.boot.actuate.health.ReactiveHealthIndicator) Assertions.entry(org.assertj.core.api.Assertions.entry) Connection(io.r2dbc.spi.Connection) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) BDDMockito.given(org.mockito.BDDMockito.given) Result(io.r2dbc.spi.Result) H2ConnectionFactory(io.r2dbc.h2.H2ConnectionFactory) ValidationDepth(io.r2dbc.spi.ValidationDepth) Collections(java.util.Collections) CloseableConnectionFactory(io.r2dbc.h2.CloseableConnectionFactory) Mockito.mock(org.mockito.Mockito.mock) CloseableConnectionFactory(io.r2dbc.h2.CloseableConnectionFactory) StepVerifier(reactor.test.StepVerifier) Result(io.r2dbc.spi.Result) Test(org.junit.jupiter.api.Test)

Example 2 with ReactiveHealthIndicator

use of org.springframework.boot.actuate.health.ReactiveHealthIndicator 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();
    }
}
Also used : ReactiveHealthIndicator(org.springframework.boot.actuate.health.ReactiveHealthIndicator) ConnectionFactory(io.r2dbc.spi.ConnectionFactory) Status(org.springframework.boot.actuate.health.Status) StepVerifier(reactor.test.StepVerifier) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) H2ConnectionOption(io.r2dbc.h2.H2ConnectionOption) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) ReactiveHealthIndicator(org.springframework.boot.actuate.health.ReactiveHealthIndicator) Assertions.entry(org.assertj.core.api.Assertions.entry) Connection(io.r2dbc.spi.Connection) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) BDDMockito.given(org.mockito.BDDMockito.given) Result(io.r2dbc.spi.Result) H2ConnectionFactory(io.r2dbc.h2.H2ConnectionFactory) ValidationDepth(io.r2dbc.spi.ValidationDepth) Collections(java.util.Collections) CloseableConnectionFactory(io.r2dbc.h2.CloseableConnectionFactory) Mockito.mock(org.mockito.Mockito.mock) CloseableConnectionFactory(io.r2dbc.h2.CloseableConnectionFactory) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Aggregations

CloseableConnectionFactory (io.r2dbc.h2.CloseableConnectionFactory)2 H2ConnectionFactory (io.r2dbc.h2.H2ConnectionFactory)2 H2ConnectionOption (io.r2dbc.h2.H2ConnectionOption)2 Connection (io.r2dbc.spi.Connection)2 ConnectionFactory (io.r2dbc.spi.ConnectionFactory)2 Result (io.r2dbc.spi.Result)2 ValidationDepth (io.r2dbc.spi.ValidationDepth)2 Collections (java.util.Collections)2 UUID (java.util.UUID)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.entry (org.assertj.core.api.Assertions.entry)2 Test (org.junit.jupiter.api.Test)2 BDDMockito.given (org.mockito.BDDMockito.given)2 Mockito.mock (org.mockito.Mockito.mock)2 ReactiveHealthIndicator (org.springframework.boot.actuate.health.ReactiveHealthIndicator)2 Status (org.springframework.boot.actuate.health.Status)2 Flux (reactor.core.publisher.Flux)2 Mono (reactor.core.publisher.Mono)2 StepVerifier (reactor.test.StepVerifier)2