use of reactor.test.ParameterizedTestWithName in project reactor-core by reactor.
the class FluxUsingWhenTest method apiCancelFailure.
@ParameterizedTestWithName
@MethodSource("sourcesFullTransaction")
public void apiCancelFailure(Flux<String> transaction) {
TestLogger testLogger = new TestLogger();
Loggers.useCustomLoggers(s -> testLogger);
try {
final AtomicReference<TestResource> ref = new AtomicReference<>();
Flux<String> flux = Flux.usingWhen(Mono.fromCallable(TestResource::new), d -> {
ref.set(d);
return transaction;
}, TestResource::commit, TestResource::rollback, TestResource::cancelError);
StepVerifier.create(flux.take(1), 1).expectNext("Transaction started").verifyComplete();
assertThat(ref.get()).isNotNull().matches(tr -> !tr.commitProbe.wasSubscribed(), "no commit").matches(tr -> !tr.rollbackProbe.wasSubscribed(), "no rollback").matches(tr -> tr.cancelProbe.wasSubscribed(), "cancel method used");
// since the CancelInner is subscribed in a fire-and-forget fashion, the log comes later
// the test must be done before the finally, lest the error message be printed too late for TestLogger to catch it
Awaitility.await().atMost(1, TimeUnit.SECONDS).untilAsserted(() -> assertThat(testLogger.getErrContent()).startsWith("[ WARN]").contains("Async resource cleanup failed after cancel - java.lang.ArithmeticException: / by zero"));
} finally {
Loggers.resetLoggerFactory();
}
}
use of reactor.test.ParameterizedTestWithName in project reactor-core by reactor.
the class FluxUsingWhenTest method apiCancelGeneratingNullLogs.
@ParameterizedTestWithName
@MethodSource("sourcesFullTransaction")
public void apiCancelGeneratingNullLogs(Flux<String> transactionToCancel) {
TestLogger testLogger = new TestLogger();
Loggers.useCustomLoggers(s -> testLogger);
try {
final AtomicReference<TestResource> ref = new AtomicReference<>();
Flux<String> flux = Flux.usingWhen(Mono.fromCallable(TestResource::new), d -> {
ref.set(d);
return transactionToCancel;
}, TestResource::commit, TestResource::rollback, TestResource::cancelNull);
StepVerifier.create(flux.take(1), 1).expectNext("Transaction started").verifyComplete();
assertThat(ref.get()).isNotNull().matches(tr -> !tr.commitProbe.wasSubscribed(), "no commit").matches(tr -> !tr.rollbackProbe.wasSubscribed(), "no rollback").matches(tr -> !tr.cancelProbe.wasSubscribed(), "cancel method short-circuited");
} finally {
Loggers.resetLoggerFactory();
}
assertThat(testLogger.getErrContent()).contains("[ WARN] (" + Thread.currentThread().getName() + ") " + "Error generating async resource cleanup during onCancel - java.lang.NullPointerException");
}
use of reactor.test.ParameterizedTestWithName in project reactor-core by reactor.
the class FluxUsingWhenTest method cancelWithHandlerFailure.
@ParameterizedTestWithName
@MethodSource("sources01")
public void cancelWithHandlerFailure(Flux<String> source) {
TestResource testResource = new TestResource();
final TestLogger tl = new TestLogger();
Loggers.useCustomLoggers(name -> tl);
try {
Flux<String> test = Flux.usingWhen(Mono.just(testResource), tr -> source, TestResource::commit, TestResource::rollback, r -> r.cancel().concatWith(Mono.error(new IllegalStateException("cancel error")))).take(2);
StepVerifier.create(test).expectNext("0", "1").verifyComplete();
testResource.commitProbe.assertWasNotSubscribed();
testResource.rollbackProbe.assertWasNotSubscribed();
testResource.cancelProbe.assertWasSubscribed();
} finally {
Loggers.resetLoggerFactory();
}
assertThat(tl.getErrContent()).contains("Async resource cleanup failed after cancel").contains("java.lang.IllegalStateException: cancel error");
}
use of reactor.test.ParameterizedTestWithName in project reactor-core by reactor.
the class FluxStreamTest method fromStreamWithFailingIteratorNextInFusion.
// see https://github.com/reactor/reactor-core/issues/2761
@ParameterizedTestWithName
@ValueSource(booleans = { false, true })
void fromStreamWithFailingIteratorNextInFusion(boolean conditionalSubscriber) throws InterruptedException {
CountDownLatch thrown = new CountDownLatch(1);
Iterator<Integer> throwingIterator = new Iterator<Integer>() {
int count = 0;
@Override
public boolean hasNext() {
return count < 3;
}
@Override
public Integer next() {
if (++count > 2) {
thrown.countDown();
throw new RuntimeException("boom");
} else {
return count;
}
}
};
CompletableFuture<Throwable> error = new CompletableFuture<>();
CountDownLatch terminated = new CountDownLatch(1);
Subscriber<Integer> simpleAsyncSubscriber = new BaseSubscriber<Integer>() {
@Override
protected void hookOnSubscribe(Subscription subscription) {
request(1);
}
@Override
protected void hookOnNext(Integer value) {
// proceed on a different thread
CompletableFuture.runAsync(() -> request(1));
}
@Override
protected void hookOnError(Throwable throwable) {
// expected to be called, but isn't
error.complete(throwable);
}
@Override
protected void hookOnComplete() {
// not expected to happen
error.complete(null);
}
};
Flux<Integer> flux = Flux.fromStream(StreamSupport.stream(Spliterators.spliteratorUnknownSize(throwingIterator, 0), false));
if (conditionalSubscriber) {
flux = flux.filter(v -> true);
}
flux.publishOn(Schedulers.boundedElastic()).doOnTerminate(terminated::countDown).subscribe(simpleAsyncSubscriber);
assertThat(thrown.await(3, TimeUnit.SECONDS)).isTrue();
assertThat(terminated.await(2, TimeUnit.SECONDS)).withFailMessage("Pipeline should terminate").isTrue();
assertThat(error).succeedsWithin(Duration.ofSeconds(2), InstanceOfAssertFactories.THROWABLE).hasMessage("boom");
}
use of reactor.test.ParameterizedTestWithName in project reactor-core by reactor.
the class FluxDoOnEachTest method normal.
@ParameterizedTestWithName
@MethodSource("sources12Complete")
void normal(Flux<Integer> source) {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
AtomicReference<Integer> onNext = new AtomicReference<>();
AtomicReference<Throwable> onError = new AtomicReference<>();
AtomicBoolean onComplete = new AtomicBoolean();
LongAdder state = new LongAdder();
source.doOnEach(s -> {
if (s.isOnNext()) {
onNext.set(s.get());
state.increment();
} else if (s.isOnError()) {
onError.set(s.getThrowable());
} else if (s.isOnComplete()) {
onComplete.set(true);
}
}).filter(t -> true).subscribe(ts);
assertThat(onNext).hasValue(2);
assertThat(onError).hasValue(null);
assertThat(onComplete).isTrue();
assertThat(state.intValue()).isEqualTo(2);
}
Aggregations