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


##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveTable.java:
##########
@@ -119,6 +129,59 @@ public void testCreate() throws TException {
     assertThat(icebergTable.schema().asStruct()).isEqualTo(SCHEMA.asStruct());
   }
 
+  @ParameterizedTest
+  @ValueSource(booleans = {true, false})
+  @NullSource
+  public void testCreateTableEndToEnd(Boolean lockEnabled) {
+    String tableName =
+        Boolean.FALSE.equals(lockEnabled) ? "new_table_no_lock_e2e" : 
"new_table_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(),
+          lockEnabled == null
+              ? ImmutableMap.of()
+              : ImmutableMap.of(HIVE_LOCK_ENABLED, 
String.valueOf(lockEnabled)));
+
+      Class<? extends HiveLock> expectedLockClass =
+          Boolean.FALSE.equals(lockEnabled) ? NoLock.class : 
MetastoreLock.class;
+      assertThat(lockRef).as("Lock not captured by the 
stub").doesNotHaveNullValue();

Review Comment:
   Done !



##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveCommits.java:
##########
@@ -504,6 +508,56 @@ public void testChangeLockWithAlterTable() throws 
Exception {
         .hasSameClassAs(initialLock);
   }
 
+  @ParameterizedTest
+  @ValueSource(booleans = {true, false})
+  @NullSource
+  public void testFirstHiveCommitWithLockSetting(Boolean lockEnabled) {
+    String tableName =
+        Boolean.FALSE.equals(lockEnabled) ? "new_table_with_no_lock" : 
"new_table_with_lock";
+    TableIdentifier newTableIdentifier = TableIdentifier.of(DB_NAME, 
tableName);
+
+    try {
+      HiveTableOperations ops =
+          new HiveTableOperations(
+              catalog.getConf(),
+              catalog.clientPool(),
+              catalog.newTableOps(newTableIdentifier).io(),
+              catalog.name(),
+              newTableIdentifier.namespace().level(0),
+              newTableIdentifier.name());
+
+      AtomicReference<HiveLock> lockRef = new AtomicReference<>();
+      HiveTableOperations spyOps = spy(ops);
+      TableMetadata metadata =
+          TableMetadata.newTableMetadata(
+              SCHEMA,
+              PartitionSpec.unpartitioned(),
+              catalog.defaultWarehouseLocation(newTableIdentifier),
+              lockEnabled == null
+                  ? ImmutableMap.of()
+                  : ImmutableMap.of(HIVE_LOCK_ENABLED, 
String.valueOf(lockEnabled)));
+      doAnswer(
+              i -> {
+                lockRef.set(ops.lockObject(i.getArgument(0)));
+                return lockRef.get();
+              })
+          .when(spyOps)
+          .lockObject(eq(metadata));
+
+      // Commit with base = null (new table creation)
+      spyOps.commit(null, metadata);
+
+      Class<? extends HiveLock> expectedLockClass =
+          Boolean.FALSE.equals(lockEnabled) ? NoLock.class : 
MetastoreLock.class;
+      assertThat(lockRef).as("Lock not captured by the 
stub").doesNotHaveNullValue();

Review Comment:
   Cool, didn't realize we can directly use AtomicReference without `.get` this 
is more clean.. fixed...



##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveTable.java:
##########
@@ -119,6 +129,59 @@ public void testCreate() throws TException {
     assertThat(icebergTable.schema().asStruct()).isEqualTo(SCHEMA.asStruct());
   }
 
+  @ParameterizedTest
+  @ValueSource(booleans = {true, false})
+  @NullSource
+  public void testCreateTableEndToEnd(Boolean lockEnabled) {
+    String tableName =
+        Boolean.FALSE.equals(lockEnabled) ? "new_table_no_lock_e2e" : 
"new_table_lock_e2e";
+    TableIdentifier newTableIdentifier = TableIdentifier.of(DB_NAME, 
tableName);

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