use of io.reactivex.rxjava3.schedulers.Schedulers in project RxJava by ReactiveX.
the class RxJavaPluginsTest method overrideInitSingleScheduler.
@Test
public void overrideInitSingleScheduler() {
// make sure the Schedulers is initialized
final Scheduler s = Schedulers.single();
Supplier<Scheduler> c = new Supplier<Scheduler>() {
@Override
public Scheduler get() throws Exception {
return s;
}
};
try {
RxJavaPlugins.setInitSingleSchedulerHandler(initReplaceWithImmediate);
assertSame(ImmediateThinScheduler.INSTANCE, RxJavaPlugins.initSingleScheduler(c));
} finally {
RxJavaPlugins.reset();
}
// make sure the reset worked
assertSame(s, RxJavaPlugins.initSingleScheduler(c));
}
use of io.reactivex.rxjava3.schedulers.Schedulers in project RxJava by ReactiveX.
the class RxJavaPluginsTest method overrideInitComputationScheduler.
@Test
public void overrideInitComputationScheduler() {
// make sure the Schedulers is initialized
final Scheduler s = Schedulers.computation();
Supplier<Scheduler> c = new Supplier<Scheduler>() {
@Override
public Scheduler get() throws Exception {
return s;
}
};
try {
RxJavaPlugins.setInitComputationSchedulerHandler(initReplaceWithImmediate);
assertSame(ImmediateThinScheduler.INSTANCE, RxJavaPlugins.initComputationScheduler(c));
} finally {
RxJavaPlugins.reset();
}
// make sure the reset worked
assertSame(s, RxJavaPlugins.initComputationScheduler(c));
}
use of io.reactivex.rxjava3.schedulers.Schedulers in project RxJava by ReactiveX.
the class RxJavaPluginsTest method overrideInitNewThreadScheduler.
@Test
public void overrideInitNewThreadScheduler() {
// make sure the Schedulers is initialized;
final Scheduler s = Schedulers.newThread();
Supplier<Scheduler> c = new Supplier<Scheduler>() {
@Override
public Scheduler get() throws Exception {
return s;
}
};
try {
RxJavaPlugins.setInitNewThreadSchedulerHandler(initReplaceWithImmediate);
assertSame(ImmediateThinScheduler.INSTANCE, RxJavaPlugins.initNewThreadScheduler(c));
} finally {
RxJavaPlugins.reset();
}
// make sure the reset worked
assertSame(s, RxJavaPlugins.initNewThreadScheduler(c));
}
use of io.reactivex.rxjava3.schedulers.Schedulers in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method directScheduleOnceWithDelayUsesHook.
@Test
public void directScheduleOnceWithDelayUsesHook() {
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, 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());
}
use of io.reactivex.rxjava3.schedulers.Schedulers 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());
}
Aggregations