Search in sources :

Example 6 with TestException

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

the class ObservableFromStreamTest method hasNextCrash.

@Test
public void hasNextCrash() {
    AtomicInteger v = new AtomicInteger();
    Observable.fromStream(Stream.<Integer>generate(() -> {
        int value = v.getAndIncrement();
        if (value == 1) {
            throw new TestException();
        }
        return value;
    })).test().assertFailure(TestException.class, 0);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 7 with TestException

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

the class CompletableCacheTest method error.

@Test
public void error() {
    Completable c = Completable.error(new TestException()).doOnSubscribe(this).cache();
    assertEquals(0, count);
    c.test().assertFailure(TestException.class);
    assertEquals(1, count);
    c.test().assertFailure(TestException.class);
    assertEquals(1, count);
    c.test().assertFailure(TestException.class);
    assertEquals(1, count);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 8 with TestException

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

the class CompletableCacheTest method crossDisposeOnError.

@Test
public void crossDisposeOnError() {
    PublishSubject<Integer> ps = PublishSubject.create();
    final TestObserver<Void> to1 = new TestObserver<>();
    final TestObserver<Void> to2 = new TestObserver<Void>() {

        @Override
        public void onError(Throwable ex) {
            super.onError(ex);
            to1.dispose();
        }
    };
    Completable c = ps.ignoreElements().cache();
    c.subscribe(to2);
    c.subscribe(to1);
    ps.onError(new TestException());
    to1.assertEmpty();
    to2.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 9 with TestException

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

the class ObservableFlatMapStreamTest method mapperThrowsWhenUpstreamErrors.

@Test
public void mapperThrowsWhenUpstreamErrors() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        PublishSubject<Integer> ps = PublishSubject.create();
        AtomicInteger counter = new AtomicInteger();
        TestObserver<Integer> to = ps.hide().concatMapStream(v -> {
            if (counter.getAndIncrement() == 0) {
                return Stream.of(1, 2);
            }
            ps.onError(new IOException());
            throw new TestException();
        }).test();
        ps.onNext(1);
        ps.onNext(2);
        to.assertFailure(IOException.class, 1, 2);
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) io.reactivex.rxjava3.subjects(io.reactivex.rxjava3.subjects) Iterator(java.util.Iterator) TestException(io.reactivex.rxjava3.exceptions.TestException) java.util.stream(java.util.stream) IOException(java.io.IOException) Test(org.junit.Test) NonNull(io.reactivex.rxjava3.annotations.NonNull) Mockito(org.mockito.Mockito) TestHelper(io.reactivex.rxjava3.testsupport.TestHelper) TestObserver(io.reactivex.rxjava3.observers.TestObserver) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Disposable(io.reactivex.rxjava3.disposables.Disposable) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Assert(org.junit.Assert) TestException(io.reactivex.rxjava3.exceptions.TestException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with TestException

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

the class ObservableFlatMapStreamTest method fusedPollCrash.

@Test
public void fusedPollCrash() {
    UnicastSubject<Integer> us = UnicastSubject.create();
    TestObserver<Integer> to = us.map(v -> {
        throw new TestException();
    }).compose(TestHelper.observableStripBoundary()).flatMapStream(v -> Stream.of(1, 2)).test();
    assertTrue(us.hasObservers());
    us.onNext(1);
    assertFalse(us.hasObservers());
    to.assertFailure(TestException.class);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) io.reactivex.rxjava3.subjects(io.reactivex.rxjava3.subjects) Iterator(java.util.Iterator) TestException(io.reactivex.rxjava3.exceptions.TestException) java.util.stream(java.util.stream) IOException(java.io.IOException) Test(org.junit.Test) NonNull(io.reactivex.rxjava3.annotations.NonNull) Mockito(org.mockito.Mockito) TestHelper(io.reactivex.rxjava3.testsupport.TestHelper) TestObserver(io.reactivex.rxjava3.observers.TestObserver) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Disposable(io.reactivex.rxjava3.disposables.Disposable) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) Assert(org.junit.Assert) TestException(io.reactivex.rxjava3.exceptions.TestException) 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