Search in sources :

Example 46 with Function

use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.

the class XFlatMapTest method singlePublisher.

@Test
public void singlePublisher() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestSubscriber<Integer> ts = Single.just(1).subscribeOn(Schedulers.io()).flatMapPublisher(new Function<Integer, Publisher<Integer>>() {

            @Override
            public Publisher<Integer> apply(Integer v) throws Exception {
                sleep();
                return Flowable.<Integer>error(new TestException());
            }
        }).test();
        cb.await();
        beforeCancelSleep(ts);
        ts.cancel();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        ts.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 47 with Function

use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.

the class XFlatMapTest method observableObservable.

@Test
public void observableObservable() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserver<Integer> to = Observable.just(1).subscribeOn(Schedulers.io()).flatMap(new Function<Integer, Observable<Integer>>() {

            @Override
            public Observable<Integer> apply(Integer v) throws Exception {
                sleep();
                return Observable.<Integer>error(new TestException());
            }
        }).test();
        cb.await();
        beforeCancelSleep(to);
        to.dispose();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        to.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 48 with Function

use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.

the class XFlatMapTest method observerSingle.

@Test
public void observerSingle() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserver<Integer> to = Observable.just(1).subscribeOn(Schedulers.io()).flatMapSingle(new Function<Integer, Single<Integer>>() {

            @Override
            public Single<Integer> apply(Integer v) throws Exception {
                sleep();
                return Single.<Integer>error(new TestException());
            }
        }).test();
        cb.await();
        beforeCancelSleep(to);
        to.dispose();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        to.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 49 with Function

use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.

the class XFlatMapTest method singleCombiner.

@Test
public void singleCombiner() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserver<Integer> to = Single.just(1).subscribeOn(Schedulers.io()).flatMap(new Function<Integer, Single<Integer>>() {

            @Override
            public Single<Integer> apply(Integer v) throws Exception {
                sleep();
                return Single.<Integer>error(new TestException());
            }
        }, (a, b) -> a + b).test();
        cb.await();
        beforeCancelSleep(to);
        to.dispose();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        to.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : Schedulers(io.reactivex.rxjava3.schedulers.Schedulers) List(java.util.List) CyclicBarrier(java.util.concurrent.CyclicBarrier) TestHelper(io.reactivex.rxjava3.testsupport.TestHelper) TestException(io.reactivex.rxjava3.exceptions.TestException) TestObserver(io.reactivex.rxjava3.observers.TestObserver) io.reactivex.rxjava3.functions(io.reactivex.rxjava3.functions) Publisher(org.reactivestreams.Publisher) Assert.assertTrue(org.junit.Assert.assertTrue) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) org.junit(org.junit) RxJavaPlugins(io.reactivex.rxjava3.plugins.RxJavaPlugins) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 50 with Function

use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.

the class XFlatMapTest method maybePublisher.

@Test
public void maybePublisher() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestSubscriber<Integer> ts = Maybe.just(1).subscribeOn(Schedulers.io()).flatMapPublisher(new Function<Integer, Publisher<Integer>>() {

            @Override
            public Publisher<Integer> apply(Integer v) throws Exception {
                sleep();
                return Flowable.<Integer>error(new TestException());
            }
        }).test();
        cb.await();
        beforeCancelSleep(ts);
        ts.cancel();
        Thread.sleep(SLEEP_AFTER_CANCEL);
        ts.assertEmpty();
        assertTrue(errors.toString(), errors.isEmpty());
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Aggregations

Test (org.junit.Test)97 TestException (io.reactivex.rxjava3.exceptions.TestException)78 Observable (io.reactivex.rxjava3.core.Observable)41 InOrder (org.mockito.InOrder)36 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)21 Function (io.reactivex.rxjava3.functions.Function)20 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)14 IOException (java.io.IOException)13 Disposable (io.reactivex.rxjava3.disposables.Disposable)10 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)9 TestObserver (io.reactivex.rxjava3.observers.TestObserver)9 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)9 GroupedFlowable (io.reactivex.rxjava3.flowables.GroupedFlowable)8 CountingRunnable (io.reactivex.rxjava3.android.testutil.CountingRunnable)7 Observer (io.reactivex.rxjava3.core.Observer)7 Function (org.apache.cassandra.cql3.functions.Function)7 ImmediateThinScheduler (io.reactivex.rxjava3.internal.schedulers.ImmediateThinScheduler)6 TestHelper (io.reactivex.rxjava3.testsupport.TestHelper)6 EmptyScheduler (io.reactivex.rxjava3.android.testutil.EmptyScheduler)5