Skip to content

Commit

Permalink
Add test_multiple_pages_async.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Griffin committed Sep 20, 2024
1 parent 65df6a1 commit da788b1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/test/java/com/fauna/client/PageIteratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -96,6 +97,22 @@ public void test_multiple_pages() throws Exception {
assertThrows(NoSuchElementException.class, () -> pageIterator.next());
}

@Test
public void test_multiple_pages_async() throws Exception {
when(client.asyncQuery(any(), any(ParameterizedOf.class), any())).thenReturn(
successFuture(true, 0), successFuture(false, 1));
PageIterator<String> pageIterator = new PageIterator<>(client, fql("hello"), String.class, null);

boolean hasNext = pageIterator.hasNext();
List<String> products = new ArrayList<>();
while (hasNext) {
hasNext = pageIterator.nextAsync().thenApply(page -> {
products.addAll(page.getData());
return pageIterator.hasNext(); }).get();
}
assertEquals(4, products.size());
}

@Test
public void test_error_thrown() throws IOException {
when(client.asyncQuery(any(), any(ParameterizedOf.class), any())).thenReturn(failureFuture());
Expand Down

0 comments on commit da788b1

Please sign in to comment.