@Test public void should_invoke_function_two_times_when_try_to_advance() { Function function = mock(Function.class); RequestResponseOK<Long> requestResponseOK1 = new RequestResponseOK<>(); requestResponseOK1.addResult(1L); requestResponseOK1.addResult(2L); requestResponseOK1.addResult(3L); requestResponseOK1.setHits(4, 0, 3, 3); RequestResponseOK<Long> requestResponseOK2 = new RequestResponseOK<>(); requestResponseOK2.addResult(4L); requestResponseOK2.setHits(4, 0, 3, 1); given(function.apply(any(SelectMultiQuery.class))).willReturn(requestResponseOK1).willReturn(requestResponseOK2); SelectMultiQuery query = new SelectMultiQuery(); Spliterator<Long> longSpliterator = new ScrollSpliterator<>(query, function, 3, 4); AtomicInteger counter = new AtomicInteger(0); longSpliterator.forEachRemaining(item -> counter.incrementAndGet()); assertThat(longSpliterator.estimateSize()).isEqualTo(4); assertThat(counter.get()).isEqualTo(4); verify(function, times(2)).apply(query); }
@Override public long estimateSize() { if (requestResponse == null) { executeQuery(); } return hits.getTotal(); }
ScrollSpliterator extends AbstractSpliterator<T> { @Override public long estimateSize() { if (requestResponse == null) { executeQuery(); } return hits.getTotal(); } }
ScrollSpliterator extends AbstractSpliterator<T> { @Override public long estimateSize() { if (requestResponse == null) { executeQuery(); } return hits.getTotal(); } ScrollSpliterator(SelectMultiQuery query, Function<SelectMultiQuery, RequestResponse<T>> repository,
        int scrollTimeout, int limit); }
ScrollSpliterator extends AbstractSpliterator<T> { @Override public long estimateSize() { if (requestResponse == null) { executeQuery(); } return hits.getTotal(); } ScrollSpliterator(SelectMultiQuery query, Function<SelectMultiQuery, RequestResponse<T>> repository,
        int scrollTimeout, int limit); @Override boolean tryAdvance(Consumer<? super T> action); @Override long estimateSize(); }
ScrollSpliterator extends AbstractSpliterator<T> { @Override public long estimateSize() { if (requestResponse == null) { executeQuery(); } return hits.getTotal(); } ScrollSpliterator(SelectMultiQuery query, Function<SelectMultiQuery, RequestResponse<T>> repository,
        int scrollTimeout, int limit); @Override boolean tryAdvance(Consumer<? super T> action); @Override long estimateSize();  }