Search in sources :

Example 26 with Completable

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

the class FlowableToCompletableTest method shouldUseUnsafeSubscribeInternallyNotSubscribe.

@Test
public void shouldUseUnsafeSubscribeInternallyNotSubscribe() {
    TestSubscriber<String> subscriber = TestSubscriber.create();
    final AtomicBoolean unsubscribed = new AtomicBoolean(false);
    Completable cmp = Flowable.just("Hello World!").doOnCancel(new Action() {

        @Override
        public void run() {
            unsubscribed.set(true);
        }
    }).ignoreElements();
    cmp.<String>toFlowable().subscribe(subscriber);
    subscriber.assertComplete();
    assertFalse(unsubscribed.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Action(io.reactivex.rxjava3.functions.Action) Test(org.junit.Test)

Example 27 with Completable

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

the class SchedulerWhenTest method disposed.

@Test
public void disposed() {
    SchedulerWhen sw = new SchedulerWhen(new Function<Flowable<Flowable<Completable>>, Completable>() {

        @Override
        public Completable apply(Flowable<Flowable<Completable>> v) throws Exception {
            return Completable.never();
        }
    }, Schedulers.single());
    assertFalse(sw.isDisposed());
    sw.dispose();
    assertTrue(sw.isDisposed());
}
Also used : SchedulerWhen(io.reactivex.rxjava3.internal.schedulers.SchedulerWhen) TestException(io.reactivex.rxjava3.exceptions.TestException) Flowable(io.reactivex.rxjava3.core.Flowable) Test(org.junit.Test)

Example 28 with Completable

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

the class XFlatMapTest method maybeCompletable.

@Test
public void maybeCompletable() throws Exception {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        TestObserver<Void> to = Maybe.just(1).subscribeOn(Schedulers.io()).flatMapCompletable(new Function<Integer, Completable>() {

            @Override
            public Completable apply(Integer v) throws Exception {
                sleep();
                return Completable.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 29 with Completable

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

the class XFlatMapTest method singleCompletable.

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

            @Override
            public Completable apply(Integer v) throws Exception {
                sleep();
                return Completable.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 30 with Completable

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

the class XFlatMapTest method observerCompletable.

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

            @Override
            public Completable apply(Integer v) throws Exception {
                sleep();
                return Completable.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)

Aggregations

Test (org.junit.Test)36 TestException (io.reactivex.rxjava3.exceptions.TestException)21 Action (io.reactivex.rxjava3.functions.Action)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)6 Disposable (io.reactivex.rxjava3.disposables.Disposable)5 IOException (java.io.IOException)4 Completable (io.reactivex.rxjava3.core.Completable)3 AtomicThrowable (io.reactivex.rxjava3.internal.util.AtomicThrowable)3 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)3 Flowable (io.reactivex.rxjava3.core.Flowable)2 TestObserver (io.reactivex.rxjava3.observers.TestObserver)2 CompletableSubject (io.reactivex.rxjava3.subjects.CompletableSubject)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Pattern (java.util.regex.Pattern)2 InOrder (org.mockito.InOrder)2 ConverterTest (io.reactivex.rxjava3.core.ConverterTest)1 Observable (io.reactivex.rxjava3.core.Observable)1 Observer (io.reactivex.rxjava3.core.Observer)1 ConnectableFlowable (io.reactivex.rxjava3.flowables.ConnectableFlowable)1