Search in sources :

Example 26 with TestSubscriberEx

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

the class FlowableFlattenIterableTest method onErrorLate.

@Test
public void onErrorLate() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
        FlattenIterableSubscriber<Integer, Integer> f = new FlattenIterableSubscriber<>(ts, Functions.justFunction(Collections.<Integer>emptyList()), 128);
        f.onSubscribe(new BooleanSubscription());
        f.onError(new TestException("first"));
        ts.assertFailureAndMessage(TestException.class, "first");
        assertTrue(errors.isEmpty());
        f.done = false;
        f.onError(new TestException("second"));
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "second");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : FlattenIterableSubscriber(io.reactivex.rxjava3.internal.operators.flowable.FlowableFlattenIterable.FlattenIterableSubscriber) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)

Example 27 with TestSubscriberEx

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

the class FlowableCombineLatestTest method onErrorDisposeDelayErrorRace.

@Test
public void onErrorDisposeDelayErrorRace() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        TestException ex = new TestException();
        for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
            TestSubscriberEx<Object[]> ts = new TestSubscriberEx<>();
            AtomicReference<Subscriber<? super Object>> ref = new AtomicReference<>();
            Flowable<Object> f = new Flowable<Object>() {

                @Override
                public void subscribeActual(Subscriber<? super Object> s) {
                    ref.set(s);
                }
            };
            Flowable.combineLatestDelayError(Arrays.asList(f, Flowable.never()), (a) -> a).subscribe(ts);
            ref.get().onSubscribe(new BooleanSubscription());
            TestHelper.race(() -> ref.get().onError(ex), () -> ts.cancel());
            if (ts.errors().isEmpty()) {
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            }
        }
    });
}
Also used : java.lang.reflect(java.lang.reflect) java.util(java.util) ArgumentMatchers(org.mockito.ArgumentMatchers) org.mockito(org.mockito) io.reactivex.rxjava3.schedulers(io.reactivex.rxjava3.schedulers) io.reactivex.rxjava3.functions(io.reactivex.rxjava3.functions) java.util.concurrent(java.util.concurrent) ArgsToString(io.reactivex.rxjava3.internal.operators.flowable.FlowableZipTest.ArgsToString) java.util.concurrent.atomic(java.util.concurrent.atomic) io.reactivex.rxjava3.subscribers(io.reactivex.rxjava3.subscribers) Test(org.junit.Test) io.reactivex.rxjava3.exceptions(io.reactivex.rxjava3.exceptions) Mockito(org.mockito.Mockito) QueueFuseable(io.reactivex.rxjava3.operators.QueueFuseable) PublishProcessor(io.reactivex.rxjava3.processors.PublishProcessor) Functions(io.reactivex.rxjava3.internal.functions.Functions) org.reactivestreams(org.reactivestreams) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Assert(org.junit.Assert) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) io.reactivex.rxjava3.testsupport(io.reactivex.rxjava3.testsupport) RxJavaPlugins(io.reactivex.rxjava3.plugins.RxJavaPlugins) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 28 with TestSubscriberEx

use of io.reactivex.rxjava3.testsupport.TestSubscriberEx 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 29 with TestSubscriberEx

use of io.reactivex.rxjava3.testsupport.TestSubscriberEx 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 30 with TestSubscriberEx

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

the class MaybeMergeArrayTest method errorFused.

@Test
public void errorFused() {
    TestSubscriberEx<Integer> ts = new TestSubscriberEx<Integer>().setInitialFusionMode(QueueFuseable.ANY);
    Maybe.mergeArray(Maybe.<Integer>error(new TestException()), Maybe.just(2)).subscribe(ts);
    ts.assertFuseable().assertFusionMode(QueueFuseable.ASYNC).assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)26 TestException (io.reactivex.rxjava3.exceptions.TestException)15 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)12 Disposable (io.reactivex.rxjava3.disposables.Disposable)5 TestSubscriberEx (io.reactivex.rxjava3.testsupport.TestSubscriberEx)5 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)3 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)3 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)2 PublishProcessor (io.reactivex.rxjava3.processors.PublishProcessor)2 Random (java.util.Random)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Assert (org.junit.Assert)2 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)1 Flowable (io.reactivex.rxjava3.core.Flowable)1 io.reactivex.rxjava3.exceptions (io.reactivex.rxjava3.exceptions)1 io.reactivex.rxjava3.functions (io.reactivex.rxjava3.functions)1 BiFunction (io.reactivex.rxjava3.functions.BiFunction)1 Functions (io.reactivex.rxjava3.internal.functions.Functions)1 FlattenIterableSubscriber (io.reactivex.rxjava3.internal.operators.flowable.FlowableFlattenIterable.FlattenIterableSubscriber)1