use of reactor.core.publisher.Sinks.EmitFailureHandler.FAIL_FAST in project reactor-core by reactor.
the class FluxSpecTests method whenMappingFunctionThrowsMappedComposableAcceptsError.
@Test
public void whenMappingFunctionThrowsMappedComposableAcceptsError() {
// "When a mapping function throws an exception, the mapped composable accepts the error"
// given: "a source composable with a mapping function that throws an error"
Sinks.Many<Integer> source = Sinks.many().multicast().onBackpressureBuffer();
Flux<String> mapped = source.asFlux().map(it -> {
if (it == 1) {
throw new RuntimeException();
} else {
return "na";
}
});
LongAdder errors = new LongAdder();
mapped.doOnError(e -> errors.increment()).subscribe();
// when: "the source accepts a value"
source.emitNext(1, FAIL_FAST);
// then: "the error is passed on"
assertThat(errors.intValue()).isEqualTo(1);
}
use of reactor.core.publisher.Sinks.EmitFailureHandler.FAIL_FAST in project reactor-core by reactor.
the class FluxSpecTests method whenFilterFunctionThrowsFilteredComposableAcceptsError.
@Test
public void whenFilterFunctionThrowsFilteredComposableAcceptsError() {
// "When a filter function throws an exception, the filtered composable accepts the error"
// given: "a source composable with a filter function that throws an error"
Sinks.Many<Integer> source = Sinks.many().multicast().onBackpressureBuffer();
Flux<Integer> filtered = source.asFlux().filter(it -> {
if (it == 1) {
throw new RuntimeException();
} else {
return true;
}
});
LongAdder errors = new LongAdder();
filtered.doOnError(e -> errors.increment()).subscribe();
// when: "the source accepts a value"
source.emitNext(1, FAIL_FAST);
// then: "the error is passed on"
assertThat(errors.intValue()).isEqualTo(1);
}
use of reactor.core.publisher.Sinks.EmitFailureHandler.FAIL_FAST in project reactor-core by reactor.
the class FluxBufferTimeoutTest method requestedFromUpstreamShouldNotExceedDownstreamDemand.
@Test
public void requestedFromUpstreamShouldNotExceedDownstreamDemand() {
Sinks.Many<String> sink = Sinks.many().multicast().onBackpressureBuffer();
Flux<String> emitter = sink.asFlux();
AtomicLong requestedOutstanding = new AtomicLong(0);
VirtualTimeScheduler scheduler = VirtualTimeScheduler.create();
Flux<List<String>> flux = emitter.doOnRequest(requestedOutstanding::addAndGet).bufferTimeout(5, Duration.ofMillis(100), scheduler).doOnNext(list -> requestedOutstanding.addAndGet(0 - list.size()));
StepVerifier.withVirtualTime(() -> flux, () -> scheduler, 0).expectSubscription().then(() -> assertThat(requestedOutstanding).hasValue(0)).thenRequest(2).then(() -> assertThat(requestedOutstanding.get()).isEqualTo(10)).then(() -> sink.emitNext("a", FAIL_FAST)).thenAwait(Duration.ofMillis(100)).assertNext(s -> assertThat(s).containsExactly("a")).then(() -> assertThat(requestedOutstanding).hasValue(9)).thenRequest(1).then(() -> assertThat(requestedOutstanding).hasValue(10)).thenCancel().verify();
}
use of reactor.core.publisher.Sinks.EmitFailureHandler.FAIL_FAST in project reactor-core by reactor.
the class FluxMergeSequentialTest method testReentrantWork.
@Test
public void testReentrantWork() {
final Sinks.Many<Integer> subject = Sinks.unsafe().many().multicast().directBestEffort();
final AtomicBoolean once = new AtomicBoolean();
subject.asFlux().flatMapSequential(Flux::just).doOnNext(t -> {
if (once.compareAndSet(false, true)) {
subject.emitNext(2, FAIL_FAST);
}
}).subscribe(ts);
subject.emitNext(1, FAIL_FAST);
ts.assertNoError();
ts.assertNotComplete();
ts.assertValues(1, 2);
}
Aggregations