@Test(expected = NullPointerException.class) public void timeoutSchedulerNull() { normal.completable.timeout(1, TimeUnit.SECONDS, (Scheduler)null); }
@Test(expected = NullPointerException.class) public void timeoutUnitNull() { normal.completable.timeout(1, null); }
@Test(expected = NullPointerException.class) public void timeoutOtherNull() { normal.completable.timeout(1, TimeUnit.SECONDS, (Completable)null); }
@Test(timeout = 5000) public void timeoutTimerCancelled() throws InterruptedException { Completable c = Completable.fromCallable(new Callable<Object>() { @Override public Object call() throws Exception { Thread.sleep(50); return null; } }).timeout(100, TimeUnit.MILLISECONDS, normal.completable); c.blockingAwait(); Thread.sleep(100); normal.assertSubscriptions(0); }
@Test(timeout = 5000) public void timeoutEmitError() { Throwable e = Completable.never().timeout(100, TimeUnit.MILLISECONDS).blockingGet(); Assert.assertTrue(e instanceof TimeoutException); }
@Test(timeout = 5000) public void timeoutSwitchNormal() { Completable c = Completable.never().timeout(100, TimeUnit.MILLISECONDS, normal.completable); c.blockingAwait(); normal.assertSubscriptions(1); }
@Test public void mainSuccess() { Completable.complete() .timeout(1, TimeUnit.DAYS) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(); }
@Test public void mainError() { Completable.error(new TestException()) .timeout(1, TimeUnit.DAYS) .test() .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TestException.class); }
@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 otherErrors() { Completable.never() .timeout(1, TimeUnit.MILLISECONDS, Completable.error(new TestException())) .test() .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TestException.class); }
@Test public void timeoutContinueOther() throws Exception { final int[] call = { 0 }; Completable other = Completable.fromAction(new Action() { @Override public void run() throws Exception { call[0]++; } }); Completable.never() .timeout(100, TimeUnit.MILLISECONDS, Schedulers.io(), other) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(); assertEquals(1, call[0]); }
@Test public void shouldUnsubscribeFromUnderlyingSubscriptionOnDispose() { final PublishSubject<String> subject = PublishSubject.create(); final TestScheduler scheduler = new TestScheduler(); final TestObserver<Void> observer = subject.ignoreElements() .timeout(100, TimeUnit.MILLISECONDS, scheduler) .test(); assertTrue(subject.hasObservers()); observer.dispose(); assertFalse(subject.hasObservers()); }
.timeout(1, TimeUnit.MILLISECONDS, scheduler, Completable.complete()).test();