use of io.reactivex.android.testutil.CountingRunnable in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method workerSchedulePeriodicallyUsesHookOnce.
@Test
@Ignore("Implementation delegated to default RxJava implementation")
public void workerSchedulePeriodicallyUsesHookOnce() {
Worker worker = scheduler.createWorker();
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();
worker.schedulePeriodically(counter, 1, 1, MINUTES);
// Verify our action was passed to the schedulers hook.
assertSame(counter, runnableRef.get());
runnableRef.set(null);
idleMainLooper(1, MINUTES);
runUiThreadTasks();
// Verify the scheduled action was the one returned from the hook.
assertEquals(1, newCounter.get());
assertEquals(0, counter.get());
// Ensure the hook was not called again when the runnable re-scheduled itself.
assertNull(runnableRef.get());
}
use of io.reactivex.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());
}
use of io.reactivex.android.testutil.CountingRunnable in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method directScheduleOnceWithDelayDisposedDoesNotRun.
@Test
public void directScheduleOnceWithDelayDisposedDoesNotRun() {
CountingRunnable counter = new CountingRunnable();
Disposable disposable = scheduler.scheduleDirect(counter, 1, MINUTES);
idleMainLooper(30, SECONDS);
disposable.dispose();
idleMainLooper(30, SECONDS);
runUiThreadTasks();
assertEquals(0, counter.get());
}
use of io.reactivex.android.testutil.CountingRunnable in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method workerSchedulePeriodicallyDisposedDoesNotRun.
@Test
@Ignore("Implementation delegated to default RxJava implementation")
public void workerSchedulePeriodicallyDisposedDoesNotRun() {
Worker worker = scheduler.createWorker();
CountingRunnable counter = new CountingRunnable();
Disposable disposable = worker.schedulePeriodically(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());
}
use of io.reactivex.android.testutil.CountingRunnable in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method workerUnsubscriptionDuringSchedulingCancelsScheduledAction.
@Test
public void workerUnsubscriptionDuringSchedulingCancelsScheduledAction() {
final AtomicReference<Worker> workerRef = new AtomicReference<>();
RxJavaPlugins.setScheduleHandler(new Function<Runnable, Runnable>() {
@Override
public Runnable apply(Runnable runnable) {
// Purposefully unsubscribe in an asinine point after the normal unsubscribed check.
workerRef.get().dispose();
return runnable;
}
});
Worker worker = scheduler.createWorker();
workerRef.set(worker);
CountingRunnable counter = new CountingRunnable();
worker.schedule(counter);
runUiThreadTasks();
assertEquals(0, counter.get());
}
Aggregations