difin commented on code in PR #5995: URL: https://github.com/apache/hive/pull/5995#discussion_r2277845374
########## iceberg/iceberg-catalog/src/test/java/org/apache/iceberg/hive/client/TestHiveRESTCatalogClient.java: ########## @@ -0,0 +1,185 @@ +/* + * 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.hive.client; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.Map; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.metastore.api.Database; +import org.apache.hadoop.hive.metastore.api.MetaException; +import org.apache.hadoop.hive.metastore.api.StorageDescriptor; +import org.apache.hadoop.hive.metastore.api.Table; +import org.apache.iceberg.BaseTable; +import org.apache.iceberg.CatalogUtil; +import org.apache.iceberg.PartitionSpec; +import org.apache.iceberg.Schema; +import org.apache.iceberg.SortOrder; +import org.apache.iceberg.TableMetadata; +import org.apache.iceberg.TableOperations; +import org.apache.iceberg.Transaction; +import org.apache.iceberg.catalog.Catalog; +import org.apache.iceberg.catalog.Namespace; +import org.apache.iceberg.catalog.TableIdentifier; +import org.apache.iceberg.io.FileIO; +import org.apache.iceberg.io.LocationProvider; +import org.apache.iceberg.relocated.com.google.common.collect.Maps; +import org.apache.iceberg.rest.RESTCatalog; +import org.apache.thrift.TException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.mockito.MockedStatic; +import org.mockito.Mockito; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; + +public class TestHiveRESTCatalogClient { + + static HiveRESTCatalogClient hiveRESTCatalogClient; + static RESTCatalog restCatalog; + private static MockedStatic<CatalogUtil> catalogUtilMockedStatic; + + @BeforeAll + public static void before() throws MetaException { + Configuration configuration = new Configuration(); + configuration.set("iceberg.catalog.type", "rest"); + configuration.set("iceberg.rest-catalog.uri", "http://localhost"); + catalogUtilMockedStatic = Mockito.mockStatic(CatalogUtil.class); + restCatalog = Mockito.mock(RESTCatalog.class); + catalogUtilMockedStatic.when(() -> CatalogUtil.buildIcebergCatalog(any(), any(), any())).thenReturn(restCatalog); + hiveRESTCatalogClient = Mockito.spy(new HiveRESTCatalogClient(configuration)); + hiveRESTCatalogClient.reconnect(); + TableOperations ops = new TableOperations() { + @Override + public TableMetadata current() { + return TableMetadata.newTableMetadata(new Schema(), PartitionSpec.unpartitioned(), "location", + Maps.newHashMap()); + } + + @Override + public TableMetadata refresh() { + return null; + } + + @Override + public void commit(TableMetadata base, TableMetadata metadata) { + + } + + @Override + public FileIO io() { + return null; + } + + @Override + public String metadataFileLocation(String fileName) { + return null; + } + + @Override + public LocationProvider locationProvider() { + return null; + } + }; + Mockito.doReturn(new BaseTable(ops, "tableName")).when(restCatalog).loadTable(any()); + Namespace namespace = Namespace.of("default"); + Mockito.doReturn(Arrays.asList(namespace)).when(restCatalog).listNamespaces(any()); + Mockito.doReturn(new BaseTable(ops, "tableName")).when(restCatalog).createTable(any(), any(), any(), any()); + Mockito.doReturn(tableBuilder).when(restCatalog).buildTable(any(), any()); + } + static Catalog.TableBuilder tableBuilder = new Catalog.TableBuilder() { + @Override + public Catalog.TableBuilder withPartitionSpec(PartitionSpec spec) { + return this; + } + + @Override + public Catalog.TableBuilder withSortOrder(SortOrder sortOrder) { + return this; + } + + @Override + public Catalog.TableBuilder withLocation(String location) { + return this; + } + + @Override + public Catalog.TableBuilder withProperties(Map<String, String> properties) { + return this; + } + + @Override + public Catalog.TableBuilder withProperty(String key, String value) { + return this; + } + + @Override + public org.apache.iceberg.Table create() { + return null; + } + + @Override + public Transaction createTransaction() { + return null; + } + + @Override + public Transaction replaceTransaction() { + return null; + } + + @Override + public Transaction createOrReplaceTransaction() { + return null; + } + }; + + @AfterEach + public void after() { + + } + + @Test + public void testGetTable() throws TException { + hiveRESTCatalogClient.getTable("default", "tableName"); + Mockito.verify(restCatalog).loadTable(TableIdentifier.of("default", "tableName")); + } + + @Test + public void testCreateTable() throws TException { Review Comment: Added a test for a partitioned table here (unit test) and also added a test for a partitioned table in the integration test. -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org