Java Code Examples for io.reactivex.plugins.RxJavaPlugins#setInitIoSchedulerHandler()

The following examples show how to use io.reactivex.plugins.RxJavaPlugins#setInitIoSchedulerHandler() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RxSchedulersRule.java    From quill with MIT License 6 votes vote down vote up
public Statement apply(Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            Scheduler scheduler = TrampolineScheduler.instance();
            Function<Callable<Scheduler>, Scheduler> schedulerFn = __ -> scheduler;
            RxJavaPlugins.reset();
            RxJavaPlugins.setInitIoSchedulerHandler(schedulerFn);
            RxJavaPlugins.setInitNewThreadSchedulerHandler(schedulerFn);
            RxAndroidPlugins.reset();
            RxAndroidPlugins.setInitMainThreadSchedulerHandler(schedulerFn);

            try {
                base.evaluate();
            } finally {
                RxJavaPlugins.reset();
                RxAndroidPlugins.reset();
            }
        }
    };
}
 
Example 2
Source File: AbstractObjectBoxTest.java    From Hentoid with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUpRxSchedulers() {
    Scheduler immediate = new Scheduler() {
        @Override
        public Disposable scheduleDirect(@NonNull Runnable run, long delay, @NonNull TimeUnit unit) {
            // this prevents StackOverflowErrors when scheduling with a delay
            return super.scheduleDirect(run, 0, unit);
        }

        @Override
        public Scheduler.Worker createWorker() {
            return new ExecutorScheduler.ExecutorWorker(Runnable::run, false);
        }
    };

    RxJavaPlugins.setInitIoSchedulerHandler(scheduler -> immediate);
    RxJavaPlugins.setInitComputationSchedulerHandler(scheduler -> immediate);
    RxJavaPlugins.setInitNewThreadSchedulerHandler(scheduler -> immediate);
    RxJavaPlugins.setInitSingleSchedulerHandler(scheduler -> immediate);
    RxAndroidPlugins.setInitMainThreadSchedulerHandler(scheduler -> immediate);
}
 
Example 3
Source File: RxJavaHooksManualTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenIOScheduler_whenCalled_shouldExecuteTheHooks() {

    RxJavaPlugins.setInitIoSchedulerHandler((scheduler) -> {
        initHookCalled = true;
        return scheduler.call();
    });

    RxJavaPlugins.setIoSchedulerHandler((scheduler) -> {
        hookCalled = true;
        return scheduler;
    });

    Observable.range(1, 10)
        .map(v -> v * 2)
        .subscribeOn(Schedulers.io())
        .test();
    assertTrue(hookCalled && initHookCalled);
}
 
Example 4
Source File: NetworkAPITest.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
@BeforeClass
public static void init() {
    Scheduler immediate = new Scheduler() {
        @Override
        public Disposable scheduleDirect(@NonNull Runnable run, long delay, @NonNull TimeUnit unit) {
            return super.scheduleDirect(run, 0, unit);
        }

        @Override
        public Worker createWorker() {
            return new ExecutorScheduler.ExecutorWorker(Runnable::run, false);
        }
    };

    RxJavaPlugins.setInitIoSchedulerHandler(scheduler -> immediate);
    RxJavaPlugins.setInitComputationSchedulerHandler(scheduler -> immediate);
    RxJavaPlugins.setInitNewThreadSchedulerHandler(scheduler -> immediate);
    RxJavaPlugins.setInitSingleSchedulerHandler(scheduler -> immediate);
    RxAndroidPlugins.setInitMainThreadSchedulerHandler(scheduler -> immediate);

    OkHttpClient httpClient = TLSCompactHelper.getOKHttpClient();
    GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create();
    RxJava2CallAdapterFactory rxJava2CallAdapterFactory = RxJava2CallAdapterFactory.create();
    CompositeDisposable disposable = new CompositeDisposable();

    photoService = new PhotoService(
            httpClient,
            gsonConverterFactory,
            rxJava2CallAdapterFactory,
            disposable
    );
}
 
Example 5
Source File: ObservableGroupTest.java    From RxGroups with Apache License 2.0 5 votes vote down vote up
@Before public void setUp() throws IOException {
  RxJavaPlugins.setInitIoSchedulerHandler(new Function<Callable<Scheduler>, Scheduler>() {
    @Override
    public Scheduler apply(@NonNull Callable<Scheduler> schedulerCallable) throws Exception {
      return Schedulers.trampoline();
    }
  });
}