Search in sources :

Example 16 with ParameterizedTestWithName

use of reactor.test.ParameterizedTestWithName in project reactor-core by reactor.

the class FluxCreateTest method secondOnCancelHandlerIsDisposedImmediately.

@ParameterizedTestWithName
@EnumSource(OverflowStrategy.class)
void secondOnCancelHandlerIsDisposedImmediately(OverflowStrategy overflowStrategy) {
    AtomicInteger firstDisposed = new AtomicInteger();
    AtomicInteger secondDisposed = new AtomicInteger();
    Flux.create(sink -> sink.onCancel(firstDisposed::incrementAndGet).onCancel(secondDisposed::incrementAndGet), overflowStrategy).subscribe();
    assertThat(firstDisposed).as("first handler for %s", overflowStrategy).hasValue(0);
    assertThat(secondDisposed).as("second handler for %s", overflowStrategy).hasValue(1);
}
Also used : IntStream(java.util.stream.IntStream) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SerializedFluxSink(reactor.core.publisher.FluxCreate.SerializedFluxSink) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OverflowStrategy(reactor.core.publisher.FluxSink.OverflowStrategy) EnumSource(org.junit.jupiter.params.provider.EnumSource) Scheduler(reactor.core.scheduler.Scheduler) AtomicReference(java.util.concurrent.atomic.AtomicReference) BufferAsyncSink(reactor.core.publisher.FluxCreate.BufferAsyncSink) CoreSubscriber(reactor.core.CoreSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LatestAsyncSink(reactor.core.publisher.FluxCreate.LatestAsyncSink) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Schedulers(reactor.core.scheduler.Schedulers) RaceTestUtils(reactor.test.util.RaceTestUtils) Subscriber(org.reactivestreams.Subscriber) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName) Semaphore(java.util.concurrent.Semaphore) Step(reactor.test.StepVerifier.Step) Context(reactor.util.context.Context) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) Assertions.fail(org.assertj.core.api.Assertions.fail) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Exceptions(reactor.core.Exceptions) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName)

Example 17 with ParameterizedTestWithName

use of reactor.test.ParameterizedTestWithName 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 18 with ParameterizedTestWithName

use of reactor.test.ParameterizedTestWithName 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 19 with ParameterizedTestWithName

use of reactor.test.ParameterizedTestWithName in project reactor-core by reactor.

the class InternalOneSinkTest method shouldDelegateToHandler.

@ParameterizedTestWithName
@EnumSource(value = Sinks.EmitResult.class)
void shouldDelegateToHandler(EmitResult emitResult) {
    assumeThat(emitResult.isFailure()).isTrue();
    Sinks.One<Object> sink = new InternalOneSinkAdapter<Object>() {

        @Override
        public Sinks.EmitResult tryEmitValue(Object value) {
            return emitResult;
        }

        @Override
        public Sinks.EmitResult tryEmitError(Throwable error) {
            return emitResult;
        }

        @Override
        public Sinks.EmitResult tryEmitEmpty() {
            return emitResult;
        }
    };
    for (SignalType signalType : new SignalType[] { SignalType.ON_NEXT, SignalType.ON_ERROR, SignalType.ON_COMPLETE }) {
        AtomicReference<Sinks.EmitResult> emissionRef = new AtomicReference<>();
        try {
            EmitFailureHandler handler = (failedSignalType, failedEmission) -> {
                emissionRef.set(failedEmission);
                return false;
            };
            switch(signalType) {
                case ON_NEXT:
                    sink.emitValue("Hello", handler);
                    break;
                case ON_ERROR:
                    sink.emitError(new Exception("boom"), handler);
                    break;
                case ON_COMPLETE:
                    sink.emitEmpty(handler);
                    break;
                default:
                    throw new IllegalStateException();
            }
        } catch (EmissionException e) {
            assertThat(e.getReason()).isEqualTo(Sinks.EmitResult.FAIL_NON_SERIALIZED);
        }
        assertThat(emissionRef).as("emitResult").hasValue(emitResult);
    }
}
Also used : ParameterizedTestWithName(reactor.test.ParameterizedTestWithName) Assumptions.assumeThat(org.assertj.core.api.Assumptions.assumeThat) Context(reactor.util.context.Context) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EnumSource(org.junit.jupiter.params.provider.EnumSource) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EmissionException(reactor.core.publisher.Sinks.EmissionException) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) EmitResult(reactor.core.publisher.Sinks.EmitResult) EmitFailureHandler(reactor.core.publisher.Sinks.EmitFailureHandler) Exceptions(reactor.core.Exceptions) AtomicReference(java.util.concurrent.atomic.AtomicReference) EmissionException(reactor.core.publisher.Sinks.EmissionException) EmitFailureHandler(reactor.core.publisher.Sinks.EmitFailureHandler) EmitResult(reactor.core.publisher.Sinks.EmitResult) EmissionException(reactor.core.publisher.Sinks.EmissionException) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName)

Example 20 with ParameterizedTestWithName

use of reactor.test.ParameterizedTestWithName in project reactor-core by reactor.

the class InternalManySinkTest method shouldDelegateToHandler.

@ParameterizedTestWithName
@EnumSource(value = Sinks.EmitResult.class)
void shouldDelegateToHandler(Sinks.EmitResult emitResult) {
    assumeThat(emitResult.isFailure()).isTrue();
    Sinks.Many<Object> sink = new InternalManySinkAdapter<Object>() {

        @Override
        public EmitResult tryEmitNext(Object o) {
            return emitResult;
        }

        @Override
        public Sinks.EmitResult tryEmitError(Throwable error) {
            return emitResult;
        }

        @Override
        public EmitResult tryEmitComplete() {
            return emitResult;
        }
    };
    for (SignalType signalType : new SignalType[] { SignalType.ON_NEXT, SignalType.ON_ERROR, SignalType.ON_COMPLETE }) {
        AtomicReference<EmitResult> emissionRef = new AtomicReference<>();
        try {
            EmitFailureHandler handler = (failedSignalType, failedEmission) -> {
                emissionRef.set(failedEmission);
                return false;
            };
            switch(signalType) {
                case ON_NEXT:
                    sink.emitNext("Hello", handler);
                    break;
                case ON_ERROR:
                    sink.emitError(new Exception("boom"), handler);
                    break;
                case ON_COMPLETE:
                    sink.emitComplete(handler);
                    break;
                default:
                    throw new IllegalStateException();
            }
        } catch (EmissionException e) {
            assertThat(e.getReason()).isEqualTo(EmitResult.FAIL_NON_SERIALIZED);
        }
        assertThat(emissionRef).as("emitResult").hasValue(emitResult);
    }
}
Also used : ParameterizedTestWithName(reactor.test.ParameterizedTestWithName) Assumptions.assumeThat(org.assertj.core.api.Assumptions.assumeThat) Context(reactor.util.context.Context) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EnumSource(org.junit.jupiter.params.provider.EnumSource) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EmissionException(reactor.core.publisher.Sinks.EmissionException) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) EmitResult(reactor.core.publisher.Sinks.EmitResult) EmitFailureHandler(reactor.core.publisher.Sinks.EmitFailureHandler) Exceptions(reactor.core.Exceptions) AtomicReference(java.util.concurrent.atomic.AtomicReference) EmissionException(reactor.core.publisher.Sinks.EmissionException) EmitFailureHandler(reactor.core.publisher.Sinks.EmitFailureHandler) EmitResult(reactor.core.publisher.Sinks.EmitResult) EmissionException(reactor.core.publisher.Sinks.EmissionException) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName)

Aggregations

ParameterizedTestWithName (reactor.test.ParameterizedTestWithName)29 Test (org.junit.jupiter.api.Test)28 Subscription (org.reactivestreams.Subscription)25 StepVerifier (reactor.test.StepVerifier)25 Stream (java.util.stream.Stream)24 CoreSubscriber (reactor.core.CoreSubscriber)24 Exceptions (reactor.core.Exceptions)21 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)20 Scannable (reactor.core.Scannable)20 Arrays (java.util.Arrays)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)17 Context (reactor.util.context.Context)17 Duration (java.time.Duration)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 Function (java.util.function.Function)14 Arguments (org.junit.jupiter.params.provider.Arguments)14 Arguments.arguments (org.junit.jupiter.params.provider.Arguments.arguments)14 MethodSource (org.junit.jupiter.params.provider.MethodSource)14 Publisher (org.reactivestreams.Publisher)14