Search in sources :

Example 41 with TestException

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

the class FlowableDelayTest method testDelayWithFlowableSourceThrows.

@Test
public void testDelayWithFlowableSourceThrows() {
    PublishProcessor<Integer> source = PublishProcessor.create();
    final PublishProcessor<Integer> delay = PublishProcessor.create();
    Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() {

        @Override
        public Flowable<Integer> apply(Integer t1) {
            return delay;
        }
    };
    Subscriber<Object> o = TestHelper.mockSubscriber();
    InOrder inOrder = inOrder(o);
    source.delay(delayFunc).subscribe(o);
    source.onNext(1);
    source.onError(new TestException());
    delay.onNext(1);
    inOrder.verify(o).onError(any(TestException.class));
    inOrder.verifyNoMoreInteractions();
    verify(o, never()).onNext(any());
    verify(o, never()).onComplete();
}
Also used : InOrder(org.mockito.InOrder) TestException(io.reactivex.exceptions.TestException)

Example 42 with TestException

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

the class FlowableDelayTest method testDelayWithFlowableSubscriptionFunctionThrows.

@Test
public void testDelayWithFlowableSubscriptionFunctionThrows() {
    PublishProcessor<Integer> source = PublishProcessor.create();
    final PublishProcessor<Integer> delay = PublishProcessor.create();
    Callable<Flowable<Integer>> subFunc = new Callable<Flowable<Integer>>() {

        @Override
        public Flowable<Integer> call() {
            throw new TestException();
        }
    };
    Function<Integer, Flowable<Integer>> delayFunc = new Function<Integer, Flowable<Integer>>() {

        @Override
        public Flowable<Integer> apply(Integer t1) {
            return delay;
        }
    };
    Subscriber<Object> o = TestHelper.mockSubscriber();
    InOrder inOrder = inOrder(o);
    source.delay(Flowable.defer(subFunc), delayFunc).subscribe(o);
    source.onNext(1);
    delay.onNext(1);
    source.onNext(2);
    inOrder.verify(o).onError(any(TestException.class));
    inOrder.verifyNoMoreInteractions();
    verify(o, never()).onNext(any());
    verify(o, never()).onComplete();
}
Also used : InOrder(org.mockito.InOrder) TestException(io.reactivex.exceptions.TestException)

Example 43 with TestException

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

the class CompletableMergeIterableTest method errorRace.

@Test
public void errorRace() {
    for (int i = 0; i < 500; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final PublishSubject<Integer> ps1 = PublishSubject.create();
            final PublishSubject<Integer> ps2 = PublishSubject.create();
            TestObserver<Void> to = Completable.merge(Arrays.asList(ps1.ignoreElements(), ps2.ignoreElements())).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, Schedulers.single());
            to.assertFailure(TestException.class);
            if (!errors.isEmpty()) {
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : TestException(io.reactivex.exceptions.TestException) Test(org.junit.Test)

Example 44 with TestException

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

the class CompletablePeekTest method onAfterTerminateCrashes.

@Test
public void onAfterTerminateCrashes() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Completable.complete().doAfterTerminate(new Action() {

            @Override
            public void run() throws Exception {
                throw new TestException();
            }
        }).test().assertResult();
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : Action(io.reactivex.functions.Action) TestException(io.reactivex.exceptions.TestException) TestException(io.reactivex.exceptions.TestException) Test(org.junit.Test)

Example 45 with TestException

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

the class CompletableTimeoutTest method errorTimeoutRace.

@Test
public void errorTimeoutRace() {
    for (int i = 0; i < 500; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final TestScheduler scheduler = new TestScheduler();
            final PublishSubject<Integer> ps = PublishSubject.create();
            TestObserver<Void> to = ps.ignoreElements().timeout(1, TimeUnit.MILLISECONDS, scheduler, Completable.complete()).test();
            final TestException ex = new TestException();
            Runnable r1 = new Runnable() {

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

                @Override
                public void run() {
                    scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);
                }
            };
            TestHelper.race(r1, r2, Schedulers.single());
            to.assertTerminated();
            if (!errors.isEmpty()) {
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : TestException(io.reactivex.exceptions.TestException) Test(org.junit.Test)

Aggregations

TestException (io.reactivex.exceptions.TestException)417 Test (org.junit.Test)255 InOrder (org.mockito.InOrder)35 IOException (java.io.IOException)28 BooleanSubscription (io.reactivex.internal.subscriptions.BooleanSubscription)26 TestObserver (io.reactivex.observers.TestObserver)26 Observable (io.reactivex.Observable)24 Function (io.reactivex.functions.Function)24 TestSubscriber (io.reactivex.subscribers.TestSubscriber)24 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)23 TestScheduler (io.reactivex.schedulers.TestScheduler)11 Observer (io.reactivex.Observer)8 QueueDisposable (io.reactivex.internal.fuseable.QueueDisposable)8 Disposable (io.reactivex.disposables.Disposable)7 CrashingIterable (io.reactivex.internal.util.CrashingIterable)6 Action (io.reactivex.functions.Action)5 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)2 ObserveOnObserver (io.reactivex.internal.operators.observable.ObservableObserveOn.ObserveOnObserver)2 ScalarDisposable (io.reactivex.internal.operators.observable.ObservableScalarXMap.ScalarDisposable)2 FutureSubscriber (io.reactivex.internal.subscribers.FutureSubscriber)2