Search in sources :

Example 21 with TestLogger

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

the class OperatorsTest method onDiscardCallbackErrorsLog.

@Test
public void onDiscardCallbackErrorsLog() {
    Context context = Operators.enableOnDiscard(Context.empty(), t -> {
        throw new RuntimeException("Boom");
    });
    TestLogger testLogger = new TestLogger();
    LoggerUtils.enableCaptureWith(testLogger);
    try {
        Operators.onDiscard("Foo", context);
        assertThat(testLogger.getErrContent()).contains("Error in discard hook - java.lang.RuntimeException: Boom");
    } finally {
        LoggerUtils.disableCapture();
    }
}
Also used : Context(reactor.util.context.Context) TestLogger(reactor.test.util.TestLogger) Test(org.junit.jupiter.api.Test)

Example 22 with TestLogger

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

the class NextProcessorTest method doubleError.

@Test
void doubleError() {
    TestLogger testLogger = new TestLogger();
    LoggerUtils.enableCaptureWith(testLogger);
    try {
        NextProcessor<String> mp = new NextProcessor<>(null);
        mp.onError(new Exception("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)

Example 23 with TestLogger

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

the class FluxUsingWhenTest method cancelDefaultHandlerFailure.

@ParameterizedTestWithName
@MethodSource("sources01")
@Deprecated
public void cancelDefaultHandlerFailure(Flux<String> source) {
    TestResource testResource = new TestResource();
    final TestLogger tl = new TestLogger();
    Loggers.useCustomLoggers(name -> tl);
    try {
        Function<TestResource, Publisher<?>> completeOrCancel = r -> {
            return r.commit().concatWith(Mono.error(new IllegalStateException("commit error")));
        };
        Flux<String> test = Flux.usingWhen(Mono.just(testResource), tr -> source, completeOrCancel, (r, e) -> r.rollback(new RuntimeException("placeholder ignored rollback exception")), completeOrCancel).take(2);
        StepVerifier.create(test).expectNext("0", "1").verifyComplete();
        testResource.commitProbe.assertWasSubscribed();
        testResource.cancelProbe.assertWasNotSubscribed();
        testResource.rollbackProbe.assertWasNotSubscribed();
    } finally {
        Loggers.resetLoggerFactory();
    }
    assertThat(tl.getErrContent()).contains("Async resource cleanup failed after cancel").contains("java.lang.IllegalStateException: commit error");
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) TestPublisher(reactor.test.publisher.TestPublisher) Disposable(reactor.core.Disposable) StepVerifier(reactor.test.StepVerifier) TestLogger(reactor.test.util.TestLogger) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UsingWhenSubscriber(reactor.core.publisher.FluxUsingWhen.UsingWhenSubscriber) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Tuple2(reactor.util.function.Tuple2) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Nullable(reactor.util.annotation.Nullable) Level(java.util.logging.Level) CoreSubscriber(reactor.core.CoreSubscriber) Loggers(reactor.util.Loggers) Attr(reactor.core.Scannable.Attr) ResourceSubscriber(reactor.core.publisher.FluxUsingWhen.ResourceSubscriber) Duration(java.time.Duration) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName) Assertions.assertThatNullPointerException(org.assertj.core.api.Assertions.assertThatNullPointerException) Publisher(org.reactivestreams.Publisher) Context(reactor.util.context.Context) Arguments(org.junit.jupiter.params.provider.Arguments) PublisherProbe(reactor.test.publisher.PublisherProbe) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito(org.mockito.Mockito) Fuseable(reactor.core.Fuseable) Stream(java.util.stream.Stream) Subscription(org.reactivestreams.Subscription) Named.named(org.junit.jupiter.api.Named.named) Awaitility(org.awaitility.Awaitility) TestPublisher(reactor.test.publisher.TestPublisher) Publisher(org.reactivestreams.Publisher) TestLogger(reactor.test.util.TestLogger) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName)

Example 24 with TestLogger

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

the class FluxUsingWhenTest method cancelWithHandlerGenerationFailureLogs.

@ParameterizedTestWithName
@MethodSource("sources01")
public void cancelWithHandlerGenerationFailureLogs(Flux<String> source) throws InterruptedException {
    TestLogger tl = new TestLogger();
    Loggers.useCustomLoggers(name -> tl);
    TestResource testResource = new TestResource();
    try {
        Flux<String> test = Flux.usingWhen(Mono.just(testResource), tr -> source, TestResource::commit, TestResource::rollback, r -> null).take(2);
        StepVerifier.create(test).expectNext("0", "1").verifyComplete();
        testResource.commitProbe.assertWasNotSubscribed();
        testResource.cancelProbe.assertWasNotSubscribed();
        testResource.rollbackProbe.assertWasNotSubscribed();
    } finally {
        Loggers.resetLoggerFactory();
    }
    assertThat(tl.getErrContent()).contains("Error generating async resource cleanup during onCancel").contains("java.lang.NullPointerException");
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) TestPublisher(reactor.test.publisher.TestPublisher) Disposable(reactor.core.Disposable) StepVerifier(reactor.test.StepVerifier) TestLogger(reactor.test.util.TestLogger) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UsingWhenSubscriber(reactor.core.publisher.FluxUsingWhen.UsingWhenSubscriber) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Tuple2(reactor.util.function.Tuple2) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Nullable(reactor.util.annotation.Nullable) Level(java.util.logging.Level) CoreSubscriber(reactor.core.CoreSubscriber) Loggers(reactor.util.Loggers) Attr(reactor.core.Scannable.Attr) ResourceSubscriber(reactor.core.publisher.FluxUsingWhen.ResourceSubscriber) Duration(java.time.Duration) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName) Assertions.assertThatNullPointerException(org.assertj.core.api.Assertions.assertThatNullPointerException) Publisher(org.reactivestreams.Publisher) Context(reactor.util.context.Context) Arguments(org.junit.jupiter.params.provider.Arguments) PublisherProbe(reactor.test.publisher.PublisherProbe) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito(org.mockito.Mockito) Fuseable(reactor.core.Fuseable) Stream(java.util.stream.Stream) Subscription(org.reactivestreams.Subscription) Named.named(org.junit.jupiter.api.Named.named) Awaitility(org.awaitility.Awaitility) TestLogger(reactor.test.util.TestLogger) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName)

Example 25 with TestLogger

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

the class FluxZipTest method failDoubleError3.

// FIXME use Violation.NO_CLEANUP_ON_TERMINATE
@Test
public void failDoubleError3() {
    TestLogger testLogger = new TestLogger();
    LoggerUtils.enableCaptureWith(testLogger);
    try {
        StepVerifier.create(Flux.zip(obj -> 0, Flux.just(1).hide(), Flux.never(), s -> {
            s.onSubscribe(Operators.emptySubscription());
            s.onError(new Exception("test"));
            s.onError(new Exception("test2"));
        })).verifyErrorMessage("test");
        Assertions.assertThat(testLogger.getErrContent()).contains("Operator called default onErrorDropped").contains("test2");
    } 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