Search in sources :

Example 41 with PublishProcessor

use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.

the class FlowableTakeUntilTest method untilPublisherOtherError.

@Test
public void untilPublisherOtherError() {
    PublishProcessor<Integer> main = PublishProcessor.create();
    PublishProcessor<Integer> other = PublishProcessor.create();
    TestSubscriber<Integer> ts = main.takeUntil(other).test();
    assertTrue("Main no subscribers?", main.hasSubscribers());
    assertTrue("Other no subscribers?", other.hasSubscribers());
    other.onError(new TestException());
    assertFalse("Main has subscribers?", main.hasSubscribers());
    assertFalse("Other has subscribers?", other.hasSubscribers());
    ts.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 42 with PublishProcessor

use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.

the class FlowableTimeoutWithSelectorTest method lateOnTimeoutError.

@Test
public void lateOnTimeoutError() {
    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) {
                    s.onSubscribe(new BooleanSubscription());
                    sub[count++] = s;
                }
            };
            TestSubscriber<Integer> ts = pp.timeout(Functions.justFunction(pp2)).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 43 with PublishProcessor

use of io.reactivex.rxjava3.processors.PublishProcessor in project RxJava by ReactiveX.

the class FlowableRetryWithPredicateTest method unsubscribeFromRetry.

@Test
public void unsubscribeFromRetry() {
    PublishProcessor<Integer> processor = PublishProcessor.create();
    final AtomicInteger count = new AtomicInteger(0);
    Disposable sub = processor.retry(retryTwice).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer n) {
            count.incrementAndGet();
        }
    });
    processor.onNext(1);
    sub.dispose();
    processor.onNext(2);
    assertEquals(1, count.get());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) Test(org.junit.Test)

Example 44 with PublishProcessor

use of io.reactivex.rxjava3.processors.PublishProcessor 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 45 with PublishProcessor

use of io.reactivex.rxjava3.processors.PublishProcessor 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)

Aggregations

Test (org.junit.Test)124 TestException (io.reactivex.rxjava3.exceptions.TestException)88 InOrder (org.mockito.InOrder)25 CompletableSubject (io.reactivex.rxjava3.subjects.CompletableSubject)24 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)18 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)18 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)18 Disposable (io.reactivex.rxjava3.disposables.Disposable)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 Assert (org.junit.Assert)8 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)7 io.reactivex.rxjava3.exceptions (io.reactivex.rxjava3.exceptions)6 io.reactivex.rxjava3.processors (io.reactivex.rxjava3.processors)6 PublishProcessor (io.reactivex.rxjava3.processors.PublishProcessor)6 IOException (java.io.IOException)6 TimeUnit (java.util.concurrent.TimeUnit)6 Functions (io.reactivex.rxjava3.internal.functions.Functions)5 FlowableReplay (io.reactivex.rxjava3.internal.operators.flowable.FlowableReplay)4 RxJavaPlugins (io.reactivex.rxjava3.plugins.RxJavaPlugins)4 io.reactivex.rxjava3.testsupport (io.reactivex.rxjava3.testsupport)4