36
36
37
37
public class ScrollQueryTest {
38
38
39
- @ Test
40
- public void test () throws Exception {
41
- RestRepository repository = mockRepository ();
39
+ public void test (boolean firstScrollReturnsHits ) throws Exception {
40
+ RestRepository repository = mockRepository (firstScrollReturnsHits );
42
41
ScrollReader scrollReader = Mockito .mock (ScrollReader .class );
43
42
44
43
String query = "/index/type/_search?scroll=10m&etc=etc" ;
@@ -54,23 +53,38 @@ public void test() throws Exception {
54
53
Mockito .verify (repository ).close ();
55
54
Stats stats = scrollQuery .stats ();
56
55
Assert .assertEquals (1 , stats .docsReceived );
56
+ Assert .assertEquals (1 , scrollQuery .getRead ());
57
+ }
58
+
59
+ @ Test
60
+ public void testWithEmptyFirstScroll () throws Exception {
61
+ test (false );
62
+ }
63
+
64
+ @ Test
65
+ public void testWithNonEmptyFirstScroll () throws Exception {
66
+ test (true );
57
67
}
58
68
59
- private RestRepository mockRepository () throws Exception {
69
+ private RestRepository mockRepository (boolean firstScrollReturnsHits ) throws Exception {
60
70
Map <String , Object > data = new HashMap <String , Object >();
61
71
data .put ("field" , "value" );
62
72
String id = "1" ;
63
73
Object [] hit = new Object []{id , data };
64
74
65
75
RestRepository mocked = Mockito .mock (RestRepository .class );
66
76
67
- ScrollReader .Scroll start = new ScrollReader .Scroll ("abcd" , 10 , Collections .<Object []>emptyList (), 5 , 5 );
77
+ ScrollReader .Scroll start = new ScrollReader .Scroll ("abcd" , 10 ,
78
+ firstScrollReturnsHits ? Collections .singletonList (hit ) : Collections .<Object []>emptyList (),
79
+ 5 , 5 );
68
80
69
81
Mockito .doReturn (start ).when (mocked ).scroll (Matchers .anyString (), Matchers .any (BytesArray .class ), Matchers .any (ScrollReader .class ));
70
82
71
83
ScrollReader .Scroll middle = new ScrollReader .Scroll ("efgh" , 10 , Collections .<Object []>emptyList (), 3 , 3 );
72
84
Mockito .doReturn (middle ).when (mocked ).scroll (Matchers .eq ("abcd" ), Matchers .any (ScrollReader .class ));
73
- ScrollReader .Scroll end = new ScrollReader .Scroll ("ijkl" , 10 , Collections .singletonList (hit ), 2 , 1 );
85
+ ScrollReader .Scroll end = new ScrollReader .Scroll ("ijkl" , 10 ,
86
+ firstScrollReturnsHits ? Collections .<Object []>emptyList () : Collections .singletonList (hit ),
87
+ 2 , 1 );
74
88
Mockito .doReturn (end ).when (mocked ).scroll (Matchers .eq ("efgh" ), Matchers .any (ScrollReader .class ));
75
89
ScrollReader .Scroll finalScroll = new ScrollReader .Scroll ("mnop" , 10 , true );
76
90
Mockito .doReturn (finalScroll ).when (mocked ).scroll (Matchers .eq ("ijkl" ), Matchers .any (ScrollReader .class ));
0 commit comments