Search in sources :

Example 36 with TestLogger

use of reactor.test.util.TestLogger in project reactor-core by reactor.

the class FluxFlatMapTest method failDoubleError.

@Test
public void failDoubleError() {
    TestLogger testLogger = new TestLogger();
    LoggerUtils.enableCaptureWith(testLogger);
    try {
        StepVerifier.create(Flux.from(s -> {
            s.onSubscribe(Operators.emptySubscription());
            s.onError(new Exception("test"));
            s.onError(new Exception("test2"));
        }).flatMap(Flux::just)).verifyErrorMessage("test");
        assertThat(testLogger.getErrContent()).contains("Operator called default onErrorDropped").contains("java.lang.Exception: test2");
    } finally {
        LoggerUtils.disableCapture();
    }
}
Also used : TestPublisher(reactor.test.publisher.TestPublisher) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) TestLogger(reactor.test.util.TestLogger) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AssertQueueSubscription(reactor.core.publisher.FluxPeekFuseableTest.AssertQueueSubscription) Disabled(org.junit.jupiter.api.Disabled) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Queues(reactor.util.concurrent.Queues) CoreSubscriber(reactor.core.CoreSubscriber) Loggers(reactor.util.Loggers) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Logger(reactor.util.Logger) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Schedulers(reactor.core.scheduler.Schedulers) RaceTestUtils(reactor.test.util.RaceTestUtils) Subscriber(org.reactivestreams.Subscriber) Publisher(org.reactivestreams.Publisher) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Fuseable(reactor.core.Fuseable) LoggerUtils(reactor.test.util.LoggerUtils) FAIL_FAST(reactor.core.publisher.Sinks.EmitFailureHandler.FAIL_FAST) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Exceptions(reactor.core.Exceptions) Awaitility(org.awaitility.Awaitility) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) TestLogger(reactor.test.util.TestLogger) Test(org.junit.jupiter.api.Test)

Example 37 with TestLogger

use of reactor.test.util.TestLogger in project reactor-core by reactor.

the class FluxPeekFuseableTest method afterTerminateCallbackErrorAndErrorCallbackError.

@Test
public void afterTerminateCallbackErrorAndErrorCallbackError() {
    TestLogger testLogger = new TestLogger();
    LoggerUtils.enableCaptureWith(testLogger);
    try {
        IllegalStateException error = new IllegalStateException("expected afterTerminate");
        IllegalArgumentException error2 = new IllegalArgumentException("error");
        FluxPeekFuseable<String> flux = new FluxPeekFuseable<>(Flux.empty(), null, null, e -> {
            throw error2;
        }, null, () -> {
            throw error;
        }, null, null);
        AssertSubscriber<String> ts = AssertSubscriber.create();
        flux.subscribe(ts);
        assertThat(testLogger.getErrContent()).contains("Operator called default onErrorDropped").contains(error.getMessage());
        assertThat(error2.getSuppressed()).isEmpty();
        // error2 is never thrown
        ts.assertNoValues();
        ts.assertComplete();
    } finally {
        LoggerUtils.disableCapture();
    }
}
Also used : TestLogger(reactor.test.util.TestLogger) Test(org.junit.jupiter.api.Test)

Example 38 with TestLogger

use of reactor.test.util.TestLogger in project reactor-core by reactor.

the class FluxPeekFuseableTest method afterTerminateCallbackErrorAndErrorCallbackError2.

@Test
public void afterTerminateCallbackErrorAndErrorCallbackError2() {
    TestLogger testLogger = new TestLogger();
    LoggerUtils.enableCaptureWith(testLogger);
    try {
        IllegalStateException afterTerminate = new IllegalStateException("afterTerminate");
        IllegalArgumentException error = new IllegalArgumentException("error");
        NullPointerException error2 = new NullPointerException();
        FluxPeekFuseable<String> flux = new FluxPeekFuseable<>(Flux.error(error2), null, null, e -> {
            throw error;
        }, null, () -> {
            throw afterTerminate;
        }, null, null);
        AssertSubscriber<String> ts = AssertSubscriber.create();
        flux.subscribe(ts);
        assertThat(testLogger.getErrContent()).contains("Operator called default onErrorDropped").contains(afterTerminate.getMessage());
        // afterTerminate suppressed error which itself suppressed original error2
        assertThat(afterTerminate.getSuppressed().length).isEqualTo(1);
        assertThat(afterTerminate.getSuppressed()[0]).isEqualTo(error);
        assertThat(error.getSuppressed().length).isEqualTo(1);
        assertThat(error.getSuppressed()[0]).isEqualTo(error2);
        ts.assertNoValues();
        // the subscriber still sees the 'error' message since actual.onError is called before the afterTerminate callback
        ts.assertErrorMessage("error");
    } finally {
        LoggerUtils.disableCapture();
    }
}
Also used : TestLogger(reactor.test.util.TestLogger) Test(org.junit.jupiter.api.Test)

Example 39 with TestLogger

use of reactor.test.util.TestLogger in project reactor-core by reactor.

the class FluxPeekTest method afterTerminateCallbackErrorAndErrorCallbackError2.

@Test
public void afterTerminateCallbackErrorAndErrorCallbackError2() {
    TestLogger testLogger = new TestLogger();
    LoggerUtils.enableCaptureWith(testLogger);
    try {
        IllegalStateException afterTerminate = new IllegalStateException("afterTerminate");
        IllegalArgumentException error = new IllegalArgumentException("error");
        NullPointerException ex = new NullPointerException();
        FluxPeek<String> flux = new FluxPeek<>(Flux.error(ex), null, null, e -> {
            throw error;
        }, null, () -> {
            throw afterTerminate;
        }, null, null);
        AssertSubscriber<String> ts = AssertSubscriber.create();
        flux.subscribe(ts);
        assertThat(testLogger.getErrContent()).contains("Operator called default onErrorDropped").contains(afterTerminate.getMessage());
        // afterTerminate suppressed error which itself suppressed original err
        assertThat(afterTerminate.getSuppressed()).hasSize(1);
        assertThat(afterTerminate).hasSuppressedException(error);
        assertThat(error.getSuppressed()).hasSize(1);
        assertThat(error).hasSuppressedException(ex);
        ts.assertNoValues();
        // the subscriber still sees the 'error' message since actual.onError is called before the afterTerminate callback
        ts.assertErrorMessage("error");
    } finally {
        LoggerUtils.disableCapture();
    }
}
Also used : TestLogger(reactor.test.util.TestLogger) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest) 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