use of reactor.test.util.TestLogger in project reactor-core by reactor.
the class SinkOneMulticastTest method doubleError.
@Test
void doubleError() {
TestLogger testLogger = new TestLogger();
LoggerUtils.enableCaptureWith(testLogger);
try {
SinkOneMulticast<String> sink = new SinkOneMulticast<>();
sink.emitError(new Exception("test"), Sinks.EmitFailureHandler.FAIL_FAST);
sink.emitError(new Exception("test2"), Sinks.EmitFailureHandler.FAIL_FAST);
Assertions.assertThat(testLogger.getErrContent()).contains("Operator called default onErrorDropped").contains("test2");
} finally {
LoggerUtils.disableCapture();
}
}
use of reactor.test.util.TestLogger 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.util.TestLogger 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.util.TestLogger 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.util.TestLogger in project reactor-core by reactor.
the class SignalLoggerTests method safeLogsWhenPassingQueueSubscription.
@Test
public void safeLogsWhenPassingQueueSubscription() {
TestLogger logger = new TestLogger();
SignalLogger signalLogger = new SignalLogger<>(Flux.empty(), null, Level.INFO, false, it -> logger);
signalLogger.safeLog(SignalType.ON_NEXT, new FluxPeekFuseableTest.AssertQueueSubscription<>());
assertThat(logger.getOutContent()).contains("A Fuseable Subscription has been passed to the logging framework, this is generally a sign of a misplaced log(), " + "eg. 'window(2).log()' instead of 'window(2).flatMap(w -> w.log())'").contains("onNext(reactor.core.publisher.FluxPeekFuseableTest$AssertQueueSubscription");
}
Aggregations