rdblue commented on a change in pull request #1633:
URL: https://github.com/apache/iceberg/pull/1633#discussion_r513635486



##########
File path: aws/src/test/java/org/apache/iceberg/aws/glue/TestGlueCatalog.java
##########
@@ -0,0 +1,260 @@
+/*
+ * 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.aws.glue;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.iceberg.BaseMetastoreTableOperations;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.exceptions.NamespaceNotEmptyException;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.apache.iceberg.relocated.com.google.common.collect.Lists;
+import org.apache.iceberg.relocated.com.google.common.collect.Sets;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import software.amazon.awssdk.services.glue.GlueClient;
+import software.amazon.awssdk.services.glue.model.CreateDatabaseRequest;
+import software.amazon.awssdk.services.glue.model.CreateDatabaseResponse;
+import software.amazon.awssdk.services.glue.model.CreateTableRequest;
+import software.amazon.awssdk.services.glue.model.CreateTableResponse;
+import software.amazon.awssdk.services.glue.model.Database;
+import software.amazon.awssdk.services.glue.model.DeleteDatabaseRequest;
+import software.amazon.awssdk.services.glue.model.DeleteDatabaseResponse;
+import software.amazon.awssdk.services.glue.model.DeleteTableRequest;
+import software.amazon.awssdk.services.glue.model.DeleteTableResponse;
+import software.amazon.awssdk.services.glue.model.GetDatabaseRequest;
+import software.amazon.awssdk.services.glue.model.GetDatabaseResponse;
+import software.amazon.awssdk.services.glue.model.GetDatabasesRequest;
+import software.amazon.awssdk.services.glue.model.GetDatabasesResponse;
+import software.amazon.awssdk.services.glue.model.GetTableRequest;
+import software.amazon.awssdk.services.glue.model.GetTableResponse;
+import software.amazon.awssdk.services.glue.model.GetTablesRequest;
+import software.amazon.awssdk.services.glue.model.GetTablesResponse;
+import software.amazon.awssdk.services.glue.model.Table;
+import software.amazon.awssdk.services.glue.model.UpdateDatabaseRequest;
+import software.amazon.awssdk.services.glue.model.UpdateDatabaseResponse;
+
+public class TestGlueCatalog {
+
+  private static final String WAREHOUSE_PATH = "s3a://bucket";
+  private GlueClient glue;
+  private GlueCatalog glueCatalog;
+
+  @Before
+  public void before() {
+    glue = Mockito.mock(GlueClient.class);
+    glueCatalog = new GlueCatalog(new Configuration(), glue, null, 
WAREHOUSE_PATH, false);
+  }
+
+  @Test
+  public void defaultWarehouseLocation_noDbUri() {
+    Mockito.doReturn(GetDatabaseResponse.builder()
+        .database(Database.builder().name("db").build()).build())
+        .when(glue).getDatabase(Mockito.any(GetDatabaseRequest.class));
+    String location = 
glueCatalog.defaultWarehouseLocation(TableIdentifier.of("db", "table"));
+    Assert.assertEquals(WAREHOUSE_PATH + "/db.db/table", location);
+  }
+
+  @Test
+  public void defaultWarehouseLocation_dbUri() {
+    Mockito.doReturn(GetDatabaseResponse.builder()
+        
.database(Database.builder().name("db").locationUri("s3://bucket2/db").build()).build())
+        .when(glue).getDatabase(Mockito.any(GetDatabaseRequest.class));
+    String location = 
glueCatalog.defaultWarehouseLocation(TableIdentifier.of("db", "table"));
+    Assert.assertEquals("s3://bucket2/db/table", location);
+  }
+
+  @Test
+  public void listTables() {
+    Mockito.doReturn(GetDatabaseResponse.builder()
+        .database(Database.builder().name("db1").build()).build())
+        .when(glue).getDatabase(Mockito.any(GetDatabaseRequest.class));
+    Mockito.doReturn(GetTablesResponse.builder()
+        .tableList(
+            Table.builder().databaseName("db1").name("t1").build(),
+            Table.builder().databaseName("db1").name("t2").build()
+        ).build())
+        .when(glue).getTables(Mockito.any(GetTablesRequest.class));
+    Assert.assertEquals(
+        Lists.newArrayList(
+            TableIdentifier.of("db1", "t1"),
+            TableIdentifier.of("db1", "t2")
+        ),
+        glueCatalog.listTables(Namespace.of("db1"))
+    );
+  }
+
+  @Test
+  public void dropTable() {
+    Map<String, String> properties = new HashMap<>();
+    properties.put(BaseMetastoreTableOperations.TABLE_TYPE_PROP,
+        BaseMetastoreTableOperations.ICEBERG_TABLE_TYPE_VALUE);
+    Mockito.doReturn(GetTableResponse.builder()
+        
.table(Table.builder().databaseName("db1").name("t1").parameters(properties).build()).build())
+        .when(glue).getTable(Mockito.any(GetTableRequest.class));
+    Mockito.doReturn(GetDatabaseResponse.builder()
+        .database(Database.builder().name("db1").build()).build())
+        .when(glue).getDatabase(Mockito.any(GetDatabaseRequest.class));
+    Mockito.doReturn(DeleteTableResponse.builder().build())
+        .when(glue).deleteTable(Mockito.any(DeleteTableRequest.class));
+    glueCatalog.dropTable(TableIdentifier.of("db1", "t1"));

Review comment:
       This doesn't appear to verify that any of the above calls actually 
happened. Mock tests should validate that the expected RPC calls were actually 
made.




----------------------------------------------------------------
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.

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