/** * Begin executing the blocking event loop without any initial action. * <p> * This method will block until the {@link #shutdown()} is invoked. * @see #execute(Action) */ public void execute() { execute(Functions.EMPTY_ACTION); }
/** * Begin executing the blocking event loop without any initial action. * <p> * This method will block until the {@link #shutdown()} is invoked. * @see #execute(Action) */ public void execute() { execute(Functions.EMPTY_ACTION); }
@Test public void test() { BlockingScheduler bs = new BlockingScheduler(); bs.execute(() -> { Observable.fromCallable(() -> Thread.currentThread()) .concatMap(empty -> Observable.just(empty)) .subscribeOn(Schedulers.io()) .observeOn(bs) .doFinally(() -> bs.shutdown()) .subscribe(System.out::println); }); } }
final BlockingScheduler scheduler = new BlockingScheduler(); scheduler.execute(new Action() { @Override public void run() throws Exception {
final Thread[] t1 = { null }; scheduler.execute(new Action() { @Override public void run() throws Exception {
@Test(timeout = 10000) public void asyncInterrupt() { List<Throwable> errors = TestHelper.trackPluginErrors(); try { final BlockingScheduler scheduler = new BlockingScheduler(); Schedulers.single().scheduleDirect(new Runnable() { @Override public void run() { scheduler.shutdown.set(true); scheduler.thread.interrupt(); } }, 500, TimeUnit.MILLISECONDS); scheduler.execute(); assertTrue(errors.toString(), errors.isEmpty()); } finally { RxJavaPlugins.reset(); } }
try { final BlockingScheduler scheduler = new BlockingScheduler(); scheduler.execute(new Action() { @Override public void run() throws Exception {
@Test(timeout = 10000) public void workerUntimed() { List<Throwable> errors = TestHelper.trackPluginErrors(); try { final BlockingScheduler scheduler = new BlockingScheduler(); scheduler.execute(new Action() { @Override public void run() throws Exception { Flowable.range(1, 5) .subscribeOn(scheduler) .doAfterTerminate(new Action() { @Override public void run() throws Exception { scheduler.shutdown(); } }) .subscribe(ts); ts.assertEmpty(); } }); ts.assertResult(1, 2, 3, 4, 5); assertTrue(errors.toString(), errors.isEmpty()); } finally { RxJavaPlugins.reset(); } }
@Test(timeout = 10000) public void workerTimed() { List<Throwable> errors = TestHelper.trackPluginErrors(); try { final BlockingScheduler scheduler = new BlockingScheduler(); scheduler.execute(new Action() { @Override public void run() throws Exception { Flowable.range(1, 5) .subscribeOn(scheduler) .delay(100, TimeUnit.MILLISECONDS, scheduler) .doAfterTerminate(new Action() { @Override public void run() throws Exception { scheduler.shutdown(); } }) .subscribe(ts); ts.assertEmpty(); } }); ts.assertResult(1, 2, 3, 4, 5); assertTrue(errors.toString(), errors.isEmpty()); } finally { RxJavaPlugins.reset(); } }
@Test(timeout = 10000) public void asyncShutdown() { List<Throwable> errors = TestHelper.trackPluginErrors(); try { final BlockingScheduler scheduler = new BlockingScheduler(); Schedulers.single().scheduleDirect(new Runnable() { @Override public void run() { scheduler.scheduleDirect(Functions.EMPTY_RUNNABLE); scheduler.shutdown(); scheduler.shutdown(); assertTrue(scheduler.scheduleDirect(Functions.EMPTY_RUNNABLE).isDisposed()); } }, 500, TimeUnit.MILLISECONDS); scheduler.execute(); assertTrue(errors.toString(), errors.isEmpty()); } finally { RxJavaPlugins.reset(); } }
@Test(timeout = 10000) public void directTimed() { List<Throwable> errors = TestHelper.trackPluginErrors(); try { final BlockingScheduler scheduler = new BlockingScheduler(); scheduler.execute(new Action() { @Override public void run() throws Exception { ts.onSubscribe(new BooleanSubscription()); scheduler.scheduleDirect(new Runnable() { @Override public void run() { ts.onNext(1); ts.onNext(2); ts.onNext(3); ts.onNext(4); ts.onNext(5); ts.onComplete(); scheduler.shutdown(); } }, 100, TimeUnit.MILLISECONDS); ts.assertEmpty(); } }); ts.assertResult(1, 2, 3, 4, 5); assertTrue(errors.toString(), errors.isEmpty()); } finally { RxJavaPlugins.reset(); } }
scheduler.execute(new Action() { @Override public void run() throws Exception {
scheduler.execute(new Action() { @Override public void run() throws Exception {
try { final BlockingScheduler scheduler = new BlockingScheduler(); scheduler.execute(new Action() { @Override public void run() throws Exception {
try { final BlockingScheduler scheduler = new BlockingScheduler(); scheduler.execute(new Action() { @Override public void run() throws Exception {
try { final BlockingScheduler scheduler = new BlockingScheduler(); scheduler.execute(new Action() { @Override public void run() throws Exception {
try { final BlockingScheduler scheduler = new BlockingScheduler(); scheduler.execute(new Action() { @Override public void run() throws Exception {
@Test(timeout = 10000) public void directCrash() { List<Throwable> errors = TestHelper.trackPluginErrors(); try { final BlockingScheduler scheduler = new BlockingScheduler(); scheduler.execute(new Action() { @Override public void run() throws Exception { scheduler.scheduleDirect(new Runnable() { @Override public void run() { scheduler.shutdown(); throw new IllegalArgumentException(); } }); } }); TestHelper.assertError(errors, 0, IllegalArgumentException.class); } finally { RxJavaPlugins.reset(); } }
@Test(timeout = 10000) public void workerCrash() { List<Throwable> errors = TestHelper.trackPluginErrors(); try { final BlockingScheduler scheduler = new BlockingScheduler(); scheduler.execute(new Action() { @Override public void run() throws Exception { final Worker worker = scheduler.createWorker(); worker.schedule(new Runnable() { @Override public void run() { worker.dispose(); scheduler.shutdown(); throw new IllegalArgumentException(); } }); } }); TestHelper.assertError(errors, 0, IllegalArgumentException.class); } finally { RxJavaPlugins.reset(); } }
@Test public void test() throws Exception { BlockingScheduler blocking = new BlockingScheduler(); blocking.execute(() -> { Flowable .create(new FlowableOnSubscribe<Integer>() { @Override public void subscribe(FlowableEmitter<Integer> emitter) throws Exception { for (int i = 0; i < 1000; i++) { emitter.onNext(i); } } }, BackpressureStrategy.LATEST) .subscribeOn(Schedulers.newThread(), false) .observeOn(blocking) .subscribe(new Consumer<Integer>() { @Override public void accept(Integer integer) throws Exception { System.out.println("LATEST " + integer + ""); } }, new Consumer<Throwable>() { @Override public void accept(Throwable throwable) throws Exception { System.out.println("LATEST Throwable: " + throwable.getMessage()); } }, () -> blocking.shutdown()); }); } }