Search in sources :

Example 31 with TestLogger

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

the class FluxTests method unimplementedErrorCallback.

@Test
public void unimplementedErrorCallback() {
    TestLogger testLogger = new TestLogger();
    LoggerUtils.enableCaptureWith(testLogger);
    try {
        Flux.error(new Exception("forced1")).log("error").subscribe();
        Flux.error(new Exception("forced2")).subscribe();
        assertThat(testLogger.getErrContent()).contains("Operator called default onErrorDropped").contains("reactor.core.Exceptions$ErrorCallbackNotImplemented: java.lang.Exception: forced2");
    } finally {
        LoggerUtils.disableCapture();
    }
}
Also used : TestLogger(reactor.test.util.TestLogger) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 32 with TestLogger

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

the class SinkOneMulticastTest method doubleSignal.

@Test
void doubleSignal() {
    TestLogger testLogger = new TestLogger();
    LoggerUtils.enableCaptureWith(testLogger);
    try {
        SinkOneMulticast<String> sink = new SinkOneMulticast<>();
        sink.emitValue("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();
    }
}
Also used : TestLogger(reactor.test.util.TestLogger) Test(org.junit.jupiter.api.Test)

Example 33 with TestLogger

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

the class ReplayProcessorTest method testReplayProcessorState.

@SuppressWarnings("unchecked")
void testReplayProcessorState(ReplayProcessor<String> rp) {
    TestLogger testLogger = new TestLogger();
    LoggerUtils.enableCaptureWith(testLogger);
    try {
        Disposable d1 = rp.subscribe();
        rp.subscribe();
        ReplayProcessor.ReplayInner<String> s = ((ReplayProcessor.ReplayInner<String>) rp.inners().findFirst().get());
        assertThat(d1).isEqualTo(s.actual());
        assertThat(s.isEmpty()).isTrue();
        assertThat(s.isCancelled()).isFalse();
        assertThat(s.isCancelled()).isFalse();
        assertThat(rp.getPrefetch()).isEqualTo(Integer.MAX_VALUE);
        if (rp.getBufferSize() != Integer.MAX_VALUE) {
            assertThat(rp.getBufferSize()).isEqualTo(1);
        }
        FluxSink<String> sink = rp.sink();
        sink.next("test");
        rp.onComplete();
        rp.onComplete();
        Exception e = new RuntimeException("test");
        rp.onError(e);
        Assertions.assertThat(testLogger.getErrContent()).contains("Operator called default onErrorDropped").contains(e.getMessage());
    } finally {
        LoggerUtils.disableCapture();
    }
}
Also used : Disposable(reactor.core.Disposable) TestLogger(reactor.test.util.TestLogger)

Example 34 with TestLogger

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

the class FluxDoFinallyTest method gh951_withoutDoOnError.

@Test
public // see https://github.com/reactor/reactor-core/issues/951
void gh951_withoutDoOnError() {
    TestLogger testLogger = new TestLogger();
    LoggerUtils.enableCaptureWith(testLogger);
    try {
        List<String> events = new ArrayList<>();
        Mono.just(true).map(this::throwError).doFinally(any -> events.add("doFinally " + any.toString())).subscribe();
        Assertions.assertThat(events).as("withoutDoOnError").containsExactly("doFinally onError");
        Assertions.assertThat(testLogger.getErrContent()).contains("Operator called default onErrorDropped").contains("reactor.core.Exceptions$ErrorCallbackNotImplemented: java.lang.IllegalStateException: boom");
    } finally {
        LoggerUtils.disableCapture();
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) TestLogger(reactor.test.util.TestLogger) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) Fuseable(reactor.core.Fuseable) LoggerUtils(reactor.test.util.LoggerUtils) FAIL_FAST(reactor.core.publisher.Sinks.EmitFailureHandler.FAIL_FAST) Subscription(org.reactivestreams.Subscription) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Assertions(org.assertj.core.api.Assertions) Queue(java.util.Queue) Exceptions(reactor.core.Exceptions) ArrayList(java.util.ArrayList) TestLogger(reactor.test.util.TestLogger) Test(org.junit.jupiter.api.Test)

Example 35 with TestLogger

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

the class FluxFlatMapTest method failDoubleErrorTerminatedInner.

// FIXME use Violation.NO_CLEANUP_ON_TERMINATE
@Test
public void failDoubleErrorTerminatedInner() {
    TestLogger testLogger = new TestLogger();
    LoggerUtils.enableCaptureWith(testLogger);
    try {
        StepVerifier.create(Flux.just(1).hide().flatMap(f -> Flux.from(s -> {
            s.onSubscribe(Operators.emptySubscription());
            Exceptions.terminate(FluxFlatMap.FlatMapMain.ERROR, ((FluxFlatMap.FlatMapInner) s).parent);
            s.onError(new Exception("test"));
        }))).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)

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