@Override public CompletableSource apply(Completable c) throws Exception { return c.subscribeOn(Schedulers.single()); } });
@Test(expected = NullPointerException.class) public void subscribeOnNull() { normal.completable.subscribeOn(null); }
@Test(timeout = 5000) public void subscribeOnNormal() { final AtomicReference<String> name = new AtomicReference<String>(); Completable c = Completable.unsafeCreate(new CompletableSource() { @Override public void subscribe(CompletableObserver s) { name.set(Thread.currentThread().getName()); EmptyDisposable.complete(s); } }).subscribeOn(Schedulers.computation()); c.blockingAwait(); Assert.assertTrue(name.get().startsWith("RxComputation")); }
@Test(timeout = 5000) public void subscribeOnError() { final AtomicReference<String> name = new AtomicReference<String>(); Completable c = Completable.unsafeCreate(new CompletableSource() { @Override public void subscribe(CompletableObserver s) { name.set(Thread.currentThread().getName()); EmptyDisposable.error(new TestException(), s); } }).subscribeOn(Schedulers.computation()); try { c.blockingAwait(); Assert.fail("No exception thrown"); } catch (TestException ex) { // expected } Assert.assertTrue(name.get().startsWith("RxComputation")); }
@Test public void dispose() { TestHelper.checkDisposed(PublishSubject.create().ignoreElements().subscribeOn(new TestScheduler())); }
@Test public void normal() { List<Throwable> list = TestCommonHelper.trackPluginErrors(); try { TestScheduler scheduler = new TestScheduler(); TestObserver<Void> ts = Completable.complete() .subscribeOn(scheduler) .test(); scheduler.advanceTimeBy(1, TimeUnit.SECONDS); ts.assertResult(); assertTrue(list.toString(), list.isEmpty()); } finally { RxJavaCommonPlugins.reset(); } }
@Test public void failSingleCompletableBlockingGet() { try { RxJavaCommonPlugins.setFailOnNonBlockingScheduler(true); Completable.complete() .subscribeOn(Schedulers.single()) .doOnComplete(new Action() { @Override public void run() throws Exception { Completable.complete().delay(10, TimeUnit.SECONDS).blockingGet(); } }) .test() .awaitDone(5, TimeUnit.SECONDS) .assertFailure(IllegalStateException.class); } finally { RxJavaCommonPlugins.reset(); } }
@Test public void failSingleCompletableBlockingAwait() { try { RxJavaCommonPlugins.setFailOnNonBlockingScheduler(true); Completable.complete() .subscribeOn(Schedulers.single()) .doOnComplete(new Action() { @Override public void run() throws Exception { Completable.complete().delay(10, TimeUnit.SECONDS).blockingAwait(); } }) .test() .awaitDone(5, TimeUnit.SECONDS) .assertFailure(IllegalStateException.class); } finally { RxJavaCommonPlugins.reset(); } }