Search in sources :

Example 1 with TestLogger

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();
    }
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) TestLogger(reactor.test.util.TestLogger) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest) Test(org.junit.jupiter.api.Test)

Example 2 with TestLogger

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();
    }
}
Also used : TestLogger(reactor.test.util.TestLogger) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest) Test(org.junit.jupiter.api.Test)

Example 3 with TestLogger

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();
    }
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) TestLogger(reactor.test.util.TestLogger) Test(org.junit.jupiter.api.Test)

Example 4 with TestLogger

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");
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) TestLogger(reactor.test.util.TestLogger) Test(org.junit.jupiter.api.Test)

Example 5 with TestLogger

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();
    }
}
Also used : TestLogger(reactor.test.util.TestLogger) CancellationException(java.util.concurrent.CancellationException) Test(org.junit.jupiter.api.Test)

Aggregations

TestLogger (reactor.test.util.TestLogger)39 Test (org.junit.jupiter.api.Test)38 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 Subscription (org.reactivestreams.Subscription)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)10 StepVerifier (reactor.test.StepVerifier)10 CountDownLatch (java.util.concurrent.CountDownLatch)9 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 CoreSubscriber (reactor.core.CoreSubscriber)9 Fuseable (reactor.core.Fuseable)9 Duration (java.time.Duration)8 TimeUnit (java.util.concurrent.TimeUnit)8 Function (java.util.function.Function)8 Awaitility (org.awaitility.Awaitility)8 Publisher (org.reactivestreams.Publisher)8 TestPublisher (reactor.test.publisher.TestPublisher)8 Loggers (reactor.util.Loggers)8 Context (reactor.util.context.Context)8 LongAdder (java.util.concurrent.atomic.LongAdder)7 FluxOperatorTest (reactor.test.publisher.FluxOperatorTest)7