Search in sources :

Example 11 with ParameterizedTestWithName

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

the class FluxDoOnEachTest method empty.

@ParameterizedTestWithName
@MethodSource("sourcesEmpty")
void empty(Flux<Integer> source) {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    AtomicReference<Integer> onNext = new AtomicReference<>();
    AtomicReference<Throwable> onError = new AtomicReference<>();
    AtomicBoolean onComplete = new AtomicBoolean();
    LongAdder state = new LongAdder();
    source.doOnEach(s -> {
        if (s.isOnNext()) {
            onNext.set(s.get());
            state.increment();
        } else if (s.isOnError()) {
            onError.set(s.getThrowable());
        } else if (s.isOnComplete()) {
            onComplete.set(true);
        }
    }).filter(t -> true).subscribe(ts);
    assertThat(onNext).hasValue(null);
    assertThat(onError).hasValue(null);
    assertThat(onComplete).isTrue();
    assertThat(state.intValue()).isEqualTo(0);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LongAdder(java.util.concurrent.atomic.LongAdder) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AssertQueueSubscription(reactor.core.publisher.FluxPeekFuseableTest.AssertQueueSubscription) ConditionalSubscriber(reactor.core.Fuseable.ConditionalSubscriber) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) DoOnEachFuseableConditionalSubscriber(reactor.core.publisher.FluxDoOnEach.DoOnEachFuseableConditionalSubscriber) CoreSubscriber(reactor.core.CoreSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Schedulers(reactor.core.scheduler.Schedulers) Assertions(org.assertj.core.api.Assertions) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) StepVerifierOptions(reactor.test.StepVerifierOptions) MethodSource(org.junit.jupiter.params.provider.MethodSource) DoOnEachConditionalSubscriber(reactor.core.publisher.FluxDoOnEach.DoOnEachConditionalSubscriber) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName) Context(reactor.util.context.Context) Arguments(org.junit.jupiter.params.provider.Arguments) Test(org.junit.jupiter.api.Test) List(java.util.List) Fuseable(reactor.core.Fuseable) Stream(java.util.stream.Stream) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Named.named(org.junit.jupiter.api.Named.named) Exceptions(reactor.core.Exceptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LongAdder(java.util.concurrent.atomic.LongAdder) AtomicReference(java.util.concurrent.atomic.AtomicReference) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName)

Example 12 with ParameterizedTestWithName

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

the class FluxDoOnEachTest method nextCallbackError.

@ParameterizedTestWithName
@MethodSource("sources12Complete")
void nextCallbackError(Flux<Integer> source) {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    LongAdder state = new LongAdder();
    Throwable err = new Exception("test");
    source.doOnEach(s -> {
        if (s.isOnNext()) {
            state.increment();
            throw Exceptions.propagate(err);
        }
    }).filter(t -> true).subscribe(ts);
    // nominal error path (DownstreamException)
    ts.assertErrorMessage("test");
    assertThat(state.intValue()).isEqualTo(1);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LongAdder(java.util.concurrent.atomic.LongAdder) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AssertQueueSubscription(reactor.core.publisher.FluxPeekFuseableTest.AssertQueueSubscription) ConditionalSubscriber(reactor.core.Fuseable.ConditionalSubscriber) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) DoOnEachFuseableConditionalSubscriber(reactor.core.publisher.FluxDoOnEach.DoOnEachFuseableConditionalSubscriber) CoreSubscriber(reactor.core.CoreSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Schedulers(reactor.core.scheduler.Schedulers) Assertions(org.assertj.core.api.Assertions) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) StepVerifierOptions(reactor.test.StepVerifierOptions) MethodSource(org.junit.jupiter.params.provider.MethodSource) DoOnEachConditionalSubscriber(reactor.core.publisher.FluxDoOnEach.DoOnEachConditionalSubscriber) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName) Context(reactor.util.context.Context) Arguments(org.junit.jupiter.params.provider.Arguments) Test(org.junit.jupiter.api.Test) List(java.util.List) Fuseable(reactor.core.Fuseable) Stream(java.util.stream.Stream) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Named.named(org.junit.jupiter.api.Named.named) Exceptions(reactor.core.Exceptions) LongAdder(java.util.concurrent.atomic.LongAdder) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName)

Example 13 with ParameterizedTestWithName

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

the class FluxDoOnEachTest method completeCallbackError.

@ParameterizedTestWithName
@MethodSource("sources12Complete")
void completeCallbackError(Flux<Integer> source) {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    AtomicBoolean completeHandled = new AtomicBoolean();
    AtomicBoolean errorHandled = new AtomicBoolean();
    Throwable err = new Exception("test");
    source.doOnEach(s -> {
        if (s.isOnComplete()) {
            completeHandled.set(true);
            throw Exceptions.propagate(err);
        }
        if (s.isOnError()) {
            errorHandled.set(true);
        }
    }).filter(t -> true).subscribe(ts);
    ts.assertErrorMessage("test");
    assertThat(completeHandled).as("complete() handler triggered").isTrue();
    assertThat(errorHandled).as("complete() failure passed to error handler triggered").isTrue();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LongAdder(java.util.concurrent.atomic.LongAdder) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AssertQueueSubscription(reactor.core.publisher.FluxPeekFuseableTest.AssertQueueSubscription) ConditionalSubscriber(reactor.core.Fuseable.ConditionalSubscriber) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) DoOnEachFuseableConditionalSubscriber(reactor.core.publisher.FluxDoOnEach.DoOnEachFuseableConditionalSubscriber) CoreSubscriber(reactor.core.CoreSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Schedulers(reactor.core.scheduler.Schedulers) Assertions(org.assertj.core.api.Assertions) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) StepVerifierOptions(reactor.test.StepVerifierOptions) MethodSource(org.junit.jupiter.params.provider.MethodSource) DoOnEachConditionalSubscriber(reactor.core.publisher.FluxDoOnEach.DoOnEachConditionalSubscriber) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName) Context(reactor.util.context.Context) Arguments(org.junit.jupiter.params.provider.Arguments) Test(org.junit.jupiter.api.Test) List(java.util.List) Fuseable(reactor.core.Fuseable) Stream(java.util.stream.Stream) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Named.named(org.junit.jupiter.api.Named.named) Exceptions(reactor.core.Exceptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName)

Example 14 with ParameterizedTestWithName

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

the class FluxDoOnEachTest method nextCallbackBubbleError.

@ParameterizedTestWithName
@MethodSource("sources12Complete")
void nextCallbackBubbleError(Flux<Integer> source) {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    LongAdder state = new LongAdder();
    Throwable err = new Exception("test");
    try {
        source.doOnEach(s -> {
            if (s.isOnNext()) {
                state.increment();
                throw Exceptions.bubble(err);
            }
        }).filter(t -> true).subscribe(ts);
        fail("Exception expected");
    } catch (Exception e) {
        assertThat(Exceptions.unwrap(e)).isSameAs(err);
        assertThat(state.intValue()).isEqualTo(1);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LongAdder(java.util.concurrent.atomic.LongAdder) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AssertQueueSubscription(reactor.core.publisher.FluxPeekFuseableTest.AssertQueueSubscription) ConditionalSubscriber(reactor.core.Fuseable.ConditionalSubscriber) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) DoOnEachFuseableConditionalSubscriber(reactor.core.publisher.FluxDoOnEach.DoOnEachFuseableConditionalSubscriber) CoreSubscriber(reactor.core.CoreSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Schedulers(reactor.core.scheduler.Schedulers) Assertions(org.assertj.core.api.Assertions) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) StepVerifierOptions(reactor.test.StepVerifierOptions) MethodSource(org.junit.jupiter.params.provider.MethodSource) DoOnEachConditionalSubscriber(reactor.core.publisher.FluxDoOnEach.DoOnEachConditionalSubscriber) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName) Context(reactor.util.context.Context) Arguments(org.junit.jupiter.params.provider.Arguments) Test(org.junit.jupiter.api.Test) List(java.util.List) Fuseable(reactor.core.Fuseable) Stream(java.util.stream.Stream) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Named.named(org.junit.jupiter.api.Named.named) Exceptions(reactor.core.Exceptions) LongAdder(java.util.concurrent.atomic.LongAdder) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName)

Example 15 with ParameterizedTestWithName

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

the class FluxDoOnEachTest method never.

@ParameterizedTestWithName
@MethodSource("sourcesNever")
void never(Flux<Integer> source) {
    AssertSubscriber<Integer> ts = AssertSubscriber.create();
    AtomicReference<Integer> onNext = new AtomicReference<>();
    AtomicReference<Throwable> onError = new AtomicReference<>();
    AtomicBoolean onComplete = new AtomicBoolean();
    LongAdder state = new LongAdder();
    source.doOnEach(s -> {
        if (s.isOnNext()) {
            onNext.set(s.get());
            state.increment();
        } else if (s.isOnError()) {
            onError.set(s.getThrowable());
        } else if (s.isOnComplete()) {
            onComplete.set(true);
        }
    }).filter(t -> true).subscribe(ts);
    assertThat(onNext).hasValue(null);
    assertThat(onError).hasValue(null);
    assertThat(onComplete).isFalse();
    assertThat(state.intValue()).isEqualTo(0);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LongAdder(java.util.concurrent.atomic.LongAdder) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AssertQueueSubscription(reactor.core.publisher.FluxPeekFuseableTest.AssertQueueSubscription) ConditionalSubscriber(reactor.core.Fuseable.ConditionalSubscriber) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) DoOnEachFuseableConditionalSubscriber(reactor.core.publisher.FluxDoOnEach.DoOnEachFuseableConditionalSubscriber) CoreSubscriber(reactor.core.CoreSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Schedulers(reactor.core.scheduler.Schedulers) Assertions(org.assertj.core.api.Assertions) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) StepVerifierOptions(reactor.test.StepVerifierOptions) MethodSource(org.junit.jupiter.params.provider.MethodSource) DoOnEachConditionalSubscriber(reactor.core.publisher.FluxDoOnEach.DoOnEachConditionalSubscriber) ParameterizedTestWithName(reactor.test.ParameterizedTestWithName) Context(reactor.util.context.Context) Arguments(org.junit.jupiter.params.provider.Arguments) Test(org.junit.jupiter.api.Test) List(java.util.List) Fuseable(reactor.core.Fuseable) Stream(java.util.stream.Stream) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Named.named(org.junit.jupiter.api.Named.named) Exceptions(reactor.core.Exceptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LongAdder(java.util.concurrent.atomic.LongAdder) AtomicReference(java.util.concurrent.atomic.AtomicReference) MethodSource(org.junit.jupiter.params.provider.MethodSource) 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