use of io.reactivex.rxjava3.android.testutil.CountingRunnable in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method workerScheduleOnceWithDelayDisposedDoesNotRun.
@Test
public void workerScheduleOnceWithDelayDisposedDoesNotRun() {
Worker worker = scheduler.createWorker();
CountingRunnable counter = new CountingRunnable();
Disposable disposable = worker.schedule(counter, 1, MINUTES);
idleMainLooper(30, SECONDS);
disposable.dispose();
idleMainLooper(30, SECONDS);
runUiThreadTasks();
assertEquals(0, counter.get());
}
use of io.reactivex.rxjava3.android.testutil.CountingRunnable in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method workerSchedulePeriodicallyDisposedDuringRunDoesNotReschedule.
@Test
@Ignore("Implementation delegated to default RxJava implementation")
public void workerSchedulePeriodicallyDisposedDuringRunDoesNotReschedule() {
Worker worker = scheduler.createWorker();
final AtomicReference<Disposable> disposableRef = new AtomicReference<>();
CountingRunnable counter = new CountingRunnable() {
@Override
public void run() {
super.run();
if (get() == 2) {
disposableRef.get().dispose();
}
}
};
Disposable disposable = worker.schedulePeriodically(counter, 1, 1, MINUTES);
disposableRef.set(disposable);
runUiThreadTasks();
assertEquals(0, counter.get());
idleMainLooper(1, MINUTES);
runUiThreadTasks();
assertEquals(1, counter.get());
idleMainLooper(1, MINUTES);
runUiThreadTasks();
assertEquals(2, counter.get());
// Dispose will have happened here during the last run() execution.
idleMainLooper(1, MINUTES);
runUiThreadTasks();
assertEquals(2, counter.get());
}
use of io.reactivex.rxjava3.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());
}
use of io.reactivex.rxjava3.android.testutil.CountingRunnable in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method workerScheduleOnceWithDelayPostsWithDelay.
@Test
public void workerScheduleOnceWithDelayPostsWithDelay() {
Worker worker = scheduler.createWorker();
CountingRunnable counter = new CountingRunnable();
worker.schedule(counter, 1, MINUTES);
runUiThreadTasks();
assertEquals(0, counter.get());
idleMainLooper(1, MINUTES);
runUiThreadTasks();
assertEquals(1, counter.get());
}
use of io.reactivex.rxjava3.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());
}
Aggregations