Search in sources :

Example 56 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.

the class FlowableSwitchMapMaybeTest method innerErrorAfterTermination.

@Test
public void innerErrorAfterTermination() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final AtomicReference<MaybeObserver<? super Integer>> moRef = new AtomicReference<>();
        TestSubscriberEx<Integer> ts = new Flowable<Integer>() {

            @Override
            protected void subscribeActual(Subscriber<? super Integer> s) {
                s.onSubscribe(new BooleanSubscription());
                s.onNext(1);
                s.onError(new TestException("outer"));
            }
        }.switchMapMaybe(new Function<Integer, MaybeSource<Integer>>() {

            @Override
            public MaybeSource<Integer> apply(Integer v) throws Exception {
                return new Maybe<Integer>() {

                    @Override
                    protected void subscribeActual(MaybeObserver<? super Integer> observer) {
                        observer.onSubscribe(Disposable.empty());
                        moRef.set(observer);
                    }
                };
            }
        }).to(TestHelper.<Integer>testConsumer());
        ts.assertFailureAndMessage(TestException.class, "outer");
        moRef.get().onError(new TestException("inner"));
        moRef.get().onComplete();
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "inner");
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) AtomicReference(java.util.concurrent.atomic.AtomicReference) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 57 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.

the class MaybeSwitchOnNextTest method delaySwitch.

@Test
public void delaySwitch() {
    PublishProcessor<Maybe<Integer>> pp = PublishProcessor.create();
    TestSubscriber<Integer> ts = Maybe.switchOnNextDelayError(pp).test();
    assertTrue(pp.hasSubscribers());
    ts.assertEmpty();
    MaybeSubject<Integer> ms1 = MaybeSubject.create();
    MaybeSubject<Integer> ms2 = MaybeSubject.create();
    pp.onNext(ms1);
    assertTrue(ms1.hasObservers());
    pp.onNext(ms2);
    assertFalse(ms1.hasObservers());
    assertTrue(ms2.hasObservers());
    assertTrue(ms2.hasObservers());
    ms2.onError(new TestException());
    assertTrue(pp.hasSubscribers());
    ts.assertEmpty();
    pp.onComplete();
    ts.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 58 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.

the class MaybeTimeoutTest method fallbackError.

@Test
public void fallbackError() {
    PublishProcessor<Integer> pp1 = PublishProcessor.create();
    PublishProcessor<Integer> pp2 = PublishProcessor.create();
    TestObserver<Integer> to = pp1.singleElement().timeout(pp2.singleElement(), Maybe.<Integer>error(new TestException())).test();
    assertTrue(pp1.hasSubscribers());
    assertTrue(pp2.hasSubscribers());
    pp2.onNext(1);
    pp2.onComplete();
    assertFalse(pp1.hasSubscribers());
    assertFalse(pp2.hasSubscribers());
    to.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 59 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.

the class MaybeMergeTest method delayErrorWithMaxConcurrencyAsyncError.

@Test
public void delayErrorWithMaxConcurrencyAsyncError() {
    final AtomicInteger count = new AtomicInteger();
    @SuppressWarnings("unchecked") Maybe<Integer>[] sources = new Maybe[3];
    for (int i = 0; i < 3; i++) {
        final int j = i + 1;
        sources[i] = Maybe.fromCallable(new Callable<Integer>() {

            @Override
            public Integer call() throws Exception {
                return count.incrementAndGet() - j;
            }
        }).subscribeOn(Schedulers.io());
    }
    sources[1] = Maybe.fromCallable(new Callable<Integer>() {

        @Override
        public Integer call() throws Exception {
            throw new TestException("" + count.incrementAndGet());
        }
    }).subscribeOn(Schedulers.io());
    for (int i = 0; i < 1000; i++) {
        count.set(0);
        Maybe.mergeDelayError(Flowable.fromArray(sources), 1).to(TestHelper.<Integer>testConsumer()).awaitDone(5, TimeUnit.SECONDS).assertFailureAndMessage(TestException.class, "2", 0, 0);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestException(io.reactivex.rxjava3.exceptions.TestException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 60 with Maybe

use of io.reactivex.rxjava3.core.Maybe in project RxJava by ReactiveX.

the class MaybeOfTypeTest method error.

@Test
public void error() {
    TestObserver<Number> to = Maybe.<Integer>error(new TestException()).ofType(Number.class).test();
    // don't make this fluent, target type required!
    to.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)55 TestException (io.reactivex.rxjava3.exceptions.TestException)38 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)13 Maybe (io.reactivex.rxjava3.core.Maybe)12 InOrder (org.mockito.InOrder)12 Flowable (io.reactivex.rxjava3.core.Flowable)10 Observable (io.reactivex.rxjava3.core.Observable)10 Disposable (io.reactivex.rxjava3.disposables.Disposable)10 Single (io.reactivex.rxjava3.core.Single)8 IOException (java.io.IOException)8 Predicate (io.reactivex.rxjava3.functions.Predicate)6 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)6 Type (java.lang.reflect.Type)6 Test (org.junit.jupiter.api.Test)6 TestObserver (io.reactivex.rxjava3.observers.TestObserver)5 Completable (io.reactivex.rxjava3.core.Completable)4 Action (io.reactivex.rxjava3.functions.Action)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 FlowableRxInvoker (org.apache.cxf.jaxrs.rx3.client.FlowableRxInvoker)4 FlowableRxInvokerProvider (org.apache.cxf.jaxrs.rx3.client.FlowableRxInvokerProvider)4