Search in sources :

Example 6 with CountingRunnable

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

the class HandlerSchedulerTest method directScheduleOnceUsesHook.

@Test
public void directScheduleOnceUsesHook() {
    final CountingRunnable newCounter = new CountingRunnable();
    final AtomicReference<Runnable> runnableRef = new AtomicReference<>();
    RxJavaPlugins.setScheduleHandler(new Function<Runnable, Runnable>() {

        @Override
        public Runnable apply(Runnable runnable) {
            runnableRef.set(runnable);
            return newCounter;
        }
    });
    CountingRunnable counter = new CountingRunnable();
    scheduler.scheduleDirect(counter);
    // Verify our runnable was passed to the schedulers hook.
    assertSame(counter, runnableRef.get());
    runUiThreadTasks();
    // Verify the scheduled runnable was the one returned from the hook.
    assertEquals(1, newCounter.get());
    assertEquals(0, counter.get());
}
Also used : CountingRunnable(io.reactivex.android.testutil.CountingRunnable) CountingRunnable(io.reactivex.android.testutil.CountingRunnable) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 7 with CountingRunnable

use of io.reactivex.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.disposables.Disposable) CountingRunnable(io.reactivex.android.testutil.CountingRunnable) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with CountingRunnable

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

the class HandlerSchedulerTest method workerSchedulePeriodicallyInputValidation.

@Test
@Ignore("Implementation delegated to default RxJava implementation")
public void workerSchedulePeriodicallyInputValidation() {
    Worker worker = scheduler.createWorker();
    try {
        worker.schedulePeriodically(null, 1, 1, MINUTES);
        fail();
    } catch (NullPointerException e) {
        assertEquals("run == null", e.getMessage());
    }
    try {
        worker.schedulePeriodically(new CountingRunnable(), 1, -1, MINUTES);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("period < 0: -1", e.getMessage());
    }
    try {
        worker.schedulePeriodically(new CountingRunnable(), 1, 1, null);
        fail();
    } catch (NullPointerException e) {
        assertEquals("unit == null", e.getMessage());
    }
}
Also used : CountingRunnable(io.reactivex.android.testutil.CountingRunnable) Worker(io.reactivex.Scheduler.Worker) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with CountingRunnable

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

the class HandlerSchedulerTest method workerScheduleOnceWithDelayUsesHook.

@Test
public void workerScheduleOnceWithDelayUsesHook() {
    final CountingRunnable newCounter = new CountingRunnable();
    final AtomicReference<Runnable> runnableRef = new AtomicReference<>();
    RxJavaPlugins.setScheduleHandler(new Function<Runnable, Runnable>() {

        @Override
        public Runnable apply(Runnable runnable) {
            runnableRef.set(runnable);
            return newCounter;
        }
    });
    Worker worker = scheduler.createWorker();
    CountingRunnable counter = new CountingRunnable();
    worker.schedule(counter, 1, MINUTES);
    // Verify our runnable was passed to the schedulers hook.
    assertSame(counter, runnableRef.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    // Verify the scheduled runnable was the one returned from the hook.
    assertEquals(1, newCounter.get());
    assertEquals(0, counter.get());
}
Also used : CountingRunnable(io.reactivex.android.testutil.CountingRunnable) CountingRunnable(io.reactivex.android.testutil.CountingRunnable) Worker(io.reactivex.Scheduler.Worker) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 10 with CountingRunnable

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

the class HandlerSchedulerTest method directSchedulePeriodicallyReschedulesItself.

@Test
@Ignore("Implementation delegated to default RxJava implementation")
public void directSchedulePeriodicallyReschedulesItself() {
    CountingRunnable counter = new CountingRunnable();
    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());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(3, counter.get());
}
Also used : CountingRunnable(io.reactivex.android.testutil.CountingRunnable) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

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