s-sanjay commented on code in PR #14236:
URL: https://github.com/apache/iceberg/pull/14236#discussion_r2432539415


##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveTable.java:
##########
@@ -119,6 +127,66 @@ public void testCreate() throws TException {
     assertThat(icebergTable.schema().asStruct()).isEqualTo(SCHEMA.asStruct());
   }
 
+  @Test
+  public void testCreateTableWithNoLock() {
+    testCreateTableEndToEnd(false);
+  }
+
+  @Test
+  public void testCreateTableWithLock() {
+    testCreateTableEndToEnd(true);
+  }
+
+  private void testCreateTableEndToEnd(boolean lockEnabled) {
+    String tableName = lockEnabled ? "new_table_lock_e2e" : 
"new_table_no_lock_e2e";
+    TableIdentifier newTableIdentifier = TableIdentifier.of(DB_NAME, 
tableName);
+
+    try {
+      // Create table with lock setting via catalog
+      // We will spy the call to create table operation and capture the lock 
object being returned
+      HiveCatalog spyCatalog = spy(catalog);
+      AtomicReference<HiveLock> lockRef = new AtomicReference<>();
+      doAnswer(
+              (args) -> {
+                TableOperations ops =
+                    catalog.newTableOps(args.getArgument(0, 
TableIdentifier.class));
+                HiveTableOperations spyOps = (HiveTableOperations) spy(ops);
+                doAnswer(
+                        (lockArgs) -> {
+                          lockRef.set(
+                              ((HiveTableOperations) ops)
+                                  .lockObject(lockArgs.getArgument(0, 
TableMetadata.class)));
+                          return lockRef.get();
+                        })
+                    .when(spyOps)
+                    .lockObject(any());
+                return spyOps;
+              })
+          .when(spyCatalog)
+          .newTableOps(newTableIdentifier);
+
+      spyCatalog.createTable(
+          newTableIdentifier,
+          SCHEMA,
+          PartitionSpec.unpartitioned(),
+          ImmutableMap.of(HIVE_LOCK_ENABLED, String.valueOf(lockEnabled)));
+
+      Class<? extends HiveLock> expectedLockClass =
+          lockEnabled ? MetastoreLock.class : NoLock.class;
+      assertThat(lockRef).as("Lock not captured by the 
stub").doesNotHaveNullValue();
+      assertThat(lockRef.get())
+          .as(
+              "Table created with HIVE_LOCK_ENABLED="

Review Comment:
   Done



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

Reply via email to