deniskuzZ commented on code in PR #6750: URL: https://github.com/apache/hive/pull/6750#discussion_r4103429069
########## standalone-metastore/metastore-rest-catalog/src/test/java/org/apache/iceberg/rest/TestHMSCatalogAdapterPagination.java: ########## @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.iceberg.rest; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import org.apache.iceberg.catalog.Catalog; +import org.apache.iceberg.catalog.Namespace; +import org.apache.iceberg.catalog.SupportsNamespaces; +import org.apache.iceberg.catalog.ViewCatalog; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; +import org.apache.iceberg.rest.responses.ListNamespacesResponse; +import org.apache.iceberg.rest.HTTPRequest.HTTPMethod; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import javax.servlet.http.HttpServletResponse; + +public class TestHMSCatalogAdapterPagination { + + @Test + public void testPaginationDelegation() throws Exception { + Catalog catalog = + Mockito.mock( + Catalog.class, + Mockito.withSettings().extraInterfaces(SupportsNamespaces.class, ViewCatalog.class)); + SupportsNamespaces nsCatalog = (SupportsNamespaces) catalog; + List<Namespace> fakeNamespaces = + Arrays.asList( + Namespace.of("db1"), + Namespace.of("db2"), + Namespace.of("db3"), + Namespace.of("db4"), + Namespace.of("db5")); + Mockito.when(nsCatalog.listNamespaces()).thenReturn(fakeNamespaces); + Mockito.when(nsCatalog.listNamespaces(Mockito.any())).thenReturn(fakeNamespaces); + + ListNamespacesResponse res3; + try (HMSCatalogAdapter adapter = + new HMSCatalogAdapter("test", catalog, null, Collections.emptyList())) { + + HttpServletResponse response = Mockito.mock(HttpServletResponse.class); + StringWriter stringWriter = new StringWriter(); + Mockito.when(response.getWriter()).thenReturn(new PrintWriter(stringWriter)); + + // 1. Missing pageSize (should call unpaginated and succeed without NumberFormatException) + Map<String, String> vars1 = ImmutableMap.of("pageToken", "0"); + ListNamespacesResponse res1 = + adapter.execute(HTTPMethod.GET, "v1/namespaces", vars1, null, response); + if (res1 == null) { + System.err.println("Error output: " + stringWriter); + } + Assertions.assertNotNull(res1, "Response should not be null"); + Assertions.assertEquals(5, res1.namespaces().size(), "Should return all 5 unpaginated"); + + // 2. Both pageToken and pageSize (should call paginated and slice without errors) Review Comment: as in prev PRs, please split into individual test-cases -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
