Skip to content

Fixing docsReceived counter (#1840) #1881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public boolean hasNext() {
} catch (IOException ex) {
throw new EsHadoopIllegalStateException(String.format("Cannot create scroll for query [%s/%s]", query, body), ex);
}

read += batch.size();
stats.docsReceived += batch.size();
// no longer needed
body = null;
query = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@

public class ScrollQueryTest {

@Test
public void test() throws Exception {
RestRepository repository = mockRepository();
public void test(boolean firstScrollReturnsHits) throws Exception {
RestRepository repository = mockRepository(firstScrollReturnsHits);
ScrollReader scrollReader = Mockito.mock(ScrollReader.class);

String query = "/index/type/_search?scroll=10m&etc=etc";
Expand All @@ -54,23 +53,38 @@ public void test() throws Exception {
Mockito.verify(repository).close();
Stats stats = scrollQuery.stats();
Assert.assertEquals(1, stats.docsReceived);
Assert.assertEquals(1, scrollQuery.getRead());
}

@Test
public void testWithEmptyFirstScroll() throws Exception {
test(false);
}

@Test
public void testWithNonEmptyFirstScroll() throws Exception {
test(true);
}

private RestRepository mockRepository() throws Exception {
private RestRepository mockRepository(boolean firstScrollReturnsHits) throws Exception {
Map<String, Object> data = new HashMap<String, Object>();
data.put("field", "value");
String id = "1";
Object[] hit = new Object[]{id, data};

RestRepository mocked = Mockito.mock(RestRepository.class);

ScrollReader.Scroll start = new ScrollReader.Scroll("abcd", 10, Collections.<Object[]>emptyList(), 5, 5);
ScrollReader.Scroll start = new ScrollReader.Scroll("abcd", 10,
firstScrollReturnsHits ? Collections.singletonList(hit) : Collections.<Object[]>emptyList(),
5, 5);

Mockito.doReturn(start).when(mocked).scroll(Matchers.anyString(), Matchers.any(BytesArray.class), Matchers.any(ScrollReader.class));

ScrollReader.Scroll middle = new ScrollReader.Scroll("efgh", 10, Collections.<Object[]>emptyList(), 3, 3);
Mockito.doReturn(middle).when(mocked).scroll(Matchers.eq("abcd"), Matchers.any(ScrollReader.class));
ScrollReader.Scroll end = new ScrollReader.Scroll("ijkl", 10, Collections.singletonList(hit), 2, 1);
ScrollReader.Scroll end = new ScrollReader.Scroll("ijkl", 10,
firstScrollReturnsHits ? Collections.<Object[]>emptyList() : Collections.singletonList(hit),
2, 1);
Mockito.doReturn(end).when(mocked).scroll(Matchers.eq("efgh"), Matchers.any(ScrollReader.class));
ScrollReader.Scroll finalScroll = new ScrollReader.Scroll("mnop", 10, true);
Mockito.doReturn(finalScroll).when(mocked).scroll(Matchers.eq("ijkl"), Matchers.any(ScrollReader.class));
Expand Down