Search in sources :

Example 21 with TestHelper

use of io.reactivex.rxjava3.testsupport.TestHelper in project RxJava by ReactiveX.

the class SingleFlatMapTest method flatMapPublisherCancelDuringFlowable.

@Test
public void flatMapPublisherCancelDuringFlowable() {
    final AtomicBoolean disposed = new AtomicBoolean();
    TestSubscriberEx<Integer> ts = Single.just(1).flatMapPublisher(new Function<Integer, Publisher<Integer>>() {

        @Override
        public Publisher<Integer> apply(Integer v) throws Exception {
            return Flowable.<Integer>never().doOnCancel(new Action() {

                @Override
                public void run() throws Exception {
                    disposed.set(true);
                }
            });
        }
    }).to(TestHelper.<Integer>testConsumer()).assertNoValues().assertNotTerminated();
    assertFalse(disposed.get());
    ts.cancel();
    assertTrue(disposed.get());
    ts.assertNotTerminated();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 22 with TestHelper

use of io.reactivex.rxjava3.testsupport.TestHelper in project RxJava by ReactiveX.

the class ObservableReplayEagerTruncateTest method badSource.

@Test
public void badSource() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        new Observable<Integer>() {

            @Override
            protected void subscribeActual(Observer<? super Integer> observer) {
                observer.onSubscribe(Disposable.empty());
                observer.onError(new TestException("First"));
                observer.onNext(1);
                observer.onError(new TestException("Second"));
                observer.onComplete();
            }
        }.replay().autoConnect().to(TestHelper.<Integer>testConsumer()).assertFailureAndMessage(TestException.class, "First");
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Observer(io.reactivex.rxjava3.core.Observer) Observable(io.reactivex.rxjava3.core.Observable) ConnectableObservable(io.reactivex.rxjava3.observables.ConnectableObservable)

Example 23 with TestHelper

use of io.reactivex.rxjava3.testsupport.TestHelper in project RxJava by ReactiveX.

the class FlowableSwitchMapMaybeTest method innerErrorAfterTermination.

@Test
public void innerErrorAfterTermination() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final AtomicReference<MaybeObserver<? super Integer>> moRef = new AtomicReference<>();
        TestSubscriberEx<Integer> ts = new Flowable<Integer>() {

            @Override
            protected void subscribeActual(Subscriber<? super Integer> s) {
                s.onSubscribe(new BooleanSubscription());
                s.onNext(1);
                s.onError(new TestException("outer"));
            }
        }.switchMapMaybe(new Function<Integer, MaybeSource<Integer>>() {

            @Override
            public MaybeSource<Integer> apply(Integer v) throws Exception {
                return new Maybe<Integer>() {

                    @Override
                    protected void subscribeActual(MaybeObserver<? super Integer> observer) {
                        observer.onSubscribe(Disposable.empty());
                        moRef.set(observer);
                    }
                };
            }
        }).to(TestHelper.<Integer>testConsumer());
        ts.assertFailureAndMessage(TestException.class, "outer");
        moRef.get().onError(new TestException("inner"));
        moRef.get().onComplete();
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "inner");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) AtomicReference(java.util.concurrent.atomic.AtomicReference) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 24 with TestHelper

use of io.reactivex.rxjava3.testsupport.TestHelper in project RxJava by ReactiveX.

the class FlowableSwitchMapSingleTest method innerErrorAfterTermination.

@Test
public void innerErrorAfterTermination() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final AtomicReference<SingleObserver<? super Integer>> moRef = new AtomicReference<>();
        TestSubscriberEx<Integer> ts = new Flowable<Integer>() {

            @Override
            protected void subscribeActual(Subscriber<? super Integer> s) {
                s.onSubscribe(new BooleanSubscription());
                s.onNext(1);
                s.onError(new TestException("outer"));
            }
        }.switchMapSingle(new Function<Integer, SingleSource<Integer>>() {

            @Override
            public SingleSource<Integer> apply(Integer v) throws Exception {
                return new Single<Integer>() {

                    @Override
                    protected void subscribeActual(SingleObserver<? super Integer> observer) {
                        observer.onSubscribe(Disposable.empty());
                        moRef.set(observer);
                    }
                };
            }
        }).to(TestHelper.<Integer>testConsumer());
        ts.assertFailureAndMessage(TestException.class, "outer");
        moRef.get().onError(new TestException("inner"));
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "inner");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) AtomicReference(java.util.concurrent.atomic.AtomicReference) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 25 with TestHelper

use of io.reactivex.rxjava3.testsupport.TestHelper in project RxJava by ReactiveX.

the class MaybeMergeTest method delayErrorWithMaxConcurrencyAsyncError.

@Test
public void delayErrorWithMaxConcurrencyAsyncError() {
    final AtomicInteger count = new AtomicInteger();
    @SuppressWarnings("unchecked") Maybe<Integer>[] sources = new Maybe[3];
    for (int i = 0; i < 3; i++) {
        final int j = i + 1;
        sources[i] = Maybe.fromCallable(new Callable<Integer>() {

            @Override
            public Integer call() throws Exception {
                return count.incrementAndGet() - j;
            }
        }).subscribeOn(Schedulers.io());
    }
    sources[1] = Maybe.fromCallable(new Callable<Integer>() {

        @Override
        public Integer call() throws Exception {
            throw new TestException("" + count.incrementAndGet());
        }
    }).subscribeOn(Schedulers.io());
    for (int i = 0; i < 1000; i++) {
        count.set(0);
        Maybe.mergeDelayError(Flowable.fromArray(sources), 1).to(TestHelper.<Integer>testConsumer()).awaitDone(5, TimeUnit.SECONDS).assertFailureAndMessage(TestException.class, "2", 0, 0);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestException(io.reactivex.rxjava3.exceptions.TestException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)21 TestException (io.reactivex.rxjava3.exceptions.TestException)19 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)9 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)6 Disposable (io.reactivex.rxjava3.disposables.Disposable)3 ConnectableFlowable (io.reactivex.rxjava3.flowables.ConnectableFlowable)3 TestObserver (io.reactivex.rxjava3.observers.TestObserver)3 Observable (io.reactivex.rxjava3.core.Observable)2 Observer (io.reactivex.rxjava3.core.Observer)2 AtomicThrowable (io.reactivex.rxjava3.internal.util.AtomicThrowable)2 ConnectableObservable (io.reactivex.rxjava3.observables.ConnectableObservable)2 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Action (io.reactivex.rxjava3.functions.Action)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Subscriber (org.reactivestreams.Subscriber)1