@Override public Flowable<Long> apply(Integer t) { return Flowable.timer(1, SECONDS, sched); } });
@Override public Publisher<Long> call() throws Exception { if (count++ == 1) { return null; } return Flowable.timer(1, TimeUnit.MILLISECONDS); } }, new Callable<Collection<Object>>() {
@Override public Publisher<Long> createPublisher(final long elements) { return Flowable.timer(1, TimeUnit.MILLISECONDS) .onBackpressureLatest() ; }
@Override public Publisher<Long> call() throws Exception { if (count++ == 1) { throw new TestException(); } return Flowable.timer(1, TimeUnit.MILLISECONDS); } }, new Callable<Collection<Object>>() {
@Test(expected = NullPointerException.class) public void timerUnitNull() { Flowable.timer(1, null); }
@Test(expected = NullPointerException.class) public void timerSchedulerNull() { Flowable.timer(1, TimeUnit.SECONDS, null); }
@Test public void testTimerOnce() { Flowable.timer(100, TimeUnit.MILLISECONDS, scheduler).subscribe(subscriber); scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); verify(subscriber, times(1)).onNext(0L); verify(subscriber, times(1)).onComplete(); verify(subscriber, never()).onError(any(Throwable.class)); }
@Test public void disposed() { TestHelper.checkDisposed(Flowable.timer(1, TimeUnit.DAYS)); }
@Test public void timerDelayZero() { List<Throwable> errors = TestHelper.trackPluginErrors(); try { for (int i = 0; i < 1000; i++) { Flowable.timer(0, TimeUnit.MILLISECONDS).blockingFirst(); } assertTrue(errors.toString(), errors.isEmpty()); } finally { RxJavaPlugins.reset(); } }
@SuppressWarnings("unchecked") @Test public void bufferBoundaryHint() { Flowable.range(1, 5).buffer(Flowable.timer(1, TimeUnit.MINUTES), 2) .test() .assertResult(Arrays.asList(1, 2, 3, 4, 5)); }
@Test public void backpressureNotReady() { Flowable.timer(1, TimeUnit.MILLISECONDS) .test(0L) .awaitDone(5, TimeUnit.SECONDS) .assertFailure(MissingBackpressureException.class); }
@Test public void emitLastOther() { Flowable.just(1) .sample(Flowable.timer(1, TimeUnit.DAYS), true) .test() .assertResult(1); }
@Test public void emitLastOtherEmpty() { Flowable.empty() .sample(Flowable.timer(1, TimeUnit.DAYS), true) .test() .assertResult(); }
@Test public void normalFlowable() { Maybe.just(1) .timeout(Flowable.timer(1, TimeUnit.DAYS)) .test() .assertResult(1); }
@Test public void neverFlowable() { Maybe.never() .timeout(Flowable.timer(1, TimeUnit.MILLISECONDS)) .test() .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TimeoutException.class); }
@Test public void delaySubscriptionFlowable() throws Exception { Single.just(1).delaySubscription(Flowable.timer(100, TimeUnit.MILLISECONDS)) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void normalFlowableFallback() { Maybe.just(1) .timeout(Flowable.timer(1, TimeUnit.DAYS), Maybe.just(2)) .test() .assertResult(1); }
@Test public void neverFlowableFallback() { Maybe.never() .timeout(Flowable.timer(1, TimeUnit.MILLISECONDS), Maybe.just(2)) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(2); }
@Test public void backpressureNoRequest() { Flowable.just(1) .debounce(Functions.justFunction(Flowable.timer(1, TimeUnit.MILLISECONDS))) .test(0L) .awaitDone(5, TimeUnit.SECONDS) .assertFailure(MissingBackpressureException.class); }
@Test public void shouldNotCompleteIfThereArePendingScalarSynchronousEmissionsWhenTheLastInnerSubscriberCompletes() { TestScheduler scheduler = new TestScheduler(); Flowable<Long> source = Flowable.mergeDelayError(Flowable.just(1L), Flowable.timer(1, TimeUnit.SECONDS, scheduler).skip(1)); TestSubscriber<Long> subscriber = new TestSubscriber<Long>(0L); source.subscribe(subscriber); scheduler.advanceTimeBy(1, TimeUnit.SECONDS); subscriber.assertNoValues(); subscriber.assertNotComplete(); subscriber.request(1); subscriber.assertValue(1L); // TODO: it should be acceptable to get a completion event without requests // assertEquals(Collections.<Notification<Long>>emptyList(), subscriber.getOnCompletedEvents()); // subscriber.request(1); subscriber.assertTerminated(); }