Search in sources :

Example 11 with TestLogger

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

the class SignalLoggerTests method currentContextLogWhenTrace.

@Test
public void currentContextLogWhenTrace() {
    TestLogger logger = new TestLogger();
    SignalLogger<?> signalLogger = new SignalLogger<>(Mono.empty(), null, Level.FINEST, false, name -> logger);
    assertThat(logger.getOutContent()).as("before currentContext()").isEmpty();
    Context context = Context.of("foo", "bar");
    signalLogger.onCurrentContextCall().accept(context);
    assertThat(logger.getOutContent()).startsWith("[TRACE] (").endsWith(") currentContext(Context1{foo=bar})\n");
}
Also used : Context(reactor.util.context.Context) TestLogger(reactor.test.util.TestLogger) Test(org.junit.jupiter.api.Test)

Example 12 with TestLogger

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

the class SignalLoggerTests method safeLogsWhenLoggerThrows.

@Test
public void safeLogsWhenLoggerThrows() {
    TestLogger logger = new TestLogger() {

        @Override
        public synchronized void info(String format, Object... arguments) {
            if (arguments[0] instanceof SignalType && arguments[1] instanceof Integer) {
                throw new UnsupportedOperationException("boom on integer");
            }
            super.info(format, arguments);
        }
    };
    SignalLogger signalLogger = new SignalLogger<>(Flux.empty(), null, Level.INFO, false, it -> logger);
    signalLogger.safeLog(SignalType.ON_NEXT, 404);
    assertThat(logger.getOutContent()).contains("UnsupportedOperationException has been raised by the logging framework, does your log() placement make sense? " + "eg. 'window(2).log()' instead of 'window(2).flatMap(w -> w.log())' - " + "java.lang.UnsupportedOperationException: boom on integer").contains("onNext(404)");
}
Also used : TestLogger(reactor.test.util.TestLogger) Test(org.junit.jupiter.api.Test)

Example 13 with TestLogger

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

the class SignalLoggerTests method currentContextLogWhenDebug.

@Test
public void currentContextLogWhenDebug() {
    TestLogger logger = new TestLogger();
    SignalLogger<?> signalLogger = new SignalLogger<>(Mono.empty(), null, Level.FINE, false, name -> logger);
    assertThat(logger.getOutContent()).as("before currentContext()").isEmpty();
    Context context = Context.of("foo", "bar");
    signalLogger.onCurrentContextCall().accept(context);
    assertThat(logger.getOutContent()).startsWith("[DEBUG] (").endsWith(") currentContext(Context1{foo=bar})\n");
}
Also used : Context(reactor.util.context.Context) TestLogger(reactor.test.util.TestLogger) Test(org.junit.jupiter.api.Test)

Example 14 with TestLogger

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

the class FluxZipTest method failDoubleError2.

// FIXME use Violation.NO_CLEANUP_ON_TERMINATE
@Test
public void failDoubleError2() {
    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)

Example 15 with TestLogger

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

the class FluxZipTest method failDoubleError.

// FIXME use Violation.NO_CLEANUP_ON_TERMINATE
@Test
public void failDoubleError() {
    TestLogger testLogger = new TestLogger();
    LoggerUtils.enableCaptureWith(testLogger);
    try {
        StepVerifier.create(Flux.zip(obj -> 0, Flux.just(1), 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