Search in sources :

Example 16 with CountingRunnable

use of io.reactivex.rxjava3.android.testutil.CountingRunnable in project RxAndroid by ReactiveX.

the class HandlerSchedulerTest method workerScheduleOnceWithNegativeDelayPostsImmediately.

@Test
public void workerScheduleOnceWithNegativeDelayPostsImmediately() {
    Worker worker = scheduler.createWorker();
    CountingRunnable counter = new CountingRunnable();
    worker.schedule(counter, -1, TimeUnit.MINUTES);
    runUiThreadTasks();
    assertEquals(1, counter.get());
}
Also used : CountingRunnable(io.reactivex.rxjava3.android.testutil.CountingRunnable) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) Test(org.junit.Test)

Example 17 with CountingRunnable

use of io.reactivex.rxjava3.android.testutil.CountingRunnable in project RxAndroid by ReactiveX.

the class HandlerSchedulerTest method directSchedulePeriodicallyDisposedDoesNotRun.

@Test
@Ignore("Implementation delegated to default RxJava implementation")
public void directSchedulePeriodicallyDisposedDoesNotRun() {
    CountingRunnable counter = new CountingRunnable();
    Disposable disposable = scheduler.schedulePeriodicallyDirect(counter, 1, 1, MINUTES);
    runUiThreadTasks();
    assertEquals(0, counter.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(1, counter.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
    disposable.dispose();
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) CountingRunnable(io.reactivex.rxjava3.android.testutil.CountingRunnable) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with CountingRunnable

use of io.reactivex.rxjava3.android.testutil.CountingRunnable in project RxAndroid by ReactiveX.

the class HandlerSchedulerTest method directScheduleOnceDisposedDoesNotRun.

@Test
public void directScheduleOnceDisposedDoesNotRun() {
    CountingRunnable counter = new CountingRunnable();
    Disposable disposable = scheduler.scheduleDirect(counter);
    disposable.dispose();
    runUiThreadTasks();
    assertEquals(0, counter.get());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) CountingRunnable(io.reactivex.rxjava3.android.testutil.CountingRunnable) Test(org.junit.Test)

Example 19 with CountingRunnable

use of io.reactivex.rxjava3.android.testutil.CountingRunnable in project RxAndroid by ReactiveX.

the class HandlerSchedulerTest method directScheduleOnceWithNegativeDelayPostsImmediately.

@Test
public void directScheduleOnceWithNegativeDelayPostsImmediately() {
    CountingRunnable counter = new CountingRunnable();
    scheduler.scheduleDirect(counter, -1, TimeUnit.MINUTES);
    runUiThreadTasks();
    assertEquals(1, counter.get());
}
Also used : CountingRunnable(io.reactivex.rxjava3.android.testutil.CountingRunnable) Test(org.junit.Test)

Example 20 with CountingRunnable

use of io.reactivex.rxjava3.android.testutil.CountingRunnable in project RxAndroid by ReactiveX.

the class HandlerSchedulerTest method directSchedulePeriodicallyThrowingDoesNotReschedule.

@Test
@Ignore("Implementation delegated to default RxJava implementation")
public void directSchedulePeriodicallyThrowingDoesNotReschedule() {
    CountingRunnable counter = new CountingRunnable() {

        @Override
        public void run() {
            super.run();
            if (get() == 2) {
                throw new RuntimeException("Broken!");
            }
        }
    };
    scheduler.schedulePeriodicallyDirect(counter, 1, 1, MINUTES);
    runUiThreadTasks();
    assertEquals(0, counter.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(1, counter.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
    // Exception will have happened here during the last run() execution.
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
}
Also used : CountingRunnable(io.reactivex.rxjava3.android.testutil.CountingRunnable) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

CountingRunnable (io.reactivex.rxjava3.android.testutil.CountingRunnable)33 Test (org.junit.Test)33 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)19 Ignore (org.junit.Ignore)12 Disposable (io.reactivex.rxjava3.disposables.Disposable)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)9