use of reactor.test.util.TestLogger in project reactor-core by reactor.
the class FluxPeekTest method afterTerminateCallbackErrorDoesNotInvokeOnError.
@Test
public void afterTerminateCallbackErrorDoesNotInvokeOnError() {
TestLogger testLogger = new TestLogger();
LoggerUtils.enableCaptureWith(testLogger);
try {
IllegalStateException e = new IllegalStateException("test");
AtomicReference<Throwable> errorCallbackCapture = new AtomicReference<>();
FluxPeek<String> flux = new FluxPeek<>(Flux.empty(), null, null, errorCallbackCapture::set, null, () -> {
throw e;
}, null, null);
AssertSubscriber<String> ts = AssertSubscriber.create();
flux.subscribe(ts);
ts.assertNoValues();
ts.assertComplete();
assertThat(errorCallbackCapture.get()).isNull();
assertThat(testLogger.getErrContent()).contains("Operator called default onErrorDropped").contains(e.toString());
} finally {
LoggerUtils.disableCapture();
}
}
use of reactor.test.util.TestLogger in project reactor-core by reactor.
the class FluxPeekTest method afterTerminateCallbackErrorAndErrorCallbackError.
@Test
public void afterTerminateCallbackErrorAndErrorCallbackError() {
TestLogger testLogger = new TestLogger();
LoggerUtils.enableCaptureWith(testLogger);
try {
IllegalStateException error1 = new IllegalStateException("afterTerminate");
IllegalArgumentException error2 = new IllegalArgumentException("error");
FluxPeek<String> flux = new FluxPeek<>(Flux.empty(), null, null, e -> {
throw error2;
}, null, () -> {
throw error1;
}, null, null);
AssertSubscriber<String> ts = AssertSubscriber.create();
flux.subscribe(ts);
assertThat(testLogger.getErrContent()).contains("Operator called default onErrorDropped").contains(error1.getMessage());
assertThat(error2.getSuppressed()).hasSize(0);
// error2 is never thrown
ts.assertNoValues();
ts.assertComplete();
} finally {
LoggerUtils.disableCapture();
}
}
use of reactor.test.util.TestLogger in project reactor-core by reactor.
the class FluxPeekFuseableTest method afterTerminateCallbackErrorDoesNotInvokeOnError.
@Test
public void afterTerminateCallbackErrorDoesNotInvokeOnError() {
TestLogger testLogger = new TestLogger();
LoggerUtils.enableCaptureWith(testLogger);
try {
IllegalStateException error = new IllegalStateException("test");
AtomicReference<Throwable> errorCallbackCapture = new AtomicReference<>();
FluxPeekFuseable<String> flux = new FluxPeekFuseable<>(Flux.empty(), null, null, errorCallbackCapture::set, null, () -> {
throw error;
}, null, null);
AssertSubscriber<String> ts = AssertSubscriber.create();
flux.subscribe(ts);
ts.assertNoValues();
ts.assertComplete();
// the onError wasn't invoked:
assertThat(errorCallbackCapture.get()).isNull();
assertThat(testLogger.getErrContent()).contains("Operator called default onErrorDropped").contains(error.getMessage());
} finally {
LoggerUtils.disableCapture();
}
}
use of reactor.test.util.TestLogger in project reactor-core by reactor.
the class FluxTests method testThrowWithoutOnErrorShowsUpInSchedulerHandler.
@Test
public void testThrowWithoutOnErrorShowsUpInSchedulerHandler() {
TestLogger testLogger = new TestLogger();
LoggerUtils.enableCaptureWith(testLogger);
AtomicReference<String> failure = new AtomicReference<>(null);
AtomicBoolean handled = new AtomicBoolean(false);
Thread.setDefaultUncaughtExceptionHandler((t, e) -> failure.set("unexpected call to default" + " UncaughtExceptionHandler with " + e));
CountDownLatch latch = new CountDownLatch(1);
AtomicInteger uncompletedWork = new AtomicInteger();
Schedulers.onHandleError((t, e) -> handled.set(true));
Schedulers.onScheduleHook("test", r -> {
uncompletedWork.incrementAndGet();
return () -> {
try {
r.run();
} finally {
uncompletedWork.decrementAndGet();
}
};
});
try {
Flux.interval(Duration.ofMillis(100)).take(1).publishOn(Schedulers.parallel()).doOnCancel(latch::countDown).subscribe(i -> {
System.out.println("About to throw...");
throw new IllegalArgumentException();
});
assertThat(latch.await(5, TimeUnit.SECONDS)).as("Expected latch to count down before timeout", latch.await(5, TimeUnit.SECONDS)).isTrue();
// awaiting to all threads done
while (uncompletedWork.get() != 0) {
Thread.sleep(100);
}
} catch (Throwable e) {
fail(e.toString());
} finally {
LoggerUtils.disableCapture();
Thread.setDefaultUncaughtExceptionHandler(null);
Schedulers.resetOnHandleError();
Schedulers.resetOnScheduleHook("test");
}
assertThat(handled).as("Uncaught error handler").isFalse();
assertThat(failure).as("Uncaught error handler").hasValue(null);
assertThat(testLogger.getErrContent()).contains("Operator called default onErrorDropped").contains("reactor.core.Exceptions$ErrorCallbackNotImplemented: java.lang.IllegalArgumentException");
}
use of reactor.test.util.TestLogger in project reactor-core by reactor.
the class NextProcessorTest method doubleSignal.
@Test
void doubleSignal() {
TestLogger testLogger = new TestLogger();
LoggerUtils.enableCaptureWith(testLogger);
try {
NextProcessor<String> mp = new NextProcessor<>(null);
mp.onNext("test");
mp.onError(new Exception("test2"));
Assertions.assertThat(testLogger.getErrContent()).contains("Operator called default onErrorDropped").contains("test2");
} finally {
LoggerUtils.disableCapture();
}
}
Aggregations