smaheshwar-pltr commented on code in PR #16796:
URL: https://github.com/apache/iceberg/pull/16796#discussion_r3591584451


##########
core/src/test/java/org/apache/iceberg/TestCatalogUtil.java:
##########
@@ -320,6 +325,76 @@ public void noFailureWhenBulkDeletingMetadataFiles() {
         .doesNotThrowAnyException();
   }
 
+  @Test
+  public void deletesSupersededMetadataFileWhenPreviousVersionsMaxIsZero() {
+    FileIO io = mock(FileIO.class);
+
+    TableMetadata.MetadataLogEntry entry1 =
+        new TableMetadata.MetadataLogEntry(
+            System.currentTimeMillis(), "s3://bucket/metadata/v1.json");
+
+    TableMetadata base = mock(TableMetadata.class);
+    TableMetadata metadata = mock(TableMetadata.class);
+
+    when(metadata.propertyAsBoolean(
+            eq(TableProperties.METADATA_DELETE_AFTER_COMMIT_ENABLED), 
anyBoolean()))
+        .thenReturn(true);
+    when(base.previousFiles()).thenReturn(ImmutableList.of(entry1));
+    
when(base.metadataFileLocation()).thenReturn("s3://bucket/metadata/v2.json");
+    when(metadata.previousFiles()).thenReturn(ImmutableList.of());
+
+    CatalogUtil.deleteRemovedMetadataFiles(io, base, metadata);
+
+    ArgumentCaptor<String> deleted = ArgumentCaptor.forClass(String.class);
+    verify(io, times(2)).deleteFile(deleted.capture());
+    assertThat(deleted.getAllValues())
+        .containsExactlyInAnyOrder("s3://bucket/metadata/v1.json", 
"s3://bucket/metadata/v2.json");
+  }
+
+  @Test
+  public void keepsSupersededMetadataFileWhenStillTracked() {
+    FileIO io = mock(FileIO.class);
+
+    TableMetadata.MetadataLogEntry entry1 =
+        new TableMetadata.MetadataLogEntry(
+            System.currentTimeMillis(), "s3://bucket/metadata/v1.json");
+    TableMetadata.MetadataLogEntry entry2 =
+        new TableMetadata.MetadataLogEntry(
+            System.currentTimeMillis(), "s3://bucket/metadata/v2.json");
+
+    TableMetadata base = mock(TableMetadata.class);
+    TableMetadata metadata = mock(TableMetadata.class);
+
+    when(metadata.propertyAsBoolean(
+            eq(TableProperties.METADATA_DELETE_AFTER_COMMIT_ENABLED), 
anyBoolean()))
+        .thenReturn(true);
+    when(base.previousFiles()).thenReturn(ImmutableList.of(entry1));
+    
when(base.metadataFileLocation()).thenReturn("s3://bucket/metadata/v2.json");

Review Comment:
   Good point on dropping the stub, done! This class uses plain `mock()` 
throughout though which is lenient FWIW



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