ebyhr commented on code in PR #14236:
URL: https://github.com/apache/iceberg/pull/14236#discussion_r2425352401
##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveCommits.java:
##########
@@ -504,6 +505,60 @@ public void testChangeLockWithAlterTable() throws
Exception {
.hasSameClassAs(initialLock);
}
+ @Test
+ public void testFirstHiveCommitNoLock() {
+ testFirstHivCommitWithLockSetting(false);
+ }
+
+ @Test
+ public void testFirstHivCommitWithLock() {
+ testFirstHivCommitWithLockSetting(true);
+ }
+
+ private void testFirstHivCommitWithLockSetting(boolean lockEnabled) {
+ String tableName = lockEnabled ? "new_table_with_lock" :
"new_table_with_no_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 ? ImmutableMap.of() :
ImmutableMap.of(HIVE_LOCK_ENABLED, "false"));
+ 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 =
+ lockEnabled ? MetastoreLock.class : NoLock.class;
+ assertThat(lockRef).as("Lock not captured by the
stub").doesNotHaveNullValue();
+ assertThat(lockRef.get())
+ .as("Lock mechanism should use metadata (" +
expectedLockClass.getSimpleName() + ")")
Review Comment:
`AbstractObjectAssert#as` accepts a string template. Same for other places.
```suggestion
.as("Lock mechanism should use metadata (%s)",
expectedLockClass.getSimpleName())
```
--
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]