6
6
import org .junit .jupiter .api .Disabled ;
7
7
import org .junit .jupiter .api .Test ;
8
8
9
+ import java .util .ArrayList ;
10
+ import java .util .Arrays ;
11
+ import java .util .List ;
9
12
import java .util .concurrent .atomic .AtomicInteger ;
10
13
11
14
import static org .junit .jupiter .api .Assertions .assertEquals ;
12
15
13
- @ Disabled ("Getting this test in place to verify that setMaxBatches does not appear to work yet." )
14
16
public class SetMaxBatchesTest extends AbstractFunctionalTest {
15
17
18
+ @ Disabled ("Getting this test in place to verify that setMaxBatches does not work when used with a query." )
16
19
@ Test
17
- void test () {
20
+ void testWithQuery () {
18
21
writeJsonDocs (50 , "max-batches-test" );
19
22
20
23
DataMovementManager dmm = client .newDataMovementManager ();
@@ -33,4 +36,32 @@ void test() {
33
36
"expect 20 URIs back. But through 6.2.2 (and probably going back much further), all URIs are returned. " +
34
37
"Modifying the thread count and batch size do not appear to affect this at all." );
35
38
}
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
+ }
36
67
}
0 commit comments