This is an automated email from the ASF dual-hosted git repository.

lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new 0e400e68dd [test] Add more tests for 
RESTCatalogTest.testSnapshotMethods
0e400e68dd is described below

commit 0e400e68ddbc775c9acfaf80008cd3bc3bd9ffe3
Author: JingsongLi <[email protected]>
AuthorDate: Tue May 27 11:41:32 2025 +0800

    [test] Add more tests for RESTCatalogTest.testSnapshotMethods
---
 .../src/main/java/org/apache/paimon/PagedList.java | 22 +++++++++++++
 .../org/apache/paimon/rest/RESTCatalogTest.java    | 37 ++++++++++++++++++++--
 2 files changed, 56 insertions(+), 3 deletions(-)

diff --git a/paimon-api/src/main/java/org/apache/paimon/PagedList.java 
b/paimon-api/src/main/java/org/apache/paimon/PagedList.java
index eb2d8cc8d0..23cc8f78f3 100644
--- a/paimon-api/src/main/java/org/apache/paimon/PagedList.java
+++ b/paimon-api/src/main/java/org/apache/paimon/PagedList.java
@@ -18,9 +18,13 @@
 
 package org.apache.paimon;
 
+import org.apache.paimon.utils.StringUtils;
+
 import javax.annotation.Nullable;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.function.Function;
 
 /**
  * Paged List which supports request data from page streaming.
@@ -48,4 +52,22 @@ public class PagedList<T> {
     public String getNextPageToken() {
         return this.nextPageToken;
     }
+
+    /** Util method to list all from paged api. */
+    public static <T> List<T> listAllFromPagedApi(Function<String, 
PagedList<T>> pagedApi) {
+        List<T> results = new ArrayList<>();
+        String pageToken = null;
+        do {
+            PagedList<T> response = pagedApi.apply(pageToken);
+            pageToken = response.getNextPageToken();
+            List<T> elements = response.getElements();
+            if (elements != null) {
+                results.addAll(elements);
+            }
+            if (pageToken == null || elements == null || elements.isEmpty()) {
+                break;
+            }
+        } while (StringUtils.isNotEmpty(pageToken));
+        return results;
+    }
 }
diff --git 
a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java 
b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java
index 44f8a3a63e..9950013486 100644
--- a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java
+++ b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java
@@ -1701,9 +1701,9 @@ public abstract class RESTCatalogTest extends 
CatalogTestBase {
                 true);
         Table table = catalog.getTable(identifier);
         batchWrite(table, singletonList(1));
-        batchWrite(table, singletonList(2));
-        batchWrite(table, singletonList(3));
-        batchWrite(table, singletonList(4));
+        batchWrite(table, singletonList(1));
+        batchWrite(table, singletonList(1));
+        batchWrite(table, singletonList(1));
 
         assertThat(catalog.listSnapshotsPaged(identifier, null, 
null).getElements())
                 .containsExactlyInAnyOrder(
@@ -1713,11 +1713,17 @@ public abstract class RESTCatalogTest extends 
CatalogTestBase {
                 .isPresent()
                 .get()
                 .isEqualTo(table.snapshot(3));
+
         assertThat(catalog.loadSnapshot(identifier, "EARLIEST"))
                 .isPresent()
                 .get()
                 .isEqualTo(table.snapshot(1));
 
+        assertThat(catalog.loadSnapshot(identifier, "LATEST"))
+                .isPresent()
+                .get()
+                .isEqualTo(table.snapshot(4));
+
         table.createTag("MY_TAG", 2);
         assertThat(catalog.loadSnapshot(identifier, "MY_TAG"))
                 .isPresent()
@@ -1725,6 +1731,31 @@ public abstract class RESTCatalogTest extends 
CatalogTestBase {
                 .isEqualTo(table.snapshot(2));
 
         assertThat(catalog.loadSnapshot(identifier, "15")).isEmpty();
+
+        // test more snapshots
+        for (int i = 0; i < 10; i++) {
+            batchWrite(table, singletonList(1));
+        }
+        RESTApi api = ((RESTCatalog) catalog).api();
+        List<Snapshot> snapshots =
+                PagedList.listAllFromPagedApi(
+                        token -> api.listSnapshotsPaged(identifier, null, 
token));
+        assertThat(snapshots)
+                .containsExactlyInAnyOrder(
+                        table.snapshot(1),
+                        table.snapshot(2),
+                        table.snapshot(3),
+                        table.snapshot(4),
+                        table.snapshot(5),
+                        table.snapshot(6),
+                        table.snapshot(7),
+                        table.snapshot(8),
+                        table.snapshot(9),
+                        table.snapshot(10),
+                        table.snapshot(11),
+                        table.snapshot(12),
+                        table.snapshot(13),
+                        table.snapshot(14));
     }
 
     private TestPagedResponse generateTestPagedResponse(

Reply via email to