rahil-c commented on code in PR #9782:
URL: https://github.com/apache/iceberg/pull/9782#discussion_r1571188458


##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2329,6 +2332,119 @@ public void 
multipleDiffsAgainstMultipleTablesLastFails() {
     assertThat(schema2.columns()).hasSize(1);
   }
 
+  @Test
+  public void testInvalidRestPageSize() {
+    RESTCatalogAdapter adapter = Mockito.spy(new 
RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) 
-> adapter);
+    Assertions.assertThatThrownBy(
+            () ->
+                catalog.initialize(
+                    "test", ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, 
"-1")))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage("Invalid value for pageSize, must be a positive integer");
+  }
+
+  @Test
+  public void testPaginationForListNamespaces() {
+    RESTCatalogAdapter adapter = Mockito.spy(new 
RESTCatalogAdapter(backendCatalog));
+    RESTCatalog catalog =
+        new RESTCatalog(SessionCatalog.SessionContext.createEmpty(), (config) 
-> adapter);
+    catalog.initialize("test", 
ImmutableMap.of(RESTSessionCatalog.REST_PAGE_SIZE, "10"));
+    int numberOfItems = 20;
+    int numberOfInvocations = 2;
+    String namespaceName = "newdb";
+
+    // create several namespaces for listing and verify
+    for (int i = 0; i < numberOfItems; i++) {
+      String nameSpaceName = namespaceName + i;
+      catalog.createNamespace(Namespace.of(nameSpaceName));
+    }
+
+    assertThat(catalog.listNamespaces()).hasSize(numberOfItems);
+
+    Mockito.verify(adapter)
+        .execute(
+            eq(HTTPMethod.GET),
+            eq("v1/config"),
+            any(),
+            any(),
+            eq(ConfigResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfItems))
+        .execute(
+            eq(HTTPMethod.POST),
+            eq("v1/namespaces"),
+            any(),
+            any(),
+            eq(CreateNamespaceResponse.class),
+            any(),
+            any());
+
+    Mockito.verify(adapter, times(numberOfInvocations))
+        .execute(
+            eq(HTTPMethod.GET),
+            eq("v1/namespaces"),
+            any(),

Review Comment:
   will fix this
   
   Update: So when trying to verify the following 
`eq(ImmutableMap.of("pageToken", "", "pageSize", "10)` I  was running into 
issues as the endpoint as the list namespaces is called twice and was hitting a 
`TooManyActualInvocations`.
   
    Once i changed this to `Mockito.verify(adapter, 
times(numberOfInvocations))` im unable to verify the first param request, as it 
hits this last `eq(ImmutableMap.of("pageToken", "10", "pageSize", "10"))`. 
   
   When i changed to the following was able to get the test to pass
   ```
       Mockito.verify(adapter, times(numberOfInvocations))
           .execute(
               eq(HTTPMethod.GET),
               eq("v1/namespaces"),
               eq(ImmutableMap.of("pageToken", "10", "pageSize", "10")),
               any(),
               eq(ListNamespacesResponse.class),
               any(),
               any());
   ```
   
   Ive also tried called mockito.verify in two seperate calls similar to what 
we do in a test like `testCatalogTokenRefresh` but was not able to get this to 
work for similar reasons, either due to `TooManyActualInvocations` or due to 
arguments not expected 
   ```
   Argument(s) are different! Wanted:
   rESTCatalogAdapter.execute(
       GET,
       "v1/namespaces",
       {"pageToken" = "", "pageSize" = "10"},
       <any>,
       class org.apache.iceberg.rest.responses.ListNamespacesResponse,
       <any>,
       <any>
   );
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to