Search in sources :

Example 36 with Completable

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

the class CompletableAndThenCompletableTest method andThenNoInterrupt.

@Test
public void andThenNoInterrupt() throws InterruptedException {
    for (int k = 0; k < 100; k++) {
        final int count = 10;
        final CountDownLatch latch = new CountDownLatch(count);
        final boolean[] interrupted = { false };
        for (int i = 0; i < count; i++) {
            Completable.complete().subscribeOn(Schedulers.io()).observeOn(Schedulers.io()).andThen(Completable.fromAction(new Action() {

                @Override
                public void run() throws Exception {
                    try {
                        Thread.sleep(30);
                    } catch (InterruptedException e) {
                        System.out.println("Interrupted! " + Thread.currentThread());
                        interrupted[0] = true;
                    }
                }
            })).subscribe(new Action() {

                @Override
                public void run() throws Exception {
                    latch.countDown();
                }
            });
        }
        latch.await();
        assertFalse("The second Completable was interrupted!", interrupted[0]);
    }
}
Also used : Action(io.reactivex.rxjava3.functions.Action) CountDownLatch(java.util.concurrent.CountDownLatch) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 37 with Completable

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

the class CompletableConcatTest method overflowReported.

@Test
public void overflowReported() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Completable.concat(Flowable.fromPublisher(new Publisher<Completable>() {

            @Override
            public void subscribe(Subscriber<? super Completable> s) {
                s.onSubscribe(new BooleanSubscription());
                s.onNext(Completable.never());
                s.onNext(Completable.never());
                s.onNext(Completable.never());
                s.onNext(Completable.never());
                s.onComplete();
            }
        }), 1).test().assertFailure(MissingBackpressureException.class);
        TestHelper.assertError(errors, 0, MissingBackpressureException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 38 with Completable

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

the class CompletableMergeTest method mainErrorInnerErrorDelayedRace.

@Test
public void mainErrorInnerErrorDelayedRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final PublishProcessor<Integer> pp1 = PublishProcessor.create();
        final PublishProcessor<Integer> pp2 = PublishProcessor.create();
        TestObserverEx<Void> to = Completable.mergeDelayError(pp1.map(new Function<Integer, Completable>() {

            @Override
            public Completable apply(Integer v) throws Exception {
                return pp2.ignoreElements();
            }
        })).to(TestHelper.<Void>testConsumer());
        pp1.onNext(1);
        final Throwable ex1 = new TestException();
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                pp1.onError(ex1);
            }
        };
        final Throwable ex2 = new TestException();
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                pp2.onError(ex2);
            }
        };
        TestHelper.race(r1, r2);
        to.assertFailure(CompositeException.class);
        List<Throwable> errors = TestHelper.compositeList(to.errors().get(0));
        TestHelper.assertError(errors, 0, TestException.class);
        TestHelper.assertError(errors, 1, TestException.class);
    }
}
Also used : AtomicThrowable(io.reactivex.rxjava3.internal.util.AtomicThrowable) Test(org.junit.Test)

Example 39 with Completable

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

the class CompletableSafeSubscribeTest method onCompleteCrash.

@Test
public void onCompleteCrash() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        CompletableObserver consumer = mock(CompletableObserver.class);
        doThrow(new TestException()).when(consumer).onComplete();
        new Completable() {

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

Example 40 with Completable

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

the class CompletableSwitchOnNextTest method noDelaySwitch.

@Test
public void noDelaySwitch() {
    PublishProcessor<Completable> pp = PublishProcessor.create();
    TestObserver<Void> to = Completable.switchOnNext(pp).test();
    assertTrue(pp.hasSubscribers());
    to.assertEmpty();
    CompletableSubject cs1 = CompletableSubject.create();
    CompletableSubject cs2 = CompletableSubject.create();
    pp.onNext(cs1);
    assertTrue(cs1.hasObservers());
    pp.onNext(cs2);
    assertFalse(cs1.hasObservers());
    assertTrue(cs2.hasObservers());
    pp.onComplete();
    assertTrue(cs2.hasObservers());
    cs2.onComplete();
    to.assertResult();
}
Also used : CompletableSubject(io.reactivex.rxjava3.subjects.CompletableSubject) 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