Search in sources :

Example 96 with Action

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

the class ObservableRetryTest method noCancelPreviousRetry.

@Test
public void noCancelPreviousRetry() {
    final AtomicInteger counter = new AtomicInteger();
    final AtomicInteger times = new AtomicInteger();
    Observable<Integer> source = Observable.defer(new Supplier<ObservableSource<Integer>>() {

        @Override
        public ObservableSource<Integer> get() throws Exception {
            if (times.getAndIncrement() < 4) {
                return Observable.error(new TestException());
            }
            return Observable.just(1);
        }
    }).doOnDispose(new Action() {

        @Override
        public void run() throws Exception {
            counter.getAndIncrement();
        }
    });
    source.retry(5).test().assertResult(1);
    assertEquals(0, counter.get());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 97 with Action

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

the class MaybeConsumersTest method onCompleteCrash.

@Test
public void onCompleteCrash() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        subscribeAutoDispose(processor, composite, this, this, new Action() {

            @Override
            public void run() throws Exception {
                throw new IOException();
            }
        });
        processor.onComplete();
        assertTrue(events.toString(), events.isEmpty());
        TestHelper.assertUndeliverable(errors, 0, IOException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : IOException(java.io.IOException) IOException(java.io.IOException) CompositeException(io.reactivex.rxjava3.exceptions.CompositeException) Test(org.junit.Test)

Example 98 with Action

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

the class CompletableAmbTest method noWinnerCompleteDispose.

@Test
public void noWinnerCompleteDispose() throws Exception {
    for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
        final AtomicBoolean interrupted = new AtomicBoolean();
        final CountDownLatch cdl = new CountDownLatch(1);
        Completable.ambArray(Completable.complete().subscribeOn(Schedulers.single()).observeOn(Schedulers.computation()), Completable.never()).subscribe(new Action() {

            @Override
            public void run() throws Exception {
                interrupted.set(Thread.currentThread().isInterrupted());
                cdl.countDown();
            }
        });
        assertTrue(cdl.await(500, TimeUnit.SECONDS));
        assertFalse("Interrupted!", interrupted.get());
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 99 with Action

use of io.reactivex.rxjava3.functions.Action 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 100 with Action

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

the class CompletableConcatDelayErrorTest method normalPublisherPrefetch.

@Test
public void normalPublisherPrefetch() throws Throwable {
    Action action1 = mock(Action.class);
    Action action2 = mock(Action.class);
    Completable.concatDelayError(Flowable.fromArray(Completable.fromAction(action1), Completable.error(new TestException()), Completable.fromAction(action2)), 1).test().assertFailure(TestException.class);
    verify(action1).run();
    verify(action2).run();
}
Also used : Action(io.reactivex.rxjava3.functions.Action) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)109 TestException (io.reactivex.rxjava3.exceptions.TestException)64 Action (io.reactivex.rxjava3.functions.Action)49 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)23 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)13 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 TestObserver (io.reactivex.rxjava3.observers.TestObserver)10 Disposable (io.reactivex.rxjava3.disposables.Disposable)9 IOException (java.io.IOException)9 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)7 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)7 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)6 Observable (io.reactivex.rxjava3.core.Observable)4 ForEachWhileSubscriber (io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber)4 CountingRunnable (io.reactivex.rxjava3.android.testutil.CountingRunnable)3 Flowable (io.reactivex.rxjava3.core.Flowable)3 GroupedFlowable (io.reactivex.rxjava3.flowables.GroupedFlowable)3 ConditionalSubscriber (io.reactivex.rxjava3.operators.ConditionalSubscriber)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3