@Override public Completable apply(Integer t) throws Exception { return Completable.complete().doOnComplete(new Action() { @Override public void run() throws Exception { b[0] = true; } }); } })
@Test(expected = NullPointerException.class) public void doOnCompleteNull() { normal.completable.doOnComplete(null); }
@Override public Completable apply(Integer t) throws Exception { return Completable.complete().doOnComplete(new Action() { @Override public void run() throws Exception { b[0] = true; } }); } })
@Test(expected = NullPointerException.class) public void doOnCompletedNull() { normal.completable.doOnComplete(null); }
@Test(timeout = 5000) public void doOnCompleteNormal() { final AtomicInteger calls = new AtomicInteger(); Completable c = normal.completable.doOnComplete(new Action() { @Override public void run() { calls.getAndIncrement(); } }); c.blockingAwait(); Assert.assertEquals(1, calls.get()); }
@Test(timeout = 5000, expected = TestException.class) public void doOnCompletedThrows() { Completable c = normal.completable.doOnComplete(new Action() { @Override public void run() { throw new TestException(); } }); c.blockingAwait(); }
@Test(timeout = 5000) public void doOnCompletedNormal() { final AtomicInteger calls = new AtomicInteger(); Completable c = normal.completable.doOnComplete(new Action() { @Override public void run() { calls.getAndIncrement(); } }); c.blockingAwait(); Assert.assertEquals(1, calls.get()); }
@Test(timeout = 5000, expected = TestException.class) public void doOnCompleteThrows() { Completable c = normal.completable.doOnComplete(new Action() { @Override public void run() { throw new TestException(); } }); c.blockingAwait(); }
@Test(expected = NullPointerException.class) public void doOnCompleteNullValue() { Completable.complete().doOnComplete(null); }
@Test(timeout = 5000) public void subscribeDispose() throws InterruptedException { final AtomicBoolean complete = new AtomicBoolean(); Completable c = normal.completable .delay(200, TimeUnit.MILLISECONDS) .doOnComplete(new Action() { @Override public void run() { complete.set(true); } }); Disposable d = c.subscribe(); Thread.sleep(100); d.dispose(); Thread.sleep(150); Assert.assertFalse("Completed", complete.get()); }
@Test(timeout = 5000) public void doOnCompleteError() { final AtomicInteger calls = new AtomicInteger(); Completable c = error.completable.doOnComplete(new Action() { @Override public void run() { calls.getAndIncrement(); } }); try { c.blockingAwait(); Assert.fail("Failed to throw TestException"); } catch (TestException ex) { // expected } Assert.assertEquals(0, calls.get()); }
@Test(timeout = 5000) public void doOnCompletedError() { final AtomicInteger calls = new AtomicInteger(); Completable c = error.completable.doOnComplete(new Action() { @Override public void run() { calls.getAndIncrement(); } }); try { c.blockingAwait(); Assert.fail("Failed to throw TestException"); } catch (TestException ex) { // expected } Assert.assertEquals(0, calls.get()); }
@Test public void timerInterruptible() throws Exception { ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(); try { for (Scheduler s : new Scheduler[] { Schedulers.single(), Schedulers.computation(), Schedulers.newThread(), Schedulers.io(), Schedulers.from(exec) }) { final AtomicBoolean interrupted = new AtomicBoolean(); TestObserver<Void> to = Completable.timer(1, TimeUnit.MILLISECONDS, s) .doOnComplete(new Action() { @Override public void run() throws Exception { try { Thread.sleep(3000); } catch (InterruptedException ex) { interrupted.set(true); } } }) .test(); Thread.sleep(500); to.cancel(); Thread.sleep(500); assertTrue(s.getClass().getSimpleName(), interrupted.get()); } } finally { exec.shutdown(); } }
@Test(timeout = 5000) public void subscribe() throws InterruptedException { final AtomicBoolean complete = new AtomicBoolean(); Completable c = normal.completable .delay(100, TimeUnit.MILLISECONDS) .doOnComplete(new Action() { @Override public void run() { complete.set(true); } }); Disposable d = c.subscribe(); assertFalse(d.isDisposed()); Thread.sleep(150); Assert.assertTrue("Not completed", complete.get()); assertTrue(d.isDisposed()); }
@Test public void failSingleCompletableBlockingAwait() { try { RxJavaPlugins.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 { RxJavaPlugins.reset(); } }
@Test public void failSingleCompletableBlockingGet() { try { RxJavaPlugins.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 { RxJavaPlugins.reset(); } }
private Completable createAndConnectUserDataService(String listenKey) { userDataStreamingService = BinanceUserDataStreamingService.create(listenKey); return userDataStreamingService.connect().doOnComplete(() -> { LOG.info("Connected to authenticated web socket"); userDataChannel.onChangeListenKey(newListenKey -> { userDataStreamingService.disconnect().blockingAwait(); createAndConnectUserDataService(newListenKey).blockingAwait(); streamingMarketDataService.setUserDataStreamingService(userDataStreamingService); }); }); }
public Completable getObservable() { repository.log("log out"); final EmployeeMerchant employeeMerchant = repository.retrieveFromCache(UseCaseConstants.EMPLOYEE_MERCHANT); return repository.logout(employeeMerchant.getEmployee().getSessionToken()).doOnComplete(() -> { repository.evictFromCache(UseCaseConstants.EMPLOYEE_MERCHANT); repository.evictFromCache(UseCaseConstants.ORDER); }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activityComponent().inject(this); splashPresenter.attachView(this); Completable.complete() .delay(TasBoilerplateSettings.SPLASH_SCREEN_DELAY_SEC, TimeUnit.SECONDS) .doOnComplete(() -> splashPresenter.init()).subscribe(); }
private void showResult( int titleId, String account, String result ) { addDisposable( Completable.fromAction( () -> mDataManager.addAccountHistory( account )) .subscribeOn(getSchedulerProvider().io()) .observeOn( getSchedulerProvider().ui()) .doOnComplete(() -> getMvpView().showAccountInfo( titleId, account, result, null) ) .subscribe() ); }