Search in sources :

Example 6 with SerializedObserver

use of io.reactivex.rxjava3.observers.SerializedObserver in project RxJava by ReactiveX.

the class SerializedObserverTest method onCompleteOnErrorRace.

@Test
public void onCompleteOnErrorRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            TestObserverEx<Integer> to = new TestObserverEx<>();
            final SerializedObserver<Integer> so = new SerializedObserver<>(to);
            Disposable d = Disposable.empty();
            so.onSubscribe(d);
            final Throwable ex = new TestException();
            Runnable r1 = new Runnable() {

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

                @Override
                public void run() {
                    so.onComplete();
                }
            };
            TestHelper.race(r1, r2);
            to.awaitDone(5, TimeUnit.SECONDS);
            if (to.completions() != 0) {
                to.assertResult();
            } else {
                to.assertFailure(TestException.class).assertError(ex);
            }
            for (Throwable e : errors) {
                assertTrue(e.toString(), e.getCause() instanceof TestException);
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 7 with SerializedObserver

use of io.reactivex.rxjava3.observers.SerializedObserver in project RxJava by ReactiveX.

the class SerializedObserverTest method onErrorQueuedUp.

@Test
@SuppressUndeliverable
public void onErrorQueuedUp() {
    AtomicReference<SerializedObserver<Integer>> soRef = new AtomicReference<>();
    TestObserverEx<Integer> to = new TestObserverEx<Integer>() {

        @Override
        public void onNext(Integer t) {
            super.onNext(t);
            soRef.get().onNext(2);
            soRef.get().onError(new TestException());
        }
    };
    final SerializedObserver<Integer> so = new SerializedObserver<>(to, true);
    soRef.set(so);
    Disposable d = Disposable.empty();
    so.onSubscribe(d);
    so.onNext(1);
    to.assertFailure(TestException.class, 1, 2);
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 8 with SerializedObserver

use of io.reactivex.rxjava3.observers.SerializedObserver in project RxJava by ReactiveX.

the class SerializedObserverTest method onNextOnErrorRaceDelayError.

@Test
public void onNextOnErrorRaceDelayError() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        TestObserver<Integer> to = new TestObserver<>();
        final SerializedObserver<Integer> so = new SerializedObserver<>(to, true);
        Disposable d = Disposable.empty();
        so.onSubscribe(d);
        final Throwable ex = new TestException();
        Runnable r1 = new Runnable() {

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

            @Override
            public void run() {
                so.onNext(1);
            }
        };
        TestHelper.race(r1, r2);
        to.awaitDone(5, TimeUnit.SECONDS).assertError(ex).assertNotComplete();
        assertTrue(to.values().size() <= 1);
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 9 with SerializedObserver

use of io.reactivex.rxjava3.observers.SerializedObserver in project RxJava by ReactiveX.

the class SerializedObserverTest method errorReentry.

@Test
public void errorReentry() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final AtomicReference<Observer<Integer>> serial = new AtomicReference<>();
        TestObserver<Integer> to = new TestObserver<Integer>() {

            @Override
            public void onNext(Integer v) {
                serial.get().onError(new TestException());
                serial.get().onError(new TestException());
                super.onNext(v);
            }
        };
        SerializedObserver<Integer> sobs = new SerializedObserver<>(to);
        sobs.onSubscribe(Disposable.empty());
        serial.set(sobs);
        sobs.onNext(1);
        to.assertValue(1);
        to.assertError(TestException.class);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 10 with SerializedObserver

use of io.reactivex.rxjava3.observers.SerializedObserver in project RxJava by ReactiveX.

the class SerializedObserverTest method onNextOnCompleteRace.

@Test
public void onNextOnCompleteRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        TestObserver<Integer> to = new TestObserver<>();
        final SerializedObserver<Integer> so = new SerializedObserver<>(to);
        Disposable d = Disposable.empty();
        so.onSubscribe(d);
        Runnable r1 = new Runnable() {

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

            @Override
            public void run() {
                so.onNext(1);
            }
        };
        TestHelper.race(r1, r2);
        to.awaitDone(5, TimeUnit.SECONDS).assertNoErrors().assertComplete();
        assertTrue(to.values().size() <= 1);
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable)

Aggregations

Disposable (io.reactivex.rxjava3.disposables.Disposable)9 TestException (io.reactivex.rxjava3.exceptions.TestException)5 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)2 SerializedObserver (io.reactivex.rxjava3.observers.SerializedObserver)1