deniskuzZ commented on code in PR #14236:
URL: https://github.com/apache/iceberg/pull/14236#discussion_r2407678863


##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveCommits.java:
##########
@@ -504,6 +506,120 @@ public void testChangeLockWithAlterTable() throws 
Exception {
         .hasSameClassAs(initialLock);
   }
 
+  @Test
+  public void testCreateTableWithNoLockEndToEnd() {
+    testCreateTableEndToEnd(false);
+  }
+
+  @Test
+  public void testCreateTableWithLockEndToEnd() {
+    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="
+                  + lockEnabled
+                  + " should use "
+                  + expectedLockClass.getSimpleName()
+                  + ")")
+          .isInstanceOf(expectedLockClass);
+    } finally {
+      catalog.dropTable(newTableIdentifier, true);
+    }
+  }
+
+  @Test
+  public void testCreateTableWithNoLock() {

Review Comment:
   Should we move the E2E tests to TestHiveTable?



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