use of io.r2dbc.spi.Result 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.spi.Result in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method selectShouldEmitAllValues.
@Test
void selectShouldEmitAllValues() {
MockRowMetadata metadata = MockRowMetadata.builder().columnMetadata(MockColumnMetadata.builder().name("name").javaType(String.class).build()).build();
MockResult result = MockResult.builder().row(MockRow.builder().identified(0, Object.class, "Walter").metadata(metadata).build(), MockRow.builder().identified(0, Object.class, "White").metadata(metadata).build()).build();
mockStatementFor("SELECT * FROM person", result);
DatabaseClient databaseClient = databaseClientBuilder.build();
databaseClient.sql("SELECT * FROM person").map(row -> row.get(0)).all().as(StepVerifier::create).expectNext("Walter").expectNext("White").verifyComplete();
}
use of io.r2dbc.spi.Result in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method shouldApplyStatementFilterFunctions.
@Test
void shouldApplyStatementFilterFunctions() {
MockResult result = MockResult.builder().build();
Statement statement = mockStatement(result);
DatabaseClient databaseClient = databaseClientBuilder.build();
databaseClient.sql("SELECT").filter((s, next) -> next.execute(s.returnGeneratedValues("foo"))).filter((s, next) -> next.execute(s.returnGeneratedValues("bar"))).fetch().all().as(StepVerifier::create).verifyComplete();
InOrder inOrder = inOrder(statement);
inOrder.verify(statement).returnGeneratedValues("foo");
inOrder.verify(statement).returnGeneratedValues("bar");
inOrder.verify(statement).execute();
inOrder.verifyNoMoreInteractions();
}
use of io.r2dbc.spi.Result in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method shouldApplySimpleStatementFilterFunctions.
@Test
void shouldApplySimpleStatementFilterFunctions() {
MockResult result = mockSingleColumnEmptyResult();
Statement statement = mockStatement(result);
DatabaseClient databaseClient = databaseClientBuilder.build();
databaseClient.sql("SELECT").filter(s -> s.returnGeneratedValues("foo")).filter(s -> s.returnGeneratedValues("bar")).fetch().all().as(StepVerifier::create).verifyComplete();
InOrder inOrder = inOrder(statement);
inOrder.verify(statement).returnGeneratedValues("foo");
inOrder.verify(statement).returnGeneratedValues("bar");
inOrder.verify(statement).execute();
inOrder.verifyNoMoreInteractions();
}
use of io.r2dbc.spi.Result in project jOOQ by jOOQ.
the class R2DBC method block.
@SuppressWarnings("unchecked")
static final <T> T block(Publisher<? extends T> publisher) {
Object complete = new Object();
LinkedBlockingQueue<Object> queue = new LinkedBlockingQueue<>();
publisher.subscribe(subscriber(s -> s.request(1), queue::add, queue::add, () -> queue.add(complete)));
try {
Object result = queue.take();
if (result instanceof Throwable)
throw new DataAccessException("Exception when blocking on publisher", (Throwable) result);
else if (result == complete)
return null;
else
return (T) result;
} catch (InterruptedException e) {
throw new DataAccessException("Exception when blocking on publisher", e);
}
}
Aggregations