Search in sources :

Example 56 with Flowable

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

the class FlowableSwitchTest method switchWhenInnerCompleteBeforeOuter.

@Test
public void switchWhenInnerCompleteBeforeOuter() {
    Flowable<Flowable<String>> source = Flowable.unsafeCreate(new Publisher<Flowable<String>>() {

        @Override
        public void subscribe(Subscriber<? super Flowable<String>> subscriber) {
            subscriber.onSubscribe(new BooleanSubscription());
            publishNext(subscriber, 10, Flowable.unsafeCreate(new Publisher<String>() {

                @Override
                public void subscribe(Subscriber<? super String> subscriber) {
                    subscriber.onSubscribe(new BooleanSubscription());
                    publishNext(subscriber, 0, "one");
                    publishNext(subscriber, 10, "two");
                    publishCompleted(subscriber, 20);
                }
            }));
            publishNext(subscriber, 100, Flowable.unsafeCreate(new Publisher<String>() {

                @Override
                public void subscribe(Subscriber<? super String> subscriber) {
                    subscriber.onSubscribe(new BooleanSubscription());
                    publishNext(subscriber, 0, "three");
                    publishNext(subscriber, 10, "four");
                    publishCompleted(subscriber, 20);
                }
            }));
            publishCompleted(subscriber, 200);
        }
    });
    Flowable<String> sampled = Flowable.switchOnNext(source);
    sampled.subscribe(subscriber);
    InOrder inOrder = inOrder(subscriber);
    scheduler.advanceTimeTo(150, TimeUnit.MILLISECONDS);
    inOrder.verify(subscriber, never()).onComplete();
    inOrder.verify(subscriber, times(1)).onNext("one");
    inOrder.verify(subscriber, times(1)).onNext("two");
    inOrder.verify(subscriber, times(1)).onNext("three");
    inOrder.verify(subscriber, times(1)).onNext("four");
    scheduler.advanceTimeTo(250, TimeUnit.MILLISECONDS);
    inOrder.verify(subscriber, never()).onNext(anyString());
    inOrder.verify(subscriber, times(1)).onComplete();
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) InOrder(org.mockito.InOrder)

Example 57 with Flowable

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

the class FlowableSwitchTest method badInnerSource.

@Test
public void badInnerSource() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Flowable.just(1).hide().switchMap(Functions.justFunction(new Flowable<Integer>() {

            @Override
            protected void subscribeActual(Subscriber<? super Integer> subscriber) {
                subscriber.onSubscribe(new BooleanSubscription());
                subscriber.onError(new TestException());
                subscriber.onComplete();
                subscriber.onError(new TestException());
                subscriber.onComplete();
            }
        })).test().assertFailure(TestException.class);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)

Example 58 with Flowable

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

the class FlowableSwitchTest method switchWithSubsequenceComplete.

@Test
public void switchWithSubsequenceComplete() {
    Flowable<Flowable<String>> source = Flowable.unsafeCreate(new Publisher<Flowable<String>>() {

        @Override
        public void subscribe(Subscriber<? super Flowable<String>> subscriber) {
            subscriber.onSubscribe(new BooleanSubscription());
            publishNext(subscriber, 50, Flowable.unsafeCreate(new Publisher<String>() {

                @Override
                public void subscribe(Subscriber<? super String> subscriber) {
                    subscriber.onSubscribe(new BooleanSubscription());
                    publishNext(subscriber, 50, "one");
                    publishNext(subscriber, 100, "two");
                }
            }));
            publishNext(subscriber, 130, Flowable.unsafeCreate(new Publisher<String>() {

                @Override
                public void subscribe(Subscriber<? super String> subscriber) {
                    subscriber.onSubscribe(new BooleanSubscription());
                    publishCompleted(subscriber, 0);
                }
            }));
            publishNext(subscriber, 150, Flowable.unsafeCreate(new Publisher<String>() {

                @Override
                public void subscribe(Subscriber<? super String> subscriber) {
                    subscriber.onSubscribe(new BooleanSubscription());
                    publishNext(subscriber, 50, "three");
                }
            }));
        }
    });
    Flowable<String> sampled = Flowable.switchOnNext(source);
    sampled.subscribe(subscriber);
    InOrder inOrder = inOrder(subscriber);
    scheduler.advanceTimeTo(90, TimeUnit.MILLISECONDS);
    inOrder.verify(subscriber, never()).onNext(anyString());
    verify(subscriber, never()).onComplete();
    verify(subscriber, never()).onError(any(Throwable.class));
    scheduler.advanceTimeTo(125, TimeUnit.MILLISECONDS);
    inOrder.verify(subscriber, times(1)).onNext("one");
    verify(subscriber, never()).onComplete();
    verify(subscriber, never()).onError(any(Throwable.class));
    scheduler.advanceTimeTo(250, TimeUnit.MILLISECONDS);
    inOrder.verify(subscriber, times(1)).onNext("three");
    verify(subscriber, never()).onComplete();
    verify(subscriber, never()).onError(any(Throwable.class));
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) InOrder(org.mockito.InOrder)

Example 59 with Flowable

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

the class FlowableTakeTest2 method cancelIgnored.

@Test
public void cancelIgnored() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        new Flowable<Integer>() {

            @Override
            protected void subscribeActual(Subscriber<? super Integer> s) {
                BooleanSubscription bs = new BooleanSubscription();
                s.onSubscribe(bs);
                assertTrue(bs.isCancelled());
                s.onNext(1);
                s.onComplete();
                s.onError(new TestException());
                s.onSubscribe(null);
            }
        }.take(0).test().assertResult();
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
        TestHelper.assertError(errors, 1, NullPointerException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 60 with Flowable

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

the class FlowableTakeUntilPredicateTest method sourceThrows.

@Test
public void sourceThrows() {
    Subscriber<Object> subscriber = TestHelper.mockSubscriber();
    Flowable.just(1).concatWith(Flowable.<Integer>error(new TestException())).concatWith(Flowable.just(2)).takeUntil(new Predicate<Integer>() {

        @Override
        public boolean test(Integer v) {
            return false;
        }
    }).subscribe(subscriber);
    verify(subscriber).onNext(1);
    verify(subscriber, never()).onNext(2);
    verify(subscriber).onError(any(TestException.class));
    verify(subscriber, never()).onComplete();
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

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