Search in sources :

Example 1 with PublishSubject

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

the class CompletableCacheTest method crossDisposeOnError.

@Test
public void crossDisposeOnError() {
    PublishSubject<Integer> ps = PublishSubject.create();
    final TestObserver<Void> to1 = new TestObserver<>();
    final TestObserver<Void> to2 = new TestObserver<Void>() {

        @Override
        public void onError(Throwable ex) {
            super.onError(ex);
            to1.dispose();
        }
    };
    Completable c = ps.ignoreElements().cache();
    c.subscribe(to2);
    c.subscribe(to1);
    ps.onError(new TestException());
    to1.assertEmpty();
    to2.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 2 with PublishSubject

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

the class ObservableFlatMapStreamTest method mapperThrowsWhenUpstreamErrors.

@Test
public void mapperThrowsWhenUpstreamErrors() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        PublishSubject<Integer> ps = PublishSubject.create();
        AtomicInteger counter = new AtomicInteger();
        TestObserver<Integer> to = ps.hide().concatMapStream(v -> {
            if (counter.getAndIncrement() == 0) {
                return Stream.of(1, 2);
            }
            ps.onError(new IOException());
            throw new TestException();
        }).test();
        ps.onNext(1);
        ps.onNext(2);
        to.assertFailure(IOException.class, 1, 2);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) io.reactivex.rxjava3.subjects(io.reactivex.rxjava3.subjects) Iterator(java.util.Iterator) TestException(io.reactivex.rxjava3.exceptions.TestException) java.util.stream(java.util.stream) IOException(java.io.IOException) Test(org.junit.Test) NonNull(io.reactivex.rxjava3.annotations.NonNull) Mockito(org.mockito.Mockito) TestHelper(io.reactivex.rxjava3.testsupport.TestHelper) TestObserver(io.reactivex.rxjava3.observers.TestObserver) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Disposable(io.reactivex.rxjava3.disposables.Disposable) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Assert(org.junit.Assert) TestException(io.reactivex.rxjava3.exceptions.TestException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with PublishSubject

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

the class ObservableFlatMapStreamTest method upstreamCancelledCloseCrash.

@Test
public void upstreamCancelledCloseCrash() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        PublishSubject<Integer> ps = PublishSubject.create();
        TestObserver<Integer> to = ps.flatMapStream(v -> Stream.of(v + 1, v + 2).onClose(() -> {
            throw new TestException();
        })).take(1).test();
        assertTrue(ps.hasObservers());
        ps.onNext(1);
        to.assertResult(2);
        assertFalse(ps.hasObservers());
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 4 with PublishSubject

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

the class FutureSingleObserverTest method onErrorCancelRace.

@Test
public void onErrorCancelRace() {
    RxJavaPlugins.setErrorHandler(Functions.emptyConsumer());
    try {
        for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
            final PublishSubject<Integer> ps = PublishSubject.create();
            final Future<?> f = ps.single(-99).toFuture();
            final TestException ex = new TestException();
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    f.cancel(true);
                }
            };
            Runnable r2 = new Runnable() {

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

Example 5 with PublishSubject

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

the class SingleTimeoutTest method shouldUnsubscribeFromUnderlyingSubscriptionOnDispose.

@Test
public void shouldUnsubscribeFromUnderlyingSubscriptionOnDispose() {
    final PublishSubject<String> subject = PublishSubject.create();
    final TestScheduler scheduler = new TestScheduler();
    final TestObserver<String> observer = subject.single("").timeout(100, TimeUnit.MILLISECONDS, scheduler).test();
    assertTrue(subject.hasObservers());
    observer.dispose();
    assertFalse(subject.hasObservers());
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) 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