use of reactor.test.util.TestLogger in project reactor-core by reactor.
the class LambdaMonoSubscriberTest method onNextConsumerFatalDoesntTriggerCancellation.
@Test
public void onNextConsumerFatalDoesntTriggerCancellation() {
TestLogger testLogger = new TestLogger();
LoggerUtils.enableCaptureWith(testLogger);
try {
LambdaMonoSubscriber<String> tested = new LambdaMonoSubscriber<>(value -> {
throw new OutOfMemoryError();
}, // no errorConsumer so that we use onErrorDropped
null, () -> {
}, null);
TestSubscription testSubscription = new TestSubscription();
tested.onSubscribe(testSubscription);
// the error is expected to be thrown as it is fatal, so it doesn't go through onErrorDropped
assertThatExceptionOfType(OutOfMemoryError.class).isThrownBy(() -> tested.onNext("foo"));
Assertions.assertThat(testLogger.getErrContent()).isEmpty();
assertThat(testSubscription.isCancelled).as("subscription isCancelled").isFalse();
} finally {
LoggerUtils.disableCapture();
}
}
use of reactor.test.util.TestLogger in project reactor-core by reactor.
the class LambdaMonoSubscriberTest method onNextConsumerExceptionNonFatalTriggersCancellation.
@Test
public void onNextConsumerExceptionNonFatalTriggersCancellation() {
TestLogger testLogger = new TestLogger();
LoggerUtils.enableCaptureWith(testLogger);
try {
LambdaMonoSubscriber<String> tested = new LambdaMonoSubscriber<>(value -> {
throw new IllegalArgumentException();
}, // no errorConsumer so that we use onErrorDropped
null, () -> {
}, null);
TestSubscription testSubscription = new TestSubscription();
tested.onSubscribe(testSubscription);
// as Mono is single-value, it cancels early on onNext. this leads to an exception
// during onNext to be bubbled up as a BubbledException, not propagated through onNext
tested.onNext("foo");
Assertions.assertThat(testLogger.getErrContent()).contains("Operator called default onErrorDropped").contains("IllegalArgumentException");
assertThat(testSubscription.isCancelled).as("subscription isCancelled").isTrue();
} finally {
LoggerUtils.disableCapture();
}
}
use of reactor.test.util.TestLogger in project reactor-core by reactor.
the class FluxFlatMapTest method failDoubleErrorTerminated.
// FIXME use Violation.NO_CLEANUP_ON_TERMINATE
@Test
public void failDoubleErrorTerminated() {
TestLogger testLogger = new TestLogger();
LoggerUtils.enableCaptureWith(testLogger);
try {
StepVerifier.create(Flux.from(s -> {
s.onSubscribe(Operators.emptySubscription());
Exceptions.terminate(FluxFlatMap.FlatMapMain.ERROR, (FluxFlatMap.FlatMapMain<?, ?>) s);
((FluxFlatMap.FlatMapMain<?, ?>) s).done = true;
((FluxFlatMap.FlatMapMain<?, ?>) s).drain(null);
s.onError(new Exception("test"));
}).flatMap(Flux::just)).verifyComplete();
assertThat(testLogger.getErrContent()).contains("Operator called default onErrorDropped").contains("java.lang.Exception: test");
} finally {
LoggerUtils.disableCapture();
}
}
use of reactor.test.util.TestLogger in project reactor-core by reactor.
the class MonoPeekAfterTest method afterSuccessOrErrorCallbackFailureInterruptsOnNextAndThrows.
@Test
public void afterSuccessOrErrorCallbackFailureInterruptsOnNextAndThrows() {
TestLogger testLogger = new TestLogger();
LoggerUtils.enableCaptureWith(testLogger);
try {
LongAdder invoked = new LongAdder();
try {
// Because of doAfterSuccessOrError, which will be removed in 3.5.0
@SuppressWarnings("deprecation") Mono<String> mono = Mono.just("foo").doAfterSuccessOrError((v, t) -> {
invoked.increment();
throw new IllegalArgumentException(v);
});
StepVerifier.create(mono).expectNext(// irrelevant
"bar").expectErrorMessage(// irrelevant
"baz").verify();
fail("Exception expected");
} catch (Throwable t) {
Throwable e = Exceptions.unwrap(t);
assertThat(e).isExactlyInstanceOf(AssertionError.class).hasMessage("expectation \"expectNext(bar)\" failed (expected value: bar; actual value: foo)");
}
assertThat(invoked.intValue()).isEqualTo(1);
Assertions.assertThat(testLogger.getErrContent()).contains("Operator called default onErrorDropped").contains("IllegalArgumentException").contains("foo");
} finally {
LoggerUtils.disableCapture();
}
}
use of reactor.test.util.TestLogger in project reactor-core by reactor.
the class MonoPeekAfterTest method afterTerminateCallbackFailureInterruptsOnNextAndThrows.
@Test
public void afterTerminateCallbackFailureInterruptsOnNextAndThrows() {
TestLogger testLogger = new TestLogger();
LoggerUtils.enableCaptureWith(testLogger);
try {
LongAdder invoked = new LongAdder();
try {
// Because of doAfterSuccessOrError, which will be removed in 3.5.0
@SuppressWarnings("deprecation") Mono<String> mono = Mono.just("foo").doAfterSuccessOrError((v, t) -> {
invoked.increment();
throw new IllegalArgumentException(v);
});
StepVerifier.create(mono).expectNext(// irrelevant
"bar").expectErrorMessage(// irrelevant
"baz").verify();
fail("Exception expected");
} catch (Throwable t) {
Throwable e = Exceptions.unwrap(t);
assertThat(e).isExactlyInstanceOf(AssertionError.class).hasMessage("expectation \"expectNext(bar)\" failed (expected value: bar; actual value: foo)");
}
assertThat(invoked.intValue()).isEqualTo(1);
Assertions.assertThat(testLogger.getErrContent()).contains("Operator called default onErrorDropped").contains("foo").contains("IllegalArgumentException");
} finally {
LoggerUtils.disableCapture();
}
}
Aggregations