Search in sources :

Example 16 with Completable

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

the class CompletableSafeSubscribeTest method onSubscribeCrash.

@Test
public void onSubscribeCrash() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        CompletableObserver consumer = mock(CompletableObserver.class);
        doThrow(new TestException()).when(consumer).onSubscribe(any());
        Disposable d = Disposable.empty();
        new Completable() {

            @Override
            protected void subscribeActual(@NonNull CompletableObserver observer) {
                observer.onSubscribe(d);
                // none of the following should arrive at the consumer
                observer.onError(new IOException());
                observer.onComplete();
            }
        }.safeSubscribe(consumer);
        InOrder order = inOrder(consumer);
        order.verify(consumer).onSubscribe(any(Disposable.class));
        order.verifyNoMoreInteractions();
        assertTrue(d.isDisposed());
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
        TestHelper.assertUndeliverable(errors, 1, IOException.class);
    });
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) InOrder(org.mockito.InOrder) IOException(java.io.IOException) Test(org.junit.Test)

Example 17 with Completable

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

the class CompletableTakeUntilTest method otherErrorLate.

@Test
public void otherErrorLate() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        final AtomicReference<CompletableObserver> ref = new AtomicReference<>();
        Completable.complete().takeUntil(new Completable() {

            @Override
            protected void subscribeActual(CompletableObserver observer) {
                observer.onSubscribe(Disposable.empty());
                ref.set(observer);
            }
        }).test().assertResult();
        ref.get().onError(new TestException());
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 18 with Completable

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

the class CompletableDelaySubscriptionTest method timestep.

@Test
public void timestep() {
    TestScheduler scheduler = new TestScheduler();
    final AtomicInteger counter = new AtomicInteger();
    Completable result = Completable.fromAction(new Action() {

        @Override
        public void run() throws Exception {
            counter.incrementAndGet();
        }
    }).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler);
    TestObserver<Void> to = result.test();
    scheduler.advanceTimeBy(90, TimeUnit.MILLISECONDS);
    to.assertEmpty();
    scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS);
    to.assertResult();
    assertEquals(1, counter.get());
}
Also used : Action(io.reactivex.rxjava3.functions.Action) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 19 with Completable

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

the class CompletableDetachTest method errorDetaches.

@Test
public void errorDetaches() throws Exception {
    Disposable d = Disposable.empty();
    final WeakReference<Disposable> wr = new WeakReference<>(d);
    TestObserver<Void> to = new Completable() {

        @Override
        protected void subscribeActual(CompletableObserver observer) {
            observer.onSubscribe(wr.get());
            observer.onError(new TestException());
            observer.onError(new IOException());
        }
    }.onTerminateDetach().test();
    d = null;
    System.gc();
    Thread.sleep(200);
    to.assertFailure(TestException.class);
    assertNull(wr.get());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) WeakReference(java.lang.ref.WeakReference) IOException(java.io.IOException) Test(org.junit.Test)

Example 20 with Completable

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

the class CompletableFromCallableTest method fromCallableInvokesLazy.

@Test
public void fromCallableInvokesLazy() {
    final AtomicInteger atomicInteger = new AtomicInteger();
    Completable completable = Completable.fromCallable(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            atomicInteger.incrementAndGet();
            return null;
        }
    });
    assertEquals(0, atomicInteger.get());
    completable.test().assertResult();
    assertEquals(1, atomicInteger.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

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