Search in sources :

Example 16 with TestException

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

the class FlowableFlatMapStreamTest method mapperThrowsWhenUpstreamErrors.

@Test
public void mapperThrowsWhenUpstreamErrors() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        PublishProcessor<Integer> pp = PublishProcessor.create();
        AtomicInteger counter = new AtomicInteger();
        TestSubscriber<Integer> ts = pp.hide().concatMapStream(v -> {
            if (counter.getAndIncrement() == 0) {
                return Stream.of(1, 2);
            }
            pp.onError(new IOException());
            throw new TestException();
        }).test();
        pp.onNext(1);
        pp.onNext(2);
        ts.assertFailure(IOException.class, 1, 2);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Iterator(java.util.Iterator) java.util.stream(java.util.stream) IOException(java.io.IOException) Test(org.junit.Test) io.reactivex.rxjava3.exceptions(io.reactivex.rxjava3.exceptions) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) io.reactivex.rxjava3.processors(io.reactivex.rxjava3.processors) Mockito(org.mockito.Mockito) TestHelper(io.reactivex.rxjava3.testsupport.TestHelper) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Assert(org.junit.Assert) Subscriber(org.reactivestreams.Subscriber) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IOException(java.io.IOException) Test(org.junit.Test)

Example 17 with TestException

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

the class ParallelCollectorTest method doubleError.

@Test
public void doubleError() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        new ParallelInvalid().collect(Collectors.toList()).test().assertFailure(TestException.class);
        assertFalse(errors.isEmpty());
        for (Throwable ex : errors) {
            assertTrue(ex.toString(), ex.getCause() instanceof TestException);
        }
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : ParallelInvalid(io.reactivex.rxjava3.parallel.ParallelInvalid) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 18 with TestException

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

the class SingleFlattenStreamAsObservableTest method streamCloseCrash.

@Test
public void streamCloseCrash() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        Single.just(1).flattenStreamAsObservable(v -> Stream.of(v).onClose(() -> {
            throw new TestException();
        })).test().assertResult(1);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    });
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 19 with TestException

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

the class SingleFlattenStreamAsObservableTest method hasNextThrowsInDrain.

@Test
public void hasNextThrowsInDrain() {
    @SuppressWarnings("unchecked") Stream<Integer> stream = mock(Stream.class);
    when(stream.iterator()).thenReturn(new Iterator<Integer>() {

        int count;

        @Override
        public boolean hasNext() {
            if (count++ > 0) {
                throw new TestException();
            }
            return true;
        }

        @Override
        public Integer next() {
            return 1;
        }
    });
    Single.just(1).flattenStreamAsObservable(v -> stream).test().assertFailure(TestException.class, 1);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 20 with TestException

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

the class ObservableFlatMapStreamTest method hasNextThrowsLater.

@Test
public void hasNextThrowsLater() {
    AtomicInteger counter = new AtomicInteger();
    Observable.just(1).hide().concatMapStream(v -> Stream.generate(() -> {
        if (counter.getAndIncrement() == 0) {
            return 1;
        }
        throw new TestException();
    })).test().assertFailure(TestException.class, 1);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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