Java Code Examples for reactor.core.publisher.Flux#blockFirst()
The following examples show how to use
reactor.core.publisher.Flux#blockFirst() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: testcontainers-java File: TestcontainersR2DBCConnectionFactoryTest.java License: MIT License | 6 votes |
@Test public void reusesUntilConnectionFactoryIsClosed() { String url = "r2dbc:tc:postgresql:///db?TC_IMAGE_TAG=10-alpine"; ConnectionFactory connectionFactory = ConnectionFactories.get(url); Integer updated = Flux .usingWhen( connectionFactory.create(), connection -> { return Mono .from(connection.createStatement("CREATE TABLE test(id integer PRIMARY KEY)").execute()) .thenMany(connection.createStatement("INSERT INTO test(id) VALUES(123)").execute()) .flatMap(Result::getRowsUpdated); }, Connection::close ) .blockFirst(); assertThat(updated).isEqualTo(1); Flux<Long> select = Flux .usingWhen( Flux.defer(connectionFactory::create), connection -> { return Flux .from(connection.createStatement("SELECT COUNT(*) FROM test").execute()) .flatMap(it -> it.map((row, meta) -> (Long) row.get(0))); }, Connection::close ); Long rows = select.blockFirst(); assertThat(rows).isEqualTo(1); close(connectionFactory); Assertions .assertThatThrownBy(select::blockFirst) .isInstanceOf(PostgresqlException.class) // relation "X" does not exists // https://github.com/postgres/postgres/blob/REL_10_0/src/backend/utils/errcodes.txt#L349 .returns("42P01", e -> ((PostgresqlException) e).getErrorDetails().getCode()); }
Example 2
Source Project: smallrye-mutiny File: MultiConvertToTest.java License: Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testCreatingAFluxWithFailure() { Flux<Integer> flux = Multi.createFrom().<Integer> failure(new IOException("boom")).convert() .with(MultiReactorConverters.toFlux()); assertThat(flux).isNotNull(); try { flux.blockFirst(); fail("Exception expected"); } catch (Exception e) { assertThat(e).isInstanceOf(RuntimeException.class).hasCauseInstanceOf(IOException.class); } }
Example 3
Source Project: smallrye-mutiny File: UniConvertToTest.java License: Apache License 2.0 | 5 votes |
@Test public void testCreatingAFluxWithFailure() { Flux<Integer> flux = Uni.createFrom().<Integer> failure(new IOException("boom")).convert() .with(UniReactorConverters.toFlux()); assertThat(flux).isNotNull(); try { flux.blockFirst(); fail("Exception expected"); } catch (Exception e) { assertThat(e).isInstanceOf(RuntimeException.class).hasCauseInstanceOf(IOException.class); } }
Example 4
Source Project: spring-security-reactive File: ExpressionReactiveAccessDecisionManager.java License: Apache License 2.0 | 5 votes |
@Override public Mono<Boolean> decide(Authentication authentication, ServerWebExchange object, Flux<ConfigAttribute> configAttributes) { ConfigAttribute attribute = configAttributes.blockFirst(); EvaluationContext context = handler.createEvaluationContext(authentication, object); Expression expression = handler.getExpressionParser().parseExpression(attribute.getAttribute()); return Mono.just(ExpressionUtils.evaluateAsBoolean(expression, context)); }
Example 5
Source Project: spring-cloud-function File: SpringFunctionAdapterInitializerTests.java License: Apache License 2.0 | 5 votes |
@Test public void functionApp() { this.initializer = new AbstractSpringFunctionAdapterInitializer<Object>(FluxFunctionApp.class) { }; this.initializer.initialize(null); Flux<?> result = Flux.from(this.initializer.apply(Flux.just(new Foo()))); Object o = result.blockFirst(); assertThat(result.blockFirst()).isInstanceOf(Bar.class); }
Example 6
Source Project: spring-cloud-sleuth File: SleuthSpanCreatorAspectFluxTests.java License: Apache License 2.0 | 5 votes |
@Test public void shouldReturnNewSpanFromTraceContext() { Flux<Long> flux = this.testBean.newSpanInTraceContext(); Long newSpanId = flux.blockFirst(); Awaitility.await().untilAsserted(() -> { then(this.spans).hasSize(1); then(this.spans.get(0).name()).isEqualTo("span-in-trace-context"); then(this.spans.get(0).id()).isEqualTo(toHexString(newSpanId)); then(this.tracer.currentSpan()).isNull(); }); }
Example 7
Source Project: spring-cloud-sleuth File: SleuthSpanCreatorAspectFluxTests.java License: Apache License 2.0 | 5 votes |
@Test public void shouldReturnNewSpanFromSubscriberContext() { Flux<Long> flux = this.testBean.newSpanInSubscriberContext(); Long newSpanId = flux.blockFirst(); Awaitility.await().untilAsserted(() -> { then(this.spans).hasSize(1); then(this.spans.get(0).name()).isEqualTo("span-in-subscriber-context"); then(this.spans.get(0).id()).isEqualTo(toHexString(newSpanId)); then(this.tracer.currentSpan()).isNull(); }); }
Example 8
Source Project: smallrye-reactive-streams-operators File: FluxFromRSPublisherTest.java License: Apache License 2.0 | 4 votes |
@Override protected String getOne(Flux instance) { return (String) instance.blockFirst(); }
Example 9
Source Project: smallrye-reactive-streams-operators File: FluxFromCompletionStageTest.java License: Apache License 2.0 | 4 votes |
@Override protected String getOne(Flux instance) { return (String) instance.blockFirst(); }