rx.plugins.RxJavaSchedulersHook Java Examples
The following examples show how to use
rx.plugins.RxJavaSchedulersHook.
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: SignInPresenterTest.java From Moxy with MIT License | 6 votes |
@Before public void setUp() { MockitoAnnotations.initMocks(this); presenter = new SignInPresenter(); presenter.setViewState(signInViewState); RxJavaPlugins.getInstance().reset(); RxJavaPlugins.getInstance().registerSchedulersHook(new RxJavaSchedulersHook() { @Override public Scheduler getIOScheduler() { return Schedulers.immediate(); } }); RxAndroidPlugins.getInstance().reset(); RxAndroidPlugins.getInstance().registerSchedulersHook(new RxAndroidSchedulersHook() { @Override public Scheduler getMainThreadScheduler() { return Schedulers.immediate(); } }); }
Example #2
Source File: RepositoriesPresenterTest.java From Moxy with MIT License | 6 votes |
@Before public void setUp() { MockitoAnnotations.initMocks(this); presenter = new RepositoriesPresenter(); presenter.setViewState(repositoriesViewState); RxJavaPlugins.getInstance().reset(); RxJavaPlugins.getInstance().registerSchedulersHook(new RxJavaSchedulersHook() { @Override public Scheduler getIOScheduler() { return Schedulers.immediate(); } }); RxAndroidPlugins.getInstance().reset(); RxAndroidPlugins.getInstance().registerSchedulersHook(new RxAndroidSchedulersHook() { @Override public Scheduler getMainThreadScheduler() { return Schedulers.immediate(); } }); }
Example #3
Source File: RxHelper.java From sfs with Apache License 2.0 | 6 votes |
public static RxJavaSchedulersHook schedulerHook(Context context) { return new RxJavaSchedulersHook() { @Override public Scheduler getComputationScheduler() { return scheduler(context); } @Override public Scheduler getIOScheduler() { return blockingScheduler(context, true); } @Override public Scheduler getNewThreadScheduler() { return scheduler(context); } }; }
Example #4
Source File: RxUnitTestTools.java From fingerpoetry-android with Apache License 2.0 | 6 votes |
/** * 把异步变成同步,方便测试 */ public static void openRxTools() { if (isInitRxTools) { return; } isInitRxTools = true; RxAndroidSchedulersHook rxAndroidSchedulersHook = new RxAndroidSchedulersHook() { @Override public Scheduler getMainThreadScheduler() { return Schedulers.immediate(); } }; RxJavaSchedulersHook rxJavaSchedulersHook = new RxJavaSchedulersHook() { @Override public Scheduler getIOScheduler() { return Schedulers.immediate(); } }; RxAndroidPlugins.getInstance().registerSchedulersHook(rxAndroidSchedulersHook); RxJavaPlugins.getInstance().registerSchedulersHook(rxJavaSchedulersHook); }
Example #5
Source File: RxHelper.java From vertx-rx with Apache License 2.0 | 6 votes |
/** * Create a scheduler hook for a {@link Context} object, the {@link rx.plugins.RxJavaSchedulersHook#getIOScheduler()} * uses a blocking scheduler. * * @param context the context object * @return the scheduler hook */ public static RxJavaSchedulersHook schedulerHook(Context context) { return new RxJavaSchedulersHook() { @Override public Scheduler getComputationScheduler() { return scheduler(context); } @Override public Scheduler getIOScheduler() { return blockingScheduler(context.owner()); } @Override public Scheduler getNewThreadScheduler() { return scheduler(context); } }; }
Example #6
Source File: RxHelper.java From vertx-rx with Apache License 2.0 | 6 votes |
/** * Create a scheduler hook for a {@link Vertx} object, the {@link rx.plugins.RxJavaSchedulersHook#getIOScheduler()} * uses a blocking scheduler. * * @param vertx the vertx object * @return the scheduler hook */ public static RxJavaSchedulersHook schedulerHook(Vertx vertx) { return new RxJavaSchedulersHook() { @Override public Scheduler getComputationScheduler() { return scheduler(vertx); } @Override public Scheduler getIOScheduler() { return blockingScheduler(vertx); } @Override public Scheduler getNewThreadScheduler() { return scheduler(vertx); } }; }
Example #7
Source File: RunTestOnContextRx.java From sfs with Apache License 2.0 | 5 votes |
@Override public Statement apply(Statement base, Description description) { Statement st = new Statement() { @Override public void evaluate() throws Throwable { Vertx v = vertx(); RxJavaSchedulersHook hook = RxHelper.schedulerHook(v.getOrCreateContext()); RxJavaHooks.setOnIOScheduler(f -> hook.getIOScheduler()); RxJavaHooks.setOnNewThreadScheduler(f -> hook.getNewThreadScheduler()); RxJavaHooks.setOnComputationScheduler(f -> hook.getComputationScheduler()); base.evaluate(); } }; return super.apply(st, description); }
Example #8
Source File: NewsModuleApiImplTest.java From ZZShow with Apache License 2.0 | 5 votes |
@Test public void testLoadNews() throws Exception { System.out.println("-- 1.testLoadNews --"); // 让Schedulers.io()返回当前线程 RxJavaPlugins.getInstance().registerSchedulersHook(new RxJavaSchedulersHook() { @Override public Scheduler getIOScheduler() { return Schedulers.immediate(); } }); moduleApi.loadNews(new RequestCallBack<List<NewsSummary>>() { @Override public void beforeRequest() { } @Override public void success(List<NewsSummary> data) { } @Override public void onError(String errorMsg) { } }, ApiConstants.NETEASE_TYPE_OTHER, ApiConstants.NETEASE_ID_GAME, 0); assertEquals(1,1); }
Example #9
Source File: SchedulerTest.java From vertx-rx with Apache License 2.0 | 5 votes |
private void testSchedulerHook(Supplier<ContextScheduler> scheduler) throws Exception { RxJavaPlugins plugins = RxJavaPlugins.getInstance(); AtomicInteger scheduled = new AtomicInteger(); AtomicInteger called = new AtomicInteger(); CountDownLatch latchCalled = new CountDownLatch(1); plugins.registerSchedulersHook(new RxJavaSchedulersHook() { @Override public Action0 onSchedule(Action0 action) { scheduled.incrementAndGet(); return () -> { action.call(); called.getAndIncrement(); latchCalled.countDown(); }; } }); ContextScheduler scheduler2 = scheduler.get(); Scheduler.Worker worker = scheduler2.createWorker(); assertEquals(0, scheduled.get()); assertEquals(0, called.get()); CountDownLatch latch = new CountDownLatch(1); AtomicInteger workerScheduledVal = new AtomicInteger(); AtomicInteger workerCalledVal = new AtomicInteger(); worker.schedule(() -> { workerScheduledVal.set(scheduled.get()); workerCalledVal.set(called.get()); latch.countDown(); }, 0, SECONDS); awaitLatch(latch); awaitLatch(latchCalled); assertEquals(1, scheduled.get()); assertEquals(1, called.get()); assertEquals(1, workerScheduledVal.get()); assertEquals(0, workerCalledVal.get()); }
Example #10
Source File: SfsServer.java From sfs with Apache License 2.0 | 4 votes |
public static void initRxSchedulers(Context context) { RxJavaSchedulersHook hook = RxHelper.schedulerHook(context); RxJavaHooks.setOnIOScheduler(f -> hook.getIOScheduler()); RxJavaHooks.setOnNewThreadScheduler(f -> hook.getNewThreadScheduler()); RxJavaHooks.setOnComputationScheduler(f -> hook.getComputationScheduler()); }
Example #11
Source File: NativeExamples.java From vertx-rx with Apache License 2.0 | 4 votes |
public void schedulerHook(Vertx vertx) { RxJavaSchedulersHook hook = RxHelper.schedulerHook(vertx); RxJavaHooks.setOnIOScheduler(f -> hook.getIOScheduler()); RxJavaHooks.setOnNewThreadScheduler(f -> hook.getNewThreadScheduler()); RxJavaHooks.setOnComputationScheduler(f -> hook.getComputationScheduler()); }
Example #12
Source File: RxifiedExamples.java From vertx-rx with Apache License 2.0 | 4 votes |
public void schedulerHook(Vertx vertx) { RxJavaSchedulersHook hook = io.vertx.rxjava.core.RxHelper.schedulerHook(vertx); RxJavaHooks.setOnIOScheduler(f -> hook.getIOScheduler()); RxJavaHooks.setOnNewThreadScheduler(f -> hook.getNewThreadScheduler()); RxJavaHooks.setOnComputationScheduler(f -> hook.getComputationScheduler()); }
Example #13
Source File: RxIdler.java From RxIdler with Apache License 2.0 | 2 votes |
/** * An {@link RxJavaSchedulersHook} which wraps * <p> * <pre><code> * RxJavaPlugins.getInstance().registerSchedulersHook(RxIdler.hooks()); * </code></pre> */ @CheckResult @NonNull public static RxJavaSchedulersHook hooks() { return new RxIdlerHook(); }
Example #14
Source File: RxHelper.java From vertx-rx with Apache License 2.0 | 2 votes |
/** * Create a scheduler hook for a {@link io.vertx.rxjava.core.Vertx} object. * * @param vertx the vertx object * @return the scheduler hook */ public static RxJavaSchedulersHook schedulerHook(Vertx vertx) { return io.vertx.rx.java.RxHelper.schedulerHook(vertx.getDelegate()); }
Example #15
Source File: RxHelper.java From vertx-rx with Apache License 2.0 | 2 votes |
/** * Create a scheduler hook for a {@link io.vertx.rxjava.core.Context} object. * * @param context the context object * @return the scheduler hook */ public static RxJavaSchedulersHook schedulerHook(Context context) { return io.vertx.rx.java.RxHelper.schedulerHook(context.getDelegate()); }