@Test public void testOnStartRequestsAreAdditiveAndOverflowBecomesMaxValue() { final List<Integer> list = new ArrayList<>(); Observable.just(1, 2, 3, 4, 5) .subscribe( new Observer<Integer>() { @Override public void onStart() { request(2); request(Long.MAX_VALUE - 1); } @Override public void onComplete() {} @Override public void onError(Throwable e) {} @Override public void onNext(Integer t) { list.add(t); } }); assertEquals(Arrays.asList(1, 2, 3, 4, 5), list); }
@Test public void testDelayErrorMaxConcurrent() { final List<Long> requests = new ArrayList<>(); Observable<Integer> source = Observable.mergeDelayError( Observable.just( Observable.just(1).asObservable(), Observable.<Integer>error(new TestException())) .doOnRequest( new LongConsumer() { @Override public void accept(long t1) { requests.add(t1); } }), 1); TestSubscriber<Integer> ts = new TestSubscriber<>(); source.subscribe(ts); ts.assertValue(1); ts.assertTerminated(); ts.assertError(TestException.class); assertEquals(Arrays.asList(1L, 1L, 1L), requests); }
/** This uses the public API collect which uses scan under the covers. */ @Test public void testSeedFactory() { Observable<List<Integer>> o = Observable.range(1, 10) .collect( new Supplier<List<Integer>>() { @Override public List<Integer> get() { return new ArrayList<>(); } }, new BiConsumer<List<Integer>, Integer>() { @Override public void accept(List<Integer> list, Integer t2) { list.add(t2); } }) .takeLast(1); assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), o.toBlocking().single()); assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), o.toBlocking().single()); }