24
24
import java .util .List ;
25
25
import java .util .concurrent .atomic .AtomicBoolean ;
26
26
27
+ import org .junit .jupiter .api .DisplayName ;
27
28
import org .junit .jupiter .api .Test ;
28
29
import org .springframework .data .util .StreamUtils ;
29
30
@@ -39,6 +40,8 @@ public void shouldCallClearScrollOnIteratorClose() {
39
40
// given
40
41
List <SearchHit <String >> hits = new ArrayList <>();
41
42
hits .add (getOneSearchHit ());
43
+ hits .add (getOneSearchHit ());
44
+ hits .add (getOneSearchHit ());
42
45
43
46
SearchScrollHits <String > searchHits = newSearchScrollHits (hits , "1234" );
44
47
@@ -51,16 +54,35 @@ public void shouldCallClearScrollOnIteratorClose() {
51
54
scrollId -> newSearchScrollHits (Collections .emptyList (), scrollId ), //
52
55
scrollIds -> clearScrollCalled .set (true ));
53
56
54
- while (iterator .hasNext ()) {
55
- iterator .next ();
56
- }
57
+ iterator .next ();
57
58
iterator .close ();
58
59
59
60
// then
60
61
assertThat (clearScrollCalled ).isTrue ();
61
62
62
63
}
63
64
65
+ @ Test // #1745
66
+ @ DisplayName ("should call clearScroll when no more data is available" )
67
+ void shouldCallClearScrollWhenNoMoreDataIsAvailable () {
68
+
69
+ List <SearchHit <String >> hits = new ArrayList <>();
70
+ hits .add (getOneSearchHit ());
71
+ SearchScrollHits <String > searchHits = newSearchScrollHits (hits , "1234" );
72
+ AtomicBoolean clearScrollCalled = new AtomicBoolean (false );
73
+
74
+ SearchHitsIterator <String > iterator = StreamQueries .streamResults ( //
75
+ 0 , //
76
+ searchHits , //
77
+ scrollId -> newSearchScrollHits (Collections .emptyList (), scrollId ), //
78
+ scrollIds -> clearScrollCalled .set (true ));
79
+
80
+ while (iterator .hasNext ()) {
81
+ iterator .next ();
82
+ }
83
+
84
+ assertThat (clearScrollCalled ).isTrue ();
85
+ }
64
86
private SearchHit <String > getOneSearchHit () {
65
87
return new SearchHit <String >(null , null , null , 0 , null , null , null , null , null , null , "one" );
66
88
}
0 commit comments