Search in sources :

Example 51 with PublishProcessor

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

the class SerializedProcessorTest method onErrorOnErrorRace.

@Test
public void onErrorOnErrorRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final FlowableProcessor<Integer> s = PublishProcessor.<Integer>create().toSerialized();
        TestSubscriber<Integer> ts = s.test();
        final TestException ex = new TestException();
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    s.onError(ex);
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    s.onError(ex);
                }
            };
            TestHelper.race(r1, r2);
            ts.assertFailure(TestException.class);
            TestHelper.assertUndeliverable(errors, 0, TestException.class);
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 52 with PublishProcessor

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

the class SerializedProcessorTest method normal.

@Test
public void normal() {
    FlowableProcessor<Integer> s = PublishProcessor.<Integer>create().toSerialized();
    TestSubscriber<Integer> ts = s.test();
    Flowable.range(1, 10).subscribe(s);
    ts.assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    assertFalse(s.hasSubscribers());
    s.onNext(11);
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        s.onError(new TestException());
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
    s.onComplete();
    BooleanSubscription bs = new BooleanSubscription();
    s.onSubscribe(bs);
    assertTrue(bs.isCancelled());
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 53 with PublishProcessor

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

the class CompletableSwitchOnNextTest method delaySwitch.

@Test
public void delaySwitch() {
    PublishProcessor<Completable> pp = PublishProcessor.create();
    TestObserver<Void> to = Completable.switchOnNextDelayError(pp).test();
    assertTrue(pp.hasSubscribers());
    to.assertEmpty();
    CompletableSubject cs1 = CompletableSubject.create();
    CompletableSubject cs2 = CompletableSubject.create();
    pp.onNext(cs1);
    assertTrue(cs1.hasObservers());
    pp.onNext(cs2);
    assertFalse(cs1.hasObservers());
    assertTrue(cs2.hasObservers());
    assertTrue(cs2.hasObservers());
    cs2.onError(new TestException());
    assertTrue(pp.hasSubscribers());
    to.assertEmpty();
    pp.onComplete();
    to.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) CompletableSubject(io.reactivex.rxjava3.subjects.CompletableSubject) Test(org.junit.Test)

Example 54 with PublishProcessor

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

the class CompletableAmbTest method innerErrorRace.

@Test
public void innerErrorRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final PublishProcessor<Integer> pp0 = PublishProcessor.create();
            final PublishProcessor<Integer> pp1 = PublishProcessor.create();
            final TestObserver<Void> to = Completable.amb(Arrays.asList(pp0.ignoreElements(), pp1.ignoreElements())).test();
            final TestException ex = new TestException();
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    pp0.onError(ex);
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    pp1.onError(ex);
                }
            };
            TestHelper.race(r1, r2);
            to.assertFailure(TestException.class);
            if (!errors.isEmpty()) {
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 55 with PublishProcessor

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

the class CompletableMergeTest method mainErrorInnerErrorRace.

@Test
public void mainErrorInnerErrorRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final PublishProcessor<Integer> pp1 = PublishProcessor.create();
            final PublishProcessor<Integer> pp2 = PublishProcessor.create();
            TestObserverEx<Void> to = Completable.merge(pp1.map(new Function<Integer, Completable>() {

                @Override
                public Completable apply(Integer v) throws Exception {
                    return pp2.ignoreElements();
                }
            })).to(TestHelper.<Void>testConsumer());
            pp1.onNext(1);
            final Throwable ex1 = new TestException();
            final Throwable ex2 = new TestException();
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    pp1.onError(ex1);
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    pp2.onError(ex2);
                }
            };
            TestHelper.race(r1, r2);
            Throwable ex = to.errors().get(0);
            if (ex instanceof CompositeException) {
                to.assertSubscribed().assertNoValues().assertNotComplete();
                errors = TestHelper.compositeList(ex);
                TestHelper.assertError(errors, 0, TestException.class);
                TestHelper.assertError(errors, 1, TestException.class);
            } else {
                to.assertFailure(TestException.class);
                if (!errors.isEmpty()) {
                    TestHelper.assertUndeliverable(errors, 0, TestException.class);
                }
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : AtomicThrowable(io.reactivex.rxjava3.internal.util.AtomicThrowable) 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