Search in sources :

Example 26 with Maybe

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

the class MaybeTimeoutPublisherTest method fallbackError.

@Test
public void fallbackError() {
    PublishProcessor<Integer> pp1 = PublishProcessor.create();
    PublishProcessor<Integer> pp2 = PublishProcessor.create();
    TestObserver<Integer> to = pp1.singleElement().timeout(pp2, 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 27 with Maybe

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

the class MaybeMergeTest method delayErrorWithMaxConcurrencyAsync.

@Test
public void delayErrorWithMaxConcurrencyAsync() {
    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());
    }
    for (int i = 0; i < 1000; i++) {
        count.set(0);
        Maybe.mergeDelayError(Flowable.fromArray(sources), 1).test().awaitDone(5, TimeUnit.SECONDS).assertResult(0, 0, 0);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 28 with Maybe

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

the class MaybeOfTypeTest method errorNotInstance.

@Test
public void errorNotInstance() {
    TestObserver<String> to = Maybe.<Integer>error(new TestException()).ofType(String.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)

Example 29 with Maybe

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

the class FlowableConcatWithMaybeTest method otherError.

@Test
public void otherError() {
    final TestSubscriber<Integer> ts = new TestSubscriber<>();
    Flowable.range(1, 5).concatWith(Maybe.<Integer>error(new TestException())).subscribe(ts);
    ts.assertFailure(TestException.class, 1, 2, 3, 4, 5);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 30 with Maybe

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

the class FlowableFirstTest method firstWithPredicate.

@Test
public void firstWithPredicate() {
    Maybe<Integer> maybe = Flowable.just(1, 2, 3, 4, 5, 6).filter(new Predicate<Integer>() {

        @Override
        public boolean test(Integer t1) {
            return t1 % 2 == 0;
        }
    }).firstElement();
    maybe.subscribe(wm);
    InOrder inOrder = inOrder(wm);
    inOrder.verify(wm, times(1)).onSuccess(2);
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) Predicate(io.reactivex.rxjava3.functions.Predicate)

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