18
18
import org .junit .Test ;
19
19
import org .junit .rules .TestRule ;
20
20
import org .junit .runner .Description ;
21
+ import org .junit .runners .model .Statement ;
21
22
22
23
import com .microsoft .azure .documentdb .AccessCondition ;
23
24
import com .microsoft .azure .documentdb .AccessConditionType ;
38
39
import com .microsoft .azure .documentdb .MediaReadMode ;
39
40
import com .microsoft .azure .documentdb .Permission ;
40
41
import com .microsoft .azure .documentdb .PermissionMode ;
42
+ import com .microsoft .azure .documentdb .QueryIterable ;
41
43
import com .microsoft .azure .documentdb .RequestOptions ;
42
44
import com .microsoft .azure .documentdb .ResourceResponse ;
43
45
import com .microsoft .azure .documentdb .StoredProcedure ;
@@ -337,9 +339,12 @@ public void testCollectionCrud() throws DocumentClientException {
337
339
338
340
@ Test
339
341
public void testQueryIterableCrud () throws DocumentClientException {
340
- DocumentClient client = new DocumentClient (HOST , MASTER_KEY , ConnectionPolicy .GetDefault (), ConsistencyLevel .Session );
341
- List <Document > documents = client .readDocuments (this .collectionForTest .getSelfLink (), null ).getQueryIterable ().toList ();
342
- int beforeCreateDocumentsCount = documents .size ();
342
+ DocumentClient client = new DocumentClient (HOST ,
343
+ MASTER_KEY ,
344
+ ConnectionPolicy .GetDefault (),
345
+ ConsistencyLevel .Session );
346
+ List <Document > documents = client .readDocuments (this .collectionForTest .getSelfLink (),
347
+ null ).getQueryIterable ().toList ();
343
348
final int numOfDocuments = 10 ;
344
349
345
350
// Create 10 documents.
@@ -348,9 +353,9 @@ public void testQueryIterableCrud() throws DocumentClientException {
348
353
client .createDocument (this .collectionForTest .getSelfLink (), documentDefinition , null , false );
349
354
}
350
355
351
- int noOfDocumentsPerPage = numOfDocuments / 5 ;
356
+ int numOfDocumentsPerPage = numOfDocuments / 5 ;
352
357
FeedOptions fo = new FeedOptions ();
353
- fo .setPageSize (noOfDocumentsPerPage );
358
+ fo .setPageSize (numOfDocumentsPerPage );
354
359
FeedResponse <Document > feedResponse ;
355
360
int i = 0 ;
356
361
String continuationToken = null ;
@@ -365,7 +370,7 @@ public void testQueryIterableCrud() throws DocumentClientException {
365
370
for (Document document : feedResponse .getQueryIterable ()) {
366
371
i ++;
367
372
currentPage .add (document .getId ());
368
- if (i == noOfDocumentsPerPage ) {
373
+ if (i == numOfDocumentsPerPage ) {
369
374
break ;
370
375
}
371
376
}
@@ -385,7 +390,21 @@ public void testQueryIterableCrud() throws DocumentClientException {
385
390
} while (continuationToken != null );
386
391
387
392
documents = client .readDocuments (this .collectionForTest .getSelfLink (), null ).getQueryIterable ().toList ();
388
- Assert .assertEquals (beforeCreateDocumentsCount + numOfDocuments , documents .size ());
393
+ Assert .assertEquals (numOfDocuments , documents .size ());
394
+
395
+ // Test fetch next block.
396
+ fo = new FeedOptions ();
397
+ fo .setPageSize (6 );
398
+
399
+ QueryIterable <Document > queryItr =
400
+ client .readDocuments (this .collectionForTest .getSelfLink (), fo ).getQueryIterable ();
401
+ Assert .assertEquals (6 , queryItr .fetchNextBlock ().size ());
402
+ Assert .assertEquals (4 , queryItr .fetchNextBlock ().size ());
403
+
404
+ // Reset the query iterable.
405
+ queryItr .reset ();
406
+ Assert .assertEquals (6 , queryItr .fetchNextBlock ().size ());
407
+ Assert .assertEquals (4 , queryItr .fetchNextBlock ().size ());
389
408
}
390
409
391
410
@ Test
0 commit comments