Search in sources :

Example 91 with PublishSubject

use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.

the class ObservableTakeLastTimedTest method takeLastTimedThrowingSource.

@Test
public void takeLastTimedThrowingSource() {
    TestScheduler scheduler = new TestScheduler();
    PublishSubject<Object> source = PublishSubject.create();
    Observable<Object> result = source.takeLast(1, TimeUnit.SECONDS, scheduler);
    Observer<Object> o = TestHelper.mockObserver();
    InOrder inOrder = inOrder(o);
    result.subscribe(o);
    // T: 0ms
    source.onNext(1);
    scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
    // T: 250ms
    source.onNext(2);
    scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
    // T: 500ms
    source.onNext(3);
    scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
    // T: 750ms
    source.onNext(4);
    scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
    // T: 1000ms
    source.onNext(5);
    scheduler.advanceTimeBy(250, TimeUnit.MILLISECONDS);
    // T: 1250ms
    source.onError(new TestException());
    inOrder.verify(o, times(1)).onError(any(TestException.class));
    verify(o, never()).onNext(any());
    verify(o, never()).onComplete();
}
Also used : InOrder(org.mockito.InOrder) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 92 with PublishSubject

use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.

the class SerializedSubjectTest method publishSubjectValueError.

@Test
public void publishSubjectValueError() {
    PublishSubject<Integer> async = PublishSubject.create();
    TestException te = new TestException();
    async.onError(te);
    Subject<Integer> serial = async.toSerialized();
    assertFalse(serial.hasObservers());
    assertFalse(serial.hasComplete());
    assertTrue(serial.hasThrowable());
    assertSame(te, serial.getThrowable());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 93 with PublishSubject

use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.

the class SerializedSubjectTest method onNextOnErrorRace.

@Test
public void onNextOnErrorRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final Subject<Integer> s = PublishSubject.<Integer>create().toSerialized();
        TestObserver<Integer> to = s.test();
        final TestException ex = new TestException();
        Runnable r1 = new Runnable() {

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

            @Override
            public void run() {
                s.onError(ex);
            }
        };
        TestHelper.race(r1, r2);
        to.assertError(ex).assertNotComplete();
        if (to.values().size() != 0) {
            to.assertValue(1);
        }
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 94 with PublishSubject

use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.

the class SerializedSubjectTest method onSubscribeOnSubscribeRace.

@Test
public void onSubscribeOnSubscribeRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final Subject<Integer> s = PublishSubject.<Integer>create().toSerialized();
        TestObserver<Integer> to = s.test();
        final Disposable bs1 = Disposable.empty();
        final Disposable bs2 = Disposable.empty();
        Runnable r1 = new Runnable() {

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

            @Override
            public void run() {
                s.onSubscribe(bs2);
            }
        };
        TestHelper.race(r1, r2);
        to.assertEmpty();
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 95 with PublishSubject

use of io.reactivex.rxjava3.subjects.PublishSubject in project RxJava by ReactiveX.

the class SerializedSubjectTest method onErrorQueued.

@Test
public void onErrorQueued() {
    Subject<Integer> sp = PublishSubject.<Integer>create().toSerialized();
    TestObserver<Integer> to = new TestObserver<Integer>() {

        @Override
        public void onNext(@NonNull Integer t) {
            super.onNext(t);
            if (t == 1) {
                sp.onNext(2);
                sp.onNext(3);
                sp.onSubscribe(Disposable.empty());
                sp.onError(new TestException());
            }
        }
    };
    sp.subscribe(to);
    sp.onNext(1);
    // errors skip ahead
    to.assertFailure(TestException.class, 1);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) NonNull(io.reactivex.rxjava3.annotations.NonNull) TestObserver(io.reactivex.rxjava3.observers.TestObserver) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Aggregations

TestException (io.reactivex.rxjava3.exceptions.TestException)69 Test (org.junit.Test)68 InOrder (org.mockito.InOrder)36 Observable (io.reactivex.rxjava3.core.Observable)28 Disposable (io.reactivex.rxjava3.disposables.Disposable)17 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)17 TestObserver (io.reactivex.rxjava3.observers.TestObserver)14 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 ObservableReplay (io.reactivex.rxjava3.internal.operators.observable.ObservableReplay)4 IOException (java.io.IOException)4 TargetApi (android.annotation.TargetApi)3 Function (io.reactivex.rxjava3.functions.Function)3 CrashingIterable (io.reactivex.rxjava3.internal.util.CrashingIterable)3 PublishSubject (io.reactivex.rxjava3.subjects.PublishSubject)3 Matchers.anyString (org.mockito.Matchers.anyString)3 NonNull (io.reactivex.rxjava3.annotations.NonNull)2 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)1 Observer (io.reactivex.rxjava3.core.Observer)1 GroupedObservable (io.reactivex.rxjava3.observables.GroupedObservable)1