Search in sources :

Example 96 with Flowable

use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.

the class StrictSubscriberTest method cancelAfterOnError.

@Test
public void cancelAfterOnError() {
    final List<Object> list = new ArrayList<>();
    Subscriber<Object> sub = new Subscriber<Object>() {

        Subscription upstream;

        @Override
        public void onSubscribe(Subscription s) {
            this.upstream = s;
        }

        @Override
        public void onNext(Object t) {
            list.add(t);
        }

        @Override
        public void onError(Throwable t) {
            upstream.cancel();
            list.add(t.getMessage());
        }

        @Override
        public void onComplete() {
            upstream.cancel();
            list.add("Done");
        }
    };
    new Flowable<Object>() {

        @Override
        protected void subscribeActual(Subscriber<? super Object> s) {
            BooleanSubscription b = new BooleanSubscription();
            s.onSubscribe(b);
            s.onError(new TestException("Forced failure"));
            list.add(b.isCancelled());
        }
    }.subscribe(sub);
    assertEquals(Arrays.<Object>asList("Forced failure", false), list);
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 97 with Flowable

use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.

the class FlowableDelayTest method delayWithFlowableSourceThrows.

@Test
public void delayWithFlowableSourceThrows() {
    PublishProcessor<Integer> source = PublishProcessor.create();
    final PublishProcessor<Integer> delay = PublishProcessor.create();
    Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() {

        @Override
        public Flowable<Integer> apply(Integer t1) {
            return delay;
        }
    };
    Subscriber<Object> subscriber = TestHelper.mockSubscriber();
    InOrder inOrder = inOrder(subscriber);
    source.delay(delayFunc).subscribe(subscriber);
    source.onNext(1);
    source.onError(new TestException());
    delay.onNext(1);
    inOrder.verify(subscriber).onError(any(TestException.class));
    inOrder.verifyNoMoreInteractions();
    verify(subscriber, never()).onNext(any());
    verify(subscriber, never()).onComplete();
}
Also used : InOrder(org.mockito.InOrder) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 98 with Flowable

use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.

the class FlowableDelayTest method delayWithFlowableReorder.

@Test
public void delayWithFlowableReorder() {
    int n = 3;
    PublishProcessor<Integer> source = PublishProcessor.create();
    final List<PublishProcessor<Integer>> subjects = new ArrayList<>();
    for (int i = 0; i < n; i++) {
        subjects.add(PublishProcessor.<Integer>create());
    }
    Flowable<Integer> result = source.delay(new Function<Integer, Flowable<Integer>>() {

        @Override
        public Flowable<Integer> apply(Integer t1) {
            return subjects.get(t1);
        }
    });
    Subscriber<Object> subscriber = TestHelper.mockSubscriber();
    InOrder inOrder = inOrder(subscriber);
    result.subscribe(subscriber);
    for (int i = 0; i < n; i++) {
        source.onNext(i);
    }
    source.onComplete();
    inOrder.verify(subscriber, never()).onNext(anyInt());
    inOrder.verify(subscriber, never()).onComplete();
    for (int i = n - 1; i >= 0; i--) {
        subjects.get(i).onComplete();
        inOrder.verify(subscriber).onNext(i);
    }
    inOrder.verify(subscriber).onComplete();
    verify(subscriber, never()).onError(any(Throwable.class));
}
Also used : InOrder(org.mockito.InOrder) PublishProcessor(io.reactivex.rxjava3.processors.PublishProcessor)

Example 99 with Flowable

use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.

the class FlowableDelayTest method delayWithFlowableSubscriptionThrows.

@Test
public void delayWithFlowableSubscriptionThrows() {
    PublishProcessor<Integer> source = PublishProcessor.create();
    final PublishProcessor<Integer> delay = PublishProcessor.create();
    Supplier<Flowable<Integer>> subFunc = new Supplier<Flowable<Integer>>() {

        @Override
        public Flowable<Integer> get() {
            return delay;
        }
    };
    Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() {

        @Override
        public Flowable<Integer> apply(Integer t1) {
            return delay;
        }
    };
    Subscriber<Object> subscriber = TestHelper.mockSubscriber();
    InOrder inOrder = inOrder(subscriber);
    source.delay(Flowable.defer(subFunc), delayFunc).subscribe(subscriber);
    source.onNext(1);
    delay.onError(new TestException());
    source.onNext(2);
    inOrder.verify(subscriber).onError(any(TestException.class));
    inOrder.verifyNoMoreInteractions();
    verify(subscriber, never()).onNext(any());
    verify(subscriber, never()).onComplete();
}
Also used : InOrder(org.mockito.InOrder) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 100 with Flowable

use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.

the class FlowableDelayTest method delayWithFlowableDelayFunctionThrows.

@Test
public void delayWithFlowableDelayFunctionThrows() {
    PublishProcessor<Integer> source = PublishProcessor.create();
    Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() {

        @Override
        public Flowable<Integer> apply(Integer t1) {
            throw new TestException();
        }
    };
    Subscriber<Object> subscriber = TestHelper.mockSubscriber();
    InOrder inOrder = inOrder(subscriber);
    source.delay(delayFunc).subscribe(subscriber);
    source.onNext(1);
    inOrder.verify(subscriber).onError(any(TestException.class));
    inOrder.verifyNoMoreInteractions();
    verify(subscriber, never()).onNext(any());
    verify(subscriber, never()).onComplete();
}
Also used : InOrder(org.mockito.InOrder) TestException(io.reactivex.rxjava3.exceptions.TestException)

Aggregations

Test (org.junit.Test)159 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)121 TestException (io.reactivex.rxjava3.exceptions.TestException)95 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)49 InOrder (org.mockito.InOrder)41 IOException (java.io.IOException)27 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)22 Disposable (io.reactivex.rxjava3.disposables.Disposable)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)11 io.reactivex.rxjava3.testsupport (io.reactivex.rxjava3.testsupport)9 java.util (java.util)9 Assert (org.junit.Assert)9 Subscriber (org.reactivestreams.Subscriber)9 GroupedFlowable (io.reactivex.rxjava3.flowables.GroupedFlowable)8 java.util.concurrent.atomic (java.util.concurrent.atomic)8 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)7 io.reactivex.rxjava3.functions (io.reactivex.rxjava3.functions)7 Functions (io.reactivex.rxjava3.internal.functions.Functions)7 RxJavaPlugins (io.reactivex.rxjava3.plugins.RxJavaPlugins)7