Search in sources :

Example 16 with NonNull

use of io.reactivex.rxjava3.annotations.NonNull in project RxJava by ReactiveX.

the class MaybeSafeSubscribeTest method onErrorCrash.

@Test
public void onErrorCrash() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        @SuppressWarnings("unchecked") MaybeObserver<Integer> consumer = mock(MaybeObserver.class);
        doThrow(new TestException()).when(consumer).onError(any());
        new Maybe<Integer>() {

            @Override
            protected void subscribeActual(@NonNull MaybeObserver<? super Integer> observer) {
                observer.onSubscribe(Disposable.empty());
                // none of the following should arrive at the consumer
                observer.onError(new IOException());
            }
        }.safeSubscribe(consumer);
        InOrder order = inOrder(consumer);
        order.verify(consumer).onSubscribe(any(Disposable.class));
        order.verify(consumer).onError(any(IOException.class));
        order.verifyNoMoreInteractions();
        TestHelper.assertError(errors, 0, CompositeException.class);
        CompositeException compositeException = (CompositeException) errors.get(0);
        TestHelper.assertError(compositeException.getExceptions(), 0, IOException.class);
        TestHelper.assertError(compositeException.getExceptions(), 1, TestException.class);
    });
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) InOrder(org.mockito.InOrder) IOException(java.io.IOException) Test(org.junit.Test)

Example 17 with NonNull

use of io.reactivex.rxjava3.annotations.NonNull in project RxJava by ReactiveX.

the class MaybeSafeSubscribeTest method onSuccessCrash.

@Test
public void onSuccessCrash() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        @SuppressWarnings("unchecked") MaybeObserver<Integer> consumer = mock(MaybeObserver.class);
        doThrow(new TestException()).when(consumer).onSuccess(any());
        new Maybe<Integer>() {

            @Override
            protected void subscribeActual(@NonNull MaybeObserver<? super Integer> observer) {
                observer.onSubscribe(Disposable.empty());
                observer.onSuccess(1);
            }
        }.safeSubscribe(consumer);
        InOrder order = inOrder(consumer);
        order.verify(consumer).onSubscribe(any(Disposable.class));
        order.verify(consumer).onSuccess(1);
        order.verifyNoMoreInteractions();
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    });
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) InOrder(org.mockito.InOrder) Test(org.junit.Test)

Example 18 with NonNull

use of io.reactivex.rxjava3.annotations.NonNull in project RxJava by ReactiveX.

the class ObservableFlatMapStreamTest method eventsIgnoredAfterCrash.

@Test
public void eventsIgnoredAfterCrash() {
    AtomicInteger calls = new AtomicInteger();
    new Observable<Integer>() {

        @Override
        protected void subscribeActual(@NonNull Observer<? super Integer> observer) {
            observer.onSubscribe(Disposable.empty());
            observer.onNext(1);
            observer.onNext(2);
            observer.onComplete();
        }
    }.flatMapStream(v -> {
        calls.getAndIncrement();
        throw new TestException();
    }).take(1).test().assertFailure(TestException.class);
    assertEquals(1, calls.get());
}
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) NonNull(io.reactivex.rxjava3.annotations.NonNull) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 19 with NonNull

use of io.reactivex.rxjava3.annotations.NonNull in project RxJava by ReactiveX.

the class SingleSafeSubscribeTest method onErrorCrash.

@Test
public void onErrorCrash() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        @SuppressWarnings("unchecked") SingleObserver<Integer> consumer = mock(SingleObserver.class);
        doThrow(new TestException()).when(consumer).onError(any());
        new Single<Integer>() {

            @Override
            protected void subscribeActual(@NonNull SingleObserver<? super Integer> observer) {
                observer.onSubscribe(Disposable.empty());
                // none of the following should arrive at the consumer
                observer.onError(new IOException());
            }
        }.safeSubscribe(consumer);
        InOrder order = inOrder(consumer);
        order.verify(consumer).onSubscribe(any(Disposable.class));
        order.verify(consumer).onError(any(IOException.class));
        order.verifyNoMoreInteractions();
        TestHelper.assertError(errors, 0, CompositeException.class);
        CompositeException compositeException = (CompositeException) errors.get(0);
        TestHelper.assertError(compositeException.getExceptions(), 0, IOException.class);
        TestHelper.assertError(compositeException.getExceptions(), 1, TestException.class);
    });
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) InOrder(org.mockito.InOrder) IOException(java.io.IOException) Test(org.junit.Test)

Example 20 with NonNull

use of io.reactivex.rxjava3.annotations.NonNull in project RxJava by ReactiveX.

the class SingleTimeoutTest method timeoutBeforeOnSubscribeFromMain.

@Test
public void timeoutBeforeOnSubscribeFromMain() {
    Disposable d = Disposable.empty();
    new Single<Integer>() {

        @Override
        protected void subscribeActual(@NonNull SingleObserver<? super @NonNull Integer> observer) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            observer.onSubscribe(d);
        }
    }.timeout(1, TimeUnit.MILLISECONDS, Single.just(1)).test().awaitDone(5, TimeUnit.SECONDS).assertResult(1);
    assertTrue(d.isDisposed());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) NonNull(io.reactivex.rxjava3.annotations.NonNull) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)20 Disposable (io.reactivex.rxjava3.disposables.Disposable)15 NonNull (io.reactivex.rxjava3.annotations.NonNull)10 InOrder (org.mockito.InOrder)10 TestException (io.reactivex.rxjava3.exceptions.TestException)9 IOException (java.io.IOException)9 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)7 Assert (org.junit.Assert)7 java.util.stream (java.util.stream)6 Iterator (java.util.Iterator)5 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)4 QueueFuseable (io.reactivex.rxjava3.operators.QueueFuseable)4 QueueSubscription (io.reactivex.rxjava3.operators.QueueSubscription)4 io.reactivex.rxjava3.testsupport (io.reactivex.rxjava3.testsupport)4 Mockito (org.mockito.Mockito)4 Subscription (org.reactivestreams.Subscription)4 Schedulers (io.reactivex.rxjava3.schedulers.Schedulers)3 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)3 TestHelper (io.reactivex.rxjava3.testsupport.TestHelper)3 Function (io.reactivex.rxjava3.functions.Function)2