Search in sources :

Example 16 with TestLogger

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

Example 17 with TestLogger

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

Example 18 with TestLogger

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();
    }
}
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 19 with TestLogger

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

Example 20 with TestLogger

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();
    }
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) TestLogger(reactor.test.util.TestLogger) 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