1818import org .junit .Test ;
1919import org .junit .rules .TestRule ;
2020import org .junit .runner .Description ;
21+ import org .junit .runners .model .Statement ;
2122
2223import com .microsoft .azure .documentdb .AccessCondition ;
2324import com .microsoft .azure .documentdb .AccessConditionType ;
3839import com .microsoft .azure .documentdb .MediaReadMode ;
3940import com .microsoft .azure .documentdb .Permission ;
4041import com .microsoft .azure .documentdb .PermissionMode ;
42+ import com .microsoft .azure .documentdb .QueryIterable ;
4143import com .microsoft .azure .documentdb .RequestOptions ;
4244import com .microsoft .azure .documentdb .ResourceResponse ;
4345import com .microsoft .azure .documentdb .StoredProcedure ;
@@ -337,9 +339,12 @@ public void testCollectionCrud() throws DocumentClientException {
337339
338340 @ Test
339341 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 ();
343348 final int numOfDocuments = 10 ;
344349
345350 // Create 10 documents.
@@ -348,9 +353,9 @@ public void testQueryIterableCrud() throws DocumentClientException {
348353 client .createDocument (this .collectionForTest .getSelfLink (), documentDefinition , null , false );
349354 }
350355
351- int noOfDocumentsPerPage = numOfDocuments / 5 ;
356+ int numOfDocumentsPerPage = numOfDocuments / 5 ;
352357 FeedOptions fo = new FeedOptions ();
353- fo .setPageSize (noOfDocumentsPerPage );
358+ fo .setPageSize (numOfDocumentsPerPage );
354359 FeedResponse <Document > feedResponse ;
355360 int i = 0 ;
356361 String continuationToken = null ;
@@ -365,7 +370,7 @@ public void testQueryIterableCrud() throws DocumentClientException {
365370 for (Document document : feedResponse .getQueryIterable ()) {
366371 i ++;
367372 currentPage .add (document .getId ());
368- if (i == noOfDocumentsPerPage ) {
373+ if (i == numOfDocumentsPerPage ) {
369374 break ;
370375 }
371376 }
@@ -385,7 +390,21 @@ public void testQueryIterableCrud() throws DocumentClientException {
385390 } while (continuationToken != null );
386391
387392 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 ());
389408 }
390409
391410 @ Test
0 commit comments