Search in sources :

Example 36 with PublishSubject

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

the class CompletableAndThenObservableTest method errorOther.

@Test
public void errorOther() {
    CompletableSubject cs = CompletableSubject.create();
    PublishSubject<Integer> ps = PublishSubject.create();
    TestObserver<Integer> to = cs.andThen(ps).test();
    assertTrue(cs.hasObservers());
    assertFalse(ps.hasObservers());
    cs.onComplete();
    assertFalse(cs.hasObservers());
    assertTrue(ps.hasObservers());
    ps.onError(new TestException());
    assertFalse(cs.hasObservers());
    assertFalse(ps.hasObservers());
    to.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 37 with PublishSubject

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

the class MaybeMergeArrayTest method errorRace.

@Test
public void errorRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final PublishSubject<Integer> ps1 = PublishSubject.create();
            final PublishSubject<Integer> ps2 = PublishSubject.create();
            TestSubscriber<Integer> ts = Maybe.mergeArray(ps1.singleElement(), ps2.singleElement()).test();
            final TestException ex = new TestException();
            Runnable r1 = new Runnable() {

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

                @Override
                public void run() {
                    ps2.onError(ex);
                }
            };
            TestHelper.race(r1, r2);
            ts.assertFailure(Throwable.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 38 with PublishSubject

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

the class ObservableWithLatestFromTest method sourceThrows.

@Test
public void sourceThrows() {
    PublishSubject<Integer> source = PublishSubject.create();
    PublishSubject<Integer> other = PublishSubject.create();
    Observable<Integer> result = source.withLatestFrom(other, COMBINER);
    TestObserverEx<Integer> to = new TestObserverEx<>();
    result.subscribe(to);
    assertTrue(source.hasObservers());
    assertTrue(other.hasObservers());
    other.onNext(1);
    source.onNext(1);
    source.onError(new TestException());
    to.assertTerminated();
    to.assertValue((1 << 8) + 1);
    to.assertError(TestException.class);
    to.assertNotComplete();
    assertFalse(source.hasObservers());
    assertFalse(other.hasObservers());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 39 with PublishSubject

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

the class ObservableWithLatestFromTest method otherThrows.

@Test
public void otherThrows() {
    PublishSubject<Integer> source = PublishSubject.create();
    PublishSubject<Integer> other = PublishSubject.create();
    Observable<Integer> result = source.withLatestFrom(other, COMBINER);
    TestObserverEx<Integer> to = new TestObserverEx<>();
    result.subscribe(to);
    assertTrue(source.hasObservers());
    assertTrue(other.hasObservers());
    other.onNext(1);
    source.onNext(1);
    other.onError(new TestException());
    to.assertTerminated();
    to.assertValue((1 << 8) + 1);
    to.assertNotComplete();
    to.assertError(TestException.class);
    assertFalse(source.hasObservers());
    assertFalse(other.hasObservers());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 40 with PublishSubject

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

the class ObservableZipIterableTest method zipIterableNextThrows.

@Test
public void zipIterableNextThrows() {
    PublishSubject<String> r1 = PublishSubject.create();
    /* define an Observer to receive aggregated events */
    Observer<String> o = TestHelper.mockObserver();
    InOrder io = inOrder(o);
    Iterable<String> r2 = new Iterable<String>() {

        @Override
        public Iterator<String> iterator() {
            return new Iterator<String>() {

                @Override
                public boolean hasNext() {
                    return true;
                }

                @Override
                public String next() {
                    throw new TestException();
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            };
        }
    };
    r1.zipWith(r2, zipr2).subscribe(o);
    r1.onError(new TestException());
    io.verify(o).onError(any(TestException.class));
    verify(o, never()).onNext(any(String.class));
    verify(o, never()).onComplete();
}
Also used : InOrder(org.mockito.InOrder) CrashingIterable(io.reactivex.rxjava3.internal.util.CrashingIterable) TestException(io.reactivex.rxjava3.exceptions.TestException)

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