Search in sources :

Example 26 with PublishSubject

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

the class ObservableMergeWithSingleTest method cancelMainOnOtherError.

@Test
public void cancelMainOnOtherError() {
    PublishSubject<Integer> ps = PublishSubject.create();
    SingleSubject<Integer> ss = SingleSubject.create();
    TestObserver<Integer> to = ps.mergeWith(ss).test();
    assertTrue(ps.hasObservers());
    assertTrue(ss.hasObservers());
    ss.onError(new TestException());
    to.assertFailure(TestException.class);
    assertFalse("main has observers!", ps.hasObservers());
    assertFalse("other has observers", ss.hasObservers());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 27 with PublishSubject

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

the class SerializedSubjectTest method onErrorOnErrorRace.

@Test
public void onErrorOnErrorRace() {
    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();
        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);
            to.assertFailure(TestException.class);
            TestHelper.assertUndeliverable(errors, 0, TestException.class);
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 28 with PublishSubject

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

the class SerializedSubjectTest method onNextOnSubscribeRace.

@Test
public void onNextOnSubscribeRace() {
    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 bs = Disposable.empty();
        Runnable r1 = new Runnable() {

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

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

Example 29 with PublishSubject

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

the class SerializedSubjectTest method onCompleteOnSubscribeRace.

@Test
public void onCompleteOnSubscribeRace() {
    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 bs = Disposable.empty();
        Runnable r1 = new Runnable() {

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

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

Example 30 with PublishSubject

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

the class SerializedSubjectTest method normal.

@Test
public void normal() {
    Subject<Integer> s = PublishSubject.<Integer>create().toSerialized();
    TestObserver<Integer> to = s.test();
    Observable.range(1, 10).subscribe(s);
    to.assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    assertFalse(s.hasObservers());
    s.onNext(11);
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        s.onError(new TestException());
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
    s.onComplete();
    Disposable bs = Disposable.empty();
    s.onSubscribe(bs);
    assertTrue(bs.isDisposed());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TestException(io.reactivex.rxjava3.exceptions.TestException) 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