Search in sources :

Example 11 with TestException

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

the class ObservableFlatMapStreamTest method upstreamCancelledCloseCrash.

@Test
public void upstreamCancelledCloseCrash() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        PublishSubject<Integer> ps = PublishSubject.create();
        TestObserver<Integer> to = ps.flatMapStream(v -> Stream.of(v + 1, v + 2).onClose(() -> {
            throw new TestException();
        })).take(1).test();
        assertTrue(ps.hasObservers());
        ps.onNext(1);
        to.assertResult(2);
        assertFalse(ps.hasObservers());
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 12 with TestException

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

the class ObservableMapOptionalTest method mapperChashConditional.

@Test
public void mapperChashConditional() {
    BehaviorSubject<Integer> source = BehaviorSubject.createDefault(1);
    source.mapOptional(v -> {
        throw new TestException();
    }).filter(v -> true).test().assertFailure(TestException.class);
    assertFalse(source.hasObservers());
}
Also used : QueueFuseable(io.reactivex.rxjava3.operators.QueueFuseable) TestHelper(io.reactivex.rxjava3.testsupport.TestHelper) Function(io.reactivex.rxjava3.functions.Function) io.reactivex.rxjava3.subjects(io.reactivex.rxjava3.subjects) TestException(io.reactivex.rxjava3.exceptions.TestException) Assert.assertFalse(org.junit.Assert.assertFalse) Disposable(io.reactivex.rxjava3.disposables.Disposable) Optional(java.util.Optional) Test(org.junit.Test) io.reactivex.rxjava3.core(io.reactivex.rxjava3.core) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 13 with TestException

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

the class BlockingFirstObserverTest method firstValueOnly.

@Test
public void firstValueOnly() {
    BlockingFirstObserver<Integer> bf = new BlockingFirstObserver<>();
    Disposable d = Disposable.empty();
    bf.onSubscribe(d);
    bf.onNext(1);
    assertTrue(d.isDisposed());
    assertEquals(1, bf.value.intValue());
    assertEquals(0, bf.getCount());
    bf.onNext(2);
    assertEquals(1, bf.value.intValue());
    assertEquals(0, bf.getCount());
    bf.onError(new TestException());
    assertEquals(1, bf.value.intValue());
    assertNull(bf.error);
    assertEquals(0, bf.getCount());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 14 with TestException

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

the class FutureSingleObserverTest method onErrorCancelRace.

@Test
public void onErrorCancelRace() {
    RxJavaPlugins.setErrorHandler(Functions.emptyConsumer());
    try {
        for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
            final PublishSubject<Integer> ps = PublishSubject.create();
            final Future<?> f = ps.single(-99).toFuture();
            final TestException ex = new TestException();
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    f.cancel(true);
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    ps.onError(ex);
                }
            };
            TestHelper.race(r1, r2);
        }
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 15 with TestException

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

the class CompletableToCompletionStageTest method completableManualCompleteExceptionallyCancels.

@Test
public void completableManualCompleteExceptionallyCancels() throws Exception {
    CompletableSubject source = CompletableSubject.create();
    CompletableFuture<Object> cf = source.toCompletionStage(null).toCompletableFuture();
    assertTrue(source.hasObservers());
    cf.completeExceptionally(new TestException());
    assertTrue(cf.isDone());
    assertTrue(cf.isCompletedExceptionally());
    assertFalse(cf.isCancelled());
    assertFalse(source.hasObservers());
    TestHelper.assertError(cf, TestException.class);
}
Also used : CompletableSubject(io.reactivex.rxjava3.subjects.CompletableSubject) 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