@Test public void shouldDeleteScrollIfFinishedOnSecondResponse() throws IOException { ElasticSearchClient client = Mockito.mock(ElasticSearchClient.class); ElasticSearchResponse initialResponse = Mockito.mock(ElasticSearchResponse.class); ElasticSearchResponse secondResponse = Mockito.mock(ElasticSearchResponse.class); int batchSize = 5; String scrollId = "testScrollId"; List<RawQuery.Result<String>> initialResults = makeTestResults(batchSize); setupResultMocks(initialResults, initialResponse, scrollId); List<RawQuery.Result<String>> secondResults = makeTestResults(batchSize-1); Mockito.when(secondResponse.getResults()).thenReturn(secondResults.stream()); Mockito.when(secondResponse.numResults()).thenReturn(secondResults.size()); Mockito.when(client.search(scrollId)).thenReturn(secondResponse); ElasticSearchScroll scroll = new ElasticSearchScroll(client, initialResponse, batchSize); for(int i=0; i<batchSize; i++){ scroll.next(); } Mockito.verify(client, Mockito.never()).deleteScroll(Mockito.any()); scroll.next(); Mockito.verify(client).deleteScroll(scrollId); }
@Override public Result<String> next() { if (hasNext()) { return queue.remove(); } throw new NoSuchElementException(); }
ElasticSearchScroll implements Iterator<RawQuery.Result<String>> { @Override public Result<String> next() { if (hasNext()) { return queue.remove(); } throw new NoSuchElementException(); } }
ElasticSearchScroll implements Iterator<RawQuery.Result<String>> { @Override public Result<String> next() { if (hasNext()) { return queue.remove(); } throw new NoSuchElementException(); } ElasticSearchScroll(ElasticSearchClient client, ElasticSearchResponse initialResponse, int nbDocByQuery); }
ElasticSearchScroll implements Iterator<RawQuery.Result<String>> { @Override public Result<String> next() { if (hasNext()) { return queue.remove(); } throw new NoSuchElementException(); } ElasticSearchScroll(ElasticSearchClient client, ElasticSearchResponse initialResponse, int nbDocByQuery); @Override boolean hasNext(); @Override Result<String> next(); }
ElasticSearchScroll implements Iterator<RawQuery.Result<String>> { @Override public Result<String> next() { if (hasNext()) { return queue.remove(); } throw new NoSuchElementException(); } ElasticSearchScroll(ElasticSearchClient client, ElasticSearchResponse initialResponse, int nbDocByQuery); @Override boolean hasNext(); @Override Result<String> next();  }