@Test public void periodicDirectTaskRaceIO() throws Exception { final Scheduler scheduler = Schedulers.io(); for (int i = 0; i < 100; i++) { final Disposable d = scheduler.schedulePeriodicallyDirect( Functions.EMPTY_RUNNABLE, 0, 0, TimeUnit.MILLISECONDS); Thread.sleep(1); d.dispose(); } }
@Test public void overrideIoScheduler() { try { RxJavaCommonPlugins.setIoSchedulerHandler(replaceWithImmediate); assertSame(ImmediateThinScheduler.INSTANCE, Schedulers.io()); } finally { RxJavaCommonPlugins.reset(); } // make sure the reset worked assertNotSame(ImmediateThinScheduler.INSTANCE, Schedulers.io()); }
@Override public Flowable<Integer> apply(Integer i) throws Exception { return i == 3 ? Flowable.just(i) : Flowable .just(i) .delay(1, TimeUnit.MILLISECONDS, Schedulers.io()); } })
/** * Shuts down the standard Schedulers. * <p>The operation is idempotent and thread-safe. */ public static void shutdown() { computation().shutdown(); io().shutdown(); newThread().shutdown(); single().shutdown(); trampoline().shutdown(); SchedulerPoolFactory.shutdown(); }
/** * Starts the standard Schedulers. * <p>The operation is idempotent and thread-safe. */ public static void start() { computation().start(); io().start(); newThread().start(); single().start(); trampoline().start(); SchedulerPoolFactory.start(); }
@Test public void testDefaultIoSchedulerIsInitializedLazily() { // unsafe default Scheduler Callable should not be evaluated try { RxJavaCommonPlugins.setInitIoSchedulerHandler(initReplaceWithImmediate); RxJavaCommonPlugins.initIoScheduler(unsafeDefault); } finally { RxJavaCommonPlugins.reset(); } // make sure the reset worked assertNotSame(ImmediateThinScheduler.INSTANCE, Schedulers.io()); }
@Test public void timeoutException() throws Exception { Completable.never() .timeout(100, TimeUnit.MILLISECONDS, Schedulers.io()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TimeoutException.class); }
@Test public void timeout() throws Exception { Single.never().timeout(100, TimeUnit.MILLISECONDS, Schedulers.io()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TimeoutException.class); }
@Test public void delaySubscriptionTimeCustomScheduler() throws Exception { Single.just(1).delaySubscription(100, TimeUnit.MILLISECONDS, Schedulers.io()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void replaySelectorSizeScheduler() { Observable.just(1).replay(Functions.<Observable<Integer>>identity(), 1, Schedulers.io()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void replaySelectorSizeScheduler() { Flowable.just(1).replay(Functions.<Flowable<Integer>>identity(), 1, Schedulers.io()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void fromFutureTimeout() throws Exception { Observable.fromFuture(Observable.never() .toFuture(), 100, TimeUnit.MILLISECONDS, Schedulers.io()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TimeoutException.class); }
@Test public void workerDisposed() { Worker w = Schedulers.io().createWorker(); assertFalse(((Disposable)w).isDisposed()); w.dispose(); assertTrue(((Disposable)w).isDisposed()); }
@Test public void replaySelectorScheduler() { Flowable.just(1).replay(Functions.<Flowable<Integer>>identity(), Schedulers.io()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void workerDisposed() { Worker w = Schedulers.io().createWorker(); assertFalse(((Disposable)w).isDisposed()); w.dispose(); assertTrue(((Disposable)w).isDisposed()); }
@Test public void timespanTimeskipCustomScheduler() { Observable.just(1) .window(1, 1, TimeUnit.MINUTES, Schedulers.io()) .flatMap(Functions.<Observable<Integer>>identity()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test(timeout = 500) public void testWithObserveOn() throws InterruptedException { TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); Flowable.range(0, Flowable.bufferSize() * 10).onBackpressureDrop().observeOn(Schedulers.io()).subscribe(ts); ts.awaitTerminalEvent(); }
@Test public void timespanTimeskipCustomSchedulerBufferSize() { Flowable.range(1, 10) .window(1, 1, TimeUnit.MINUTES, Schedulers.io(), 2) .flatMap(Functions.<Flowable<Integer>>identity()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); }
@Test public void takeLastTimeDelayErrorCustomScheduler() { Flowable.just(1, 2).concatWith(Flowable.<Integer>error(new TestException())) .takeLast(1, TimeUnit.MINUTES, Schedulers.io(), true) .test() .assertFailure(TestException.class, 1, 2); }
@Test public void skipLastTimedCustomSchedulerDelayError() { Flowable.just(1).concatWith(Flowable.just(2).delay(500, TimeUnit.MILLISECONDS)) .skipLast(300, TimeUnit.MILLISECONDS, Schedulers.io(), true) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }