Search in sources :

Example 56 with BooleanSubscription

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

the class FlowableRetryWithPredicateTest method retryOnSpecificExceptionAndNotOther.

@Test
public void retryOnSpecificExceptionAndNotOther() {
    final IOException ioe = new IOException();
    final TestException te = new TestException();
    Flowable<Integer> source = Flowable.unsafeCreate(new Publisher<Integer>() {

        int count;

        @Override
        public void subscribe(Subscriber<? super Integer> t1) {
            t1.onSubscribe(new BooleanSubscription());
            count++;
            t1.onNext(0);
            t1.onNext(1);
            if (count == 1) {
                t1.onError(ioe);
                return;
            }
            t1.onNext(2);
            t1.onNext(3);
            t1.onError(te);
        }
    });
    Subscriber<Integer> subscriber = TestHelper.mockSubscriber();
    InOrder inOrder = inOrder(subscriber);
    source.retry(retryOnTestException).subscribe(subscriber);
    inOrder.verify(subscriber).onNext(0);
    inOrder.verify(subscriber).onNext(1);
    inOrder.verify(subscriber).onNext(0);
    inOrder.verify(subscriber).onNext(1);
    inOrder.verify(subscriber).onNext(2);
    inOrder.verify(subscriber).onNext(3);
    inOrder.verify(subscriber).onError(te);
    verify(subscriber, never()).onError(ioe);
    verify(subscriber, never()).onComplete();
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) InOrder(org.mockito.InOrder) IOException(java.io.IOException) Test(org.junit.Test)

Example 57 with BooleanSubscription

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

the class FlowableSequenceEqualTest method doubleErrorFlowable.

@Test
public void doubleErrorFlowable() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Flowable.sequenceEqual(Flowable.never(), new Flowable<Object>() {

            @Override
            protected void subscribeActual(Subscriber<? super Object> s) {
                s.onSubscribe(new BooleanSubscription());
                s.onError(new TestException("First"));
                s.onError(new TestException("Second"));
            }
        }, 8).toFlowable().to(TestHelper.<Boolean>testConsumer()).assertFailureAndMessage(TestException.class, "First");
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Subscriber(org.reactivestreams.Subscriber) Test(org.junit.Test)

Example 58 with BooleanSubscription

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

the class FlowableTimeoutWithSelectorTest method lateOnTimeoutFallbackRace.

@Test
public void lateOnTimeoutFallbackRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final PublishProcessor<Integer> pp = PublishProcessor.create();
            final Subscriber<?>[] sub = { null, null };
            final Flowable<Integer> pp2 = new Flowable<Integer>() {

                int count;

                @Override
                protected void subscribeActual(Subscriber<? super Integer> s) {
                    assertFalse(((Disposable) s).isDisposed());
                    s.onSubscribe(new BooleanSubscription());
                    sub[count++] = s;
                }
            };
            TestSubscriber<Integer> ts = pp.timeout(Functions.justFunction(pp2), Flowable.<Integer>never()).test();
            pp.onNext(0);
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    pp.onNext(1);
                }
            };
            final Throwable ex = new TestException();
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    sub[0].onError(ex);
                }
            };
            TestHelper.race(r1, r2);
            ts.assertValueAt(0, 0);
            if (!errors.isEmpty()) {
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 59 with BooleanSubscription

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

the class FlowableTimeoutWithSelectorTest method onCompleteOnTimeoutRaceFallback.

@Test
public void onCompleteOnTimeoutRaceFallback() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final PublishProcessor<Integer> pp = PublishProcessor.create();
            final Subscriber<?>[] sub = { null, null };
            final Flowable<Integer> pp2 = new Flowable<Integer>() {

                int count;

                @Override
                protected void subscribeActual(Subscriber<? super Integer> s) {
                    assertFalse(((Disposable) s).isDisposed());
                    s.onSubscribe(new BooleanSubscription());
                    sub[count++] = s;
                }
            };
            TestSubscriber<Integer> ts = pp.timeout(Functions.justFunction(pp2), Flowable.<Integer>never()).test();
            pp.onNext(0);
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    pp.onComplete();
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    sub[0].onComplete();
                }
            };
            TestHelper.race(r1, r2);
            ts.assertValueAt(0, 0);
            if (!errors.isEmpty()) {
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 60 with BooleanSubscription

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

the class FlowableTimeoutWithSelectorTest method badSourceTimeout.

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

            @Override
            protected void subscribeActual(Subscriber<? super Integer> subscriber) {
                subscriber.onSubscribe(new BooleanSubscription());
                subscriber.onNext(1);
                subscriber.onNext(2);
                subscriber.onError(new TestException("First"));
                subscriber.onNext(3);
                subscriber.onComplete();
                subscriber.onError(new TestException("Second"));
            }
        }.timeout(Functions.justFunction(Flowable.never()), Flowable.<Integer>never()).take(1).test().assertResult(1);
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "First");
        TestHelper.assertUndeliverable(errors, 1, TestException.class, "Second");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

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