From da788b18fd18e6f80e0f0098618d9520e0b8a6a1 Mon Sep 17 00:00:00 2001 From: David Griffin Date: Fri, 20 Sep 2024 15:54:18 -0700 Subject: [PATCH] Add test_multiple_pages_async. --- .../java/com/fauna/client/PageIteratorTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/test/java/com/fauna/client/PageIteratorTest.java b/src/test/java/com/fauna/client/PageIteratorTest.java index 48b29a7a..d98fe619 100644 --- a/src/test/java/com/fauna/client/PageIteratorTest.java +++ b/src/test/java/com/fauna/client/PageIteratorTest.java @@ -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; @@ -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 pageIterator = new PageIterator<>(client, fql("hello"), String.class, null); + + boolean hasNext = pageIterator.hasNext(); + List 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());