Search in sources :

Example 36 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.

the class SingleDoOnLifecycleTest method onDisposeCrash.

@Test
public void onDisposeCrash() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        @SuppressWarnings("unchecked") Consumer<? super Disposable> onSubscribe = mock(Consumer.class);
        Action onDispose = mock(Action.class);
        doThrow(new TestException("First")).when(onDispose).run();
        SingleSubject<Integer> ss = SingleSubject.create();
        TestObserver<Integer> to = ss.doOnLifecycle(onSubscribe, onDispose).test();
        assertTrue(ss.hasObservers());
        to.dispose();
        assertFalse(ss.hasObservers());
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "First");
        verify(onSubscribe).accept(any());
        verify(onDispose).run();
    });
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 37 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.

the class AbstractSchedulerTests method schedulePeriodicallyDirectDecoratesRunnable.

@Test
public void schedulePeriodicallyDirectDecoratesRunnable() throws InterruptedException {
    final Scheduler scheduler = getScheduler();
    if (scheduler instanceof TrampolineScheduler) {
        // Can't properly stop a trampolined periodic task.
        return;
    }
    final AtomicReference<Disposable> disposable = new AtomicReference<>();
    try {
        assertRunnableDecorated(new Runnable() {

            @Override
            public void run() {
                disposable.set(scheduler.schedulePeriodicallyDirect(Functions.EMPTY_RUNNABLE, 1, 10000, TimeUnit.MILLISECONDS));
            }
        });
    } finally {
        disposable.get().dispose();
    }
}
Also used : SequentialDisposable(io.reactivex.rxjava3.internal.disposables.SequentialDisposable) Disposable(io.reactivex.rxjava3.disposables.Disposable) TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler) TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler) Test(org.junit.Test)

Example 38 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.

the class AbstractSchedulerTests method scheduleDirectPeriodic.

@Test
public void scheduleDirectPeriodic() throws Exception {
    Scheduler s = getScheduler();
    if (s instanceof TrampolineScheduler) {
        // can't properly stop a trampolined periodic task
        return;
    }
    final CountDownLatch cdl = new CountDownLatch(5);
    Disposable d = s.schedulePeriodicallyDirect(new Runnable() {

        @Override
        public void run() {
            cdl.countDown();
        }
    }, 10, 10, TimeUnit.MILLISECONDS);
    try {
        assertTrue(cdl.await(5, TimeUnit.SECONDS));
    } finally {
        d.dispose();
    }
    assertTrue(d.isDisposed());
}
Also used : SequentialDisposable(io.reactivex.rxjava3.internal.disposables.SequentialDisposable) Disposable(io.reactivex.rxjava3.disposables.Disposable) TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler) TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler) Test(org.junit.Test)

Example 39 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.

the class AbstractSchedulerTests method unwrapScheduleDirectTask.

@Test
public void unwrapScheduleDirectTask() {
    Scheduler scheduler = getScheduler();
    if (scheduler instanceof TrampolineScheduler) {
        // TrampolineScheduler always return EmptyDisposable
        return;
    }
    final CountDownLatch cdl = new CountDownLatch(1);
    Runnable countDownRunnable = new Runnable() {

        @Override
        public void run() {
            cdl.countDown();
        }
    };
    Disposable disposable = scheduler.scheduleDirect(countDownRunnable, 100, TimeUnit.MILLISECONDS);
    SchedulerRunnableIntrospection wrapper = (SchedulerRunnableIntrospection) disposable;
    assertSame(countDownRunnable, wrapper.getWrappedRunnable());
    disposable.dispose();
}
Also used : SequentialDisposable(io.reactivex.rxjava3.internal.disposables.SequentialDisposable) Disposable(io.reactivex.rxjava3.disposables.Disposable) TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler) TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler) Test(org.junit.Test)

Example 40 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.

the class ExecutorSchedulerInterruptibleTest method runnableDisposedAsync2.

@Test
public void runnableDisposedAsync2() throws Exception {
    final Scheduler s = Schedulers.from(executor, true);
    Disposable d = s.scheduleDirect(Functions.EMPTY_RUNNABLE);
    while (!d.isDisposed()) {
        Thread.sleep(1);
    }
}
Also used : EmptyDisposable(io.reactivex.rxjava3.internal.disposables.EmptyDisposable) Disposable(io.reactivex.rxjava3.disposables.Disposable) Scheduler(io.reactivex.rxjava3.core.Scheduler) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)251 Disposable (io.reactivex.rxjava3.disposables.Disposable)236 TestException (io.reactivex.rxjava3.exceptions.TestException)74 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)56 IOException (java.io.IOException)38 Scheduler (io.reactivex.rxjava3.core.Scheduler)36 EmptyDisposable (io.reactivex.rxjava3.internal.disposables.EmptyDisposable)35 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)34 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)32 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)22 TestObserver (io.reactivex.rxjava3.observers.TestObserver)18 SequentialDisposable (io.reactivex.rxjava3.internal.disposables.SequentialDisposable)15 QueueDisposable (io.reactivex.rxjava3.operators.QueueDisposable)13 CountingRunnable (io.reactivex.rxjava3.android.testutil.CountingRunnable)10 TrampolineScheduler (io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler)9 LifecycleDisposable (org.thoughtcrime.securesms.util.LifecycleDisposable)8 Observable (io.reactivex.rxjava3.core.Observable)6 Observer (io.reactivex.rxjava3.core.Observer)6 ScalarDisposable (io.reactivex.rxjava3.internal.operators.observable.ObservableScalarXMap.ScalarDisposable)6