Search in sources :

Example 1 with PeekFuseableConditionalSubscriber

use of reactor.core.publisher.FluxPeekFuseable.PeekFuseableConditionalSubscriber in project reactor-core by reactor.

the class FluxPeekFuseableTest method scanFuseableConditionalSubscriber.

@Test
public void scanFuseableConditionalSubscriber() {
    @SuppressWarnings("unchecked") Fuseable.ConditionalSubscriber<Integer> actual = Mockito.mock(MockUtils.TestScannableConditionalSubscriber.class);
    FluxPeek<Integer> peek = new FluxPeek<>(Flux.just(1), s -> {
    }, s -> {
    }, e -> {
    }, () -> {
    }, () -> {
    }, r -> {
    }, () -> {
    });
    PeekFuseableConditionalSubscriber<Integer> test = new PeekFuseableConditionalSubscriber<>(actual, peek);
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
    test.onError(new IllegalStateException("boom"));
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PeekFuseableConditionalSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekFuseableConditionalSubscriber) MockUtils(reactor.test.MockUtils) Subscription(org.reactivestreams.Subscription) Fuseable(reactor.core.Fuseable) Test(org.junit.Test)

Example 2 with PeekFuseableConditionalSubscriber

use of reactor.core.publisher.FluxPeekFuseable.PeekFuseableConditionalSubscriber in project reactor-core by reactor.

the class FluxPeekFuseableTest method resumeFuseableConditional.

@Test
public void resumeFuseableConditional() {
    RuntimeException nextError = new IllegalStateException("next");
    List<Throwable> resumedErrors = new ArrayList<>();
    List<Object> resumedValues = new ArrayList<>();
    Context context = Context.of(OnNextFailureStrategy.KEY_ON_NEXT_ERROR_STRATEGY, OnNextFailureStrategy.resume((t, s) -> {
        resumedErrors.add(t);
        resumedValues.add(s);
    }));
    ConditionalAssertSubscriber<Integer> actual = new ConditionalAssertSubscriber<>(context);
    SignalPeekThrowNext<Integer> peekParent = new SignalPeekThrowNext<>(nextError);
    AssertQueueSubscription<Integer> qs = new AssertQueueSubscription<>();
    PeekFuseableConditionalSubscriber<Integer> test = new PeekFuseableConditionalSubscriber<>(actual, peekParent);
    test.onSubscribe(qs);
    test.onNext(1);
    assertThat(actual.next).as("onNext skips").isEmpty();
    assertThat(qs.requested).as("onNext requested more").isEqualTo(1);
    boolean tryOnNext = test.tryOnNext(2);
    assertThat(tryOnNext).as("tryOnNext skips").isFalse();
    qs.offer(3);
    Integer polled = test.poll();
    assertThat(polled).as("poll skips").isNull();
    test.onComplete();
    assertThat(actual.error).isNull();
    assertThat(actual.completed).isTrue();
    assertThat(resumedErrors).containsExactly(nextError, nextError, nextError);
    assertThat(resumedValues).containsExactly(1, 2, 3);
}
Also used : Context(reactor.util.context.Context) PeekConditionalSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekConditionalSubscriber) CoreMatchers(org.hamcrest.CoreMatchers) StepVerifier(reactor.test.StepVerifier) Scannable(reactor.core.Scannable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Queues(reactor.util.concurrent.Queues) CoreSubscriber(reactor.core.CoreSubscriber) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Schedulers(reactor.core.scheduler.Schedulers) Thread.sleep(java.lang.Thread.sleep) MockUtils(reactor.test.MockUtils) Nullable(javax.annotation.Nullable) PeekFuseableSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekFuseableSubscriber) Context(reactor.util.context.Context) Test(org.junit.Test) Schedulers.parallel(reactor.core.scheduler.Schedulers.parallel) LongConsumer(java.util.function.LongConsumer) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Mockito(org.mockito.Mockito) List(java.util.List) Fuseable(reactor.core.Fuseable) Subscription(org.reactivestreams.Subscription) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Queue(java.util.Queue) Assert(org.junit.Assert) Exceptions(reactor.core.Exceptions) Collections(java.util.Collections) PeekFuseableConditionalSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekFuseableConditionalSubscriber) PeekFuseableConditionalSubscriber(reactor.core.publisher.FluxPeekFuseable.PeekFuseableConditionalSubscriber) ArrayList(java.util.ArrayList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Test (org.junit.Test)2 Subscription (org.reactivestreams.Subscription)2 Fuseable (reactor.core.Fuseable)2 PeekFuseableConditionalSubscriber (reactor.core.publisher.FluxPeekFuseable.PeekFuseableConditionalSubscriber)2 MockUtils (reactor.test.MockUtils)2 Thread.sleep (java.lang.Thread.sleep)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Queue (java.util.Queue)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Consumer (java.util.function.Consumer)1 LongConsumer (java.util.function.LongConsumer)1 Nullable (javax.annotation.Nullable)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 CoreMatchers (org.hamcrest.CoreMatchers)1 Assert (org.junit.Assert)1