Source:
public void testQueryIterableCrud() throws DocumentClientException { DocumentClient client = new DocumentClient(HOST, MASTER_KEY, ConnectionPolicy.GetDefault(), ConsistencyLevel.Session); List<Document> documents = client.readDocuments(this.collectionForTest.getSelfLink(), null).getQueryIterable().toList(); int beforeCreateDocumentsCount = documents.size(); int noOfDocuments = 10; for (int i = 0; i < noOfDocuments; ++i) { Document documentDefinition = new Document("{ 'name': 'For paging test' }"); client.createDocument(this.collectionForTest.getSelfLink(), documentDefinition, null, false); } int noOfDocumentsPerPage = noOfDocuments / 5; FeedOptions fo = new FeedOptions(); fo.setPageSize(noOfDocumentsPerPage); FeedResponse<Document> feedResponse; Iterator<Document> iterator; int i = 0; String continuationToken = null; List<String> currentPage = new ArrayList<String>(); List<String> previousPage = new ArrayList<String>(); do { currentPage.clear(); fo.setRequestContinuation(continuationToken); feedResponse = client.readDocuments(this.collectionForTest.getSelfLink(), fo); iterator = feedResponse.getQueryIterator(); i = 0; while (iterator.hasNext()) { i++; Document document = iterator.next(); currentPage.add(document.getId()); if (i == noOfDocumentsPerPage) { break; } } continuationToken = feedResponse.getResponseContinuation(); for (String idFromCurrentPage : currentPage) { if (previousPage.contains(idFromCurrentPage)) { Assert.fail("Both pages contain same id " + idFromCurrentPage); } } previousPage.clear(); previousPage.addAll(currentPage); try { Thread.sleep(1000); } catch (InterruptedException e) { } } while (continuationToken != null); documents = client.readDocuments(this.collectionForTest.getSelfLink(), null).getQueryIterable().toList(); Assert.assertEquals(beforeCreateDocumentsCount + noOfDocuments, documents.size()); }

Target:
public void testQueryIterableCrud() throws DocumentClientException { DocumentClient client = new DocumentClient(HOST, MASTER_KEY, ConnectionPolicy.GetDefault(), ConsistencyLevel.Session); List<Document> documents = client.readDocuments(this.collectionForTest.getSelfLink(), null).getQueryIterable().toList(); int beforeCreateDocumentsCount = documents.size(); final int numOfDocuments = 10; for (int i = 0; i < numOfDocuments; ++i) { Document documentDefinition = new Document("{ 'name': 'For paging test' }"); client.createDocument(this.collectionForTest.getSelfLink(), documentDefinition, null, false); } int noOfDocumentsPerPage = numOfDocuments / 5; FeedOptions fo = new FeedOptions(); fo.setPageSize(noOfDocumentsPerPage); FeedResponse<Document> feedResponse; int i = 0; String continuationToken = null; List<String> currentPage = new ArrayList<String>(); List<String> previousPage = new ArrayList<String>(); do { currentPage.clear(); fo.setRequestContinuation(continuationToken); feedResponse = client.readDocuments(this.collectionForTest.getSelfLink(), fo); i = 0; for (Document document : feedResponse.getQueryIterable()) { i++; currentPage.add(document.getId()); if (i == noOfDocumentsPerPage) { break; } } continuationToken = feedResponse.getResponseContinuation(); for (String idFromCurrentPage : currentPage) { if (previousPage.contains(idFromCurrentPage)) { Assert.fail("Both pages contain same id " + idFromCurrentPage); } } previousPage.clear(); previousPage.addAll(currentPage); try { Thread.sleep(1000); } catch (InterruptedException e) { } } while (continuationToken != null); documents = client.readDocuments(this.collectionForTest.getSelfLink(), null).getQueryIterable().toList(); Assert.assertEquals(beforeCreateDocumentsCount + numOfDocuments, documents.size()); }