66import org .junit .jupiter .api .Disabled ;
77import org .junit .jupiter .api .Test ;
88
9+ import java .util .ArrayList ;
10+ import java .util .Arrays ;
11+ import java .util .List ;
912import java .util .concurrent .atomic .AtomicInteger ;
1013
1114import static org .junit .jupiter .api .Assertions .assertEquals ;
1215
13- @ Disabled ("Getting this test in place to verify that setMaxBatches does not appear to work yet." )
1416public class SetMaxBatchesTest extends AbstractFunctionalTest {
1517
18+ @ Disabled ("Getting this test in place to verify that setMaxBatches does not work when used with a query." )
1619 @ Test
17- void test () {
20+ void testWithQuery () {
1821 writeJsonDocs (50 , "max-batches-test" );
1922
2023 DataMovementManager dmm = client .newDataMovementManager ();
@@ -33,4 +36,32 @@ void test() {
3336 "expect 20 URIs back. But through 6.2.2 (and probably going back much further), all URIs are returned. " +
3437 "Modifying the thread count and batch size do not appear to affect this at all." );
3538 }
39+
40+ /**
41+ * This verifies that setMaxBatches works with an iterator. The feature appears to have been introduced in 5.1.0,
42+ * so since then, it's only ever worked for an iterator. It does not work when an actual query is involved.
43+ */
44+ @ Test
45+ void iteratorTest () {
46+ List <String > results = new ArrayList <>();
47+
48+ List <String > input = new ArrayList <>();
49+ for (int i = 1 ; i <= 100 ; i ++) {
50+ input .add (i + "" );
51+ }
52+
53+ DataMovementManager dmm = client .newDataMovementManager ();
54+ QueryBatcher queryBatcher = dmm
55+ .newQueryBatcher (input .iterator ())
56+ .withThreadCount (4 )
57+ .withBatchSize (10 )
58+ .onUrisReady (batch -> results .addAll (Arrays .asList (batch .getItems ())));
59+
60+ queryBatcher .setMaxBatches (2 );
61+ dmm .startJob (queryBatcher );
62+ queryBatcher .awaitCompletion ();
63+ dmm .stopJob (queryBatcher );
64+
65+ assertEquals (20 , results .size ());
66+ }
3667}
0 commit comments