Search in sources :

Example 46 with BooleanSubscription

use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.

the class FlowableSwitchTest method switchWithError.

@Test
public void switchWithError() {
    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(final Subscriber<? super String> subscriber) {
                    subscriber.onSubscribe(new BooleanSubscription());
                    publishNext(subscriber, 50, "one");
                    publishNext(subscriber, 100, "two");
                }
            }));
            publishNext(subscriber, 200, Flowable.unsafeCreate(new Publisher<String>() {

                @Override
                public void subscribe(Subscriber<? super String> subscriber) {
                    subscriber.onSubscribe(new BooleanSubscription());
                    publishNext(subscriber, 0, "three");
                    publishNext(subscriber, 100, "four");
                }
            }));
            publishError(subscriber, 250, new TestException());
        }
    });
    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(175, TimeUnit.MILLISECONDS);
    inOrder.verify(subscriber, times(1)).onNext("two");
    verify(subscriber, never()).onComplete();
    verify(subscriber, never()).onError(any(Throwable.class));
    scheduler.advanceTimeTo(225, TimeUnit.MILLISECONDS);
    inOrder.verify(subscriber, times(1)).onNext("three");
    verify(subscriber, never()).onComplete();
    verify(subscriber, never()).onError(any(Throwable.class));
    scheduler.advanceTimeTo(350, TimeUnit.MILLISECONDS);
    inOrder.verify(subscriber, never()).onNext(anyString());
    verify(subscriber, never()).onComplete();
    verify(subscriber, times(1)).onError(any(TestException.class));
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) InOrder(org.mockito.InOrder)

Example 47 with BooleanSubscription

use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription in project RxJava by ReactiveX.

the class FlowableSwitchTest method switchIssue737.

@Test
public void switchIssue737() {
    // https://github.com/ReactiveX/RxJava/issues/737
    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, 0, Flowable.unsafeCreate(new Publisher<String>() {

                @Override
                public void subscribe(Subscriber<? super String> subscriber) {
                    subscriber.onSubscribe(new BooleanSubscription());
                    publishNext(subscriber, 10, "1-one");
                    publishNext(subscriber, 20, "1-two");
                    // The following events will be ignored
                    publishNext(subscriber, 30, "1-three");
                    publishCompleted(subscriber, 40);
                }
            }));
            publishNext(subscriber, 25, Flowable.unsafeCreate(new Publisher<String>() {

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

Example 48 with BooleanSubscription

use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription 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 49 with BooleanSubscription

use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription 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 50 with BooleanSubscription

use of io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription 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)

Aggregations

BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)227 Test (org.junit.Test)152 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)81 TestException (io.reactivex.rxjava3.exceptions.TestException)40 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)32 IOException (java.io.IOException)26 InOrder (org.mockito.InOrder)19 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)12 Subscriber (org.reactivestreams.Subscriber)11 io.reactivex.rxjava3.testsupport (io.reactivex.rxjava3.testsupport)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 Assert (org.junit.Assert)10 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 io.reactivex.rxjava3.functions (io.reactivex.rxjava3.functions)8 Functions (io.reactivex.rxjava3.internal.functions.Functions)8 ConditionalSubscriber (io.reactivex.rxjava3.operators.ConditionalSubscriber)8 RxJavaPlugins (io.reactivex.rxjava3.plugins.RxJavaPlugins)8 io.reactivex.rxjava3.processors (io.reactivex.rxjava3.processors)8 java.util (java.util)8