Search in sources :

Example 31 with TestException

use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.

the class MaybeAmbTest method innerErrorRace.

@Test
public void innerErrorRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final PublishProcessor<Integer> pp0 = PublishProcessor.create();
            final PublishProcessor<Integer> pp1 = PublishProcessor.create();
            final TestObserver<Integer> to = Maybe.amb(Arrays.asList(pp0.singleElement(), pp1.singleElement())).test();
            final TestException ex = new TestException();
            Runnable r1 = new Runnable() {

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

                @Override
                public void run() {
                    pp1.onError(ex);
                }
            };
            TestHelper.race(r1, r2);
            to.assertFailure(TestException.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 32 with TestException

use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.

the class MaybeCacheTest method crossCancelOnError.

@Test
public void crossCancelOnError() {
    final TestSubscriber<Integer> ts = new TestSubscriber<>();
    PublishProcessor<Integer> pp = PublishProcessor.create();
    Maybe<Integer> source = pp.singleElement().cache();
    source.subscribe(Functions.emptyConsumer(), new Consumer<Object>() {

        @Override
        public void accept(Object v) throws Exception {
            ts.cancel();
        }
    });
    source.toFlowable().subscribe(ts);
    pp.onError(new TestException());
    ts.assertEmpty();
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 33 with TestException

use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.

the class FlowableWindowWithStartEndFlowableTest method closeError.

@Test
public void closeError() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        AtomicReference<Subscriber<? super Integer>> ref1 = new AtomicReference<>();
        AtomicReference<Subscriber<? super Integer>> ref2 = new AtomicReference<>();
        Flowable<Integer> f1 = Flowable.<Integer>unsafeCreate(ref1::set);
        Flowable<Integer> f2 = Flowable.<Integer>unsafeCreate(ref2::set);
        TestSubscriber<Integer> ts = BehaviorProcessor.createDefault(1).window(f1, v -> f2).flatMap(v -> v).test();
        ref1.get().onSubscribe(new BooleanSubscription());
        ref1.get().onNext(1);
        ref2.get().onSubscribe(new BooleanSubscription());
        ref2.get().onError(new TestException());
        ref2.get().onError(new TestException());
        ts.assertFailure(TestException.class);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    });
}
Also used : java.util(java.util) io.reactivex.rxjava3.functions(io.reactivex.rxjava3.functions) java.util.concurrent.atomic(java.util.concurrent.atomic) io.reactivex.rxjava3.subscribers(io.reactivex.rxjava3.subscribers) IOException(java.io.IOException) io.reactivex.rxjava3.exceptions(io.reactivex.rxjava3.exceptions) io.reactivex.rxjava3.processors(io.reactivex.rxjava3.processors) TimeUnit(java.util.concurrent.TimeUnit) Functions(io.reactivex.rxjava3.internal.functions.Functions) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) org.reactivestreams(org.reactivestreams) org.junit(org.junit) 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)

Example 34 with TestException

use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.

the class FlowableWindowWithStartEndFlowableTest method windowOpenMainError.

@Test
public void windowOpenMainError() {
    AtomicReference<Subscriber<? super Integer>> ref1 = new AtomicReference<>();
    PublishProcessor<Object> pp = PublishProcessor.create();
    Flowable<Integer> f1 = Flowable.<Integer>unsafeCreate(ref1::set);
    AtomicInteger counter = new AtomicInteger();
    TestSubscriber<Flowable<Object>> ts = pp.window(f1, v -> Flowable.never()).doOnNext(w -> {
        if (counter.getAndIncrement() == 0) {
            ref1.get().onNext(2);
            pp.onNext(1);
            pp.onError(new TestException());
        }
        w.test();
    }).test();
    ref1.get().onSubscribe(new BooleanSubscription());
    ref1.get().onNext(1);
    ts.assertError(TestException.class);
}
Also used : java.util(java.util) io.reactivex.rxjava3.functions(io.reactivex.rxjava3.functions) java.util.concurrent.atomic(java.util.concurrent.atomic) io.reactivex.rxjava3.subscribers(io.reactivex.rxjava3.subscribers) IOException(java.io.IOException) io.reactivex.rxjava3.exceptions(io.reactivex.rxjava3.exceptions) io.reactivex.rxjava3.processors(io.reactivex.rxjava3.processors) TimeUnit(java.util.concurrent.TimeUnit) Functions(io.reactivex.rxjava3.internal.functions.Functions) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) org.reactivestreams(org.reactivestreams) org.junit(org.junit) 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)

Example 35 with TestException

use of io.reactivex.rxjava3.exceptions.TestException in project RxJava by ReactiveX.

the class FlowableWithLatestFromTest method withError.

@Test
public void withError() {
    TestSubscriber<String> ts = new TestSubscriber<>(0);
    Flowable.range(1, 3).withLatestFrom(new Flowable<?>[] { Flowable.just(1), Flowable.error(new TestException()) }, toArray).subscribe(ts);
    ts.assertNoValues();
    ts.assertError(TestException.class);
    ts.assertNotComplete();
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Aggregations

TestException (io.reactivex.rxjava3.exceptions.TestException)656 Test (org.junit.Test)555 IOException (java.io.IOException)95 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)90 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)81 Disposable (io.reactivex.rxjava3.disposables.Disposable)56 InOrder (org.mockito.InOrder)54 TestObserver (io.reactivex.rxjava3.observers.TestObserver)47 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)47 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)40 Observable (io.reactivex.rxjava3.core.Observable)38 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)20 Action (io.reactivex.rxjava3.functions.Action)20 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)20 CompletableSubject (io.reactivex.rxjava3.subjects.CompletableSubject)18 Observer (io.reactivex.rxjava3.core.Observer)15 TestHelper (io.reactivex.rxjava3.testsupport.TestHelper)15 Assert (org.junit.Assert)15 java.util (java.util)13 RxJavaPlugins (io.reactivex.rxjava3.plugins.RxJavaPlugins)12