smengcl commented on code in PR #10774:
URL: https://github.com/apache/ozone/pull/10774#discussion_r3708669578


##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/snapshot/defrag/TestSnapshotDefragService.java:
##########
@@ -1108,6 +1108,69 @@ public void testCheckAndDefragSnapshotFailure(boolean 
previousSnapshotExists) th
     }
   }
 
+  @ParameterizedTest
+  @ValueSource(booleans = {true, false})
+  public void testCheckpointCleanupOnDefragFailure(boolean 
previousSnapshotExists) throws IOException {
+    SnapshotInfo snapshotInfo = createMockSnapshotInfo(UUID.randomUUID(), 
"vol1", "bucket1", "snap2");
+    SnapshotInfo previousSnapshotInfo;
+    if (previousSnapshotExists) {
+      previousSnapshotInfo = createMockSnapshotInfo(UUID.randomUUID(), "vol1", 
"bucket1", "snap1");
+      
snapshotInfo.setPathPreviousSnapshotId(previousSnapshotInfo.getSnapshotId());
+    } else {
+      previousSnapshotInfo = null;
+    }
+
+    SnapshotChainManager chainManager = mock(SnapshotChainManager.class);
+    try (MockedStatic<SnapshotUtils> mockedStatic = 
Mockito.mockStatic(SnapshotUtils.class)) {
+      mockedStatic.when(() -> SnapshotUtils.getSnapshotInfo(eq(ozoneManager), 
eq(chainManager),
+          eq(snapshotInfo.getSnapshotId()))).thenReturn(snapshotInfo);
+      if (previousSnapshotExists) {
+        mockedStatic.when(() -> 
SnapshotUtils.getSnapshotInfo(eq(ozoneManager), eq(chainManager),
+            
eq(previousSnapshotInfo.getSnapshotId()))).thenReturn(previousSnapshotInfo);
+      }
+
+      SnapshotDefragService spyDefragService = Mockito.spy(defragService);
+      doReturn(Pair.of(true, 
10)).when(spyDefragService).needsDefragmentation(eq(snapshotInfo));
+
+      @SuppressWarnings("resource") // Mock object, no actual resource 
management needed
+      OmMetadataManagerImpl checkpointMetadataManager = 
mock(OmMetadataManagerImpl.class);
+      File checkpointPath = tempDir.resolve("checkpoint_" + 
System.nanoTime()).toAbsolutePath().toFile();
+      // Create actual checkpoint directory to verify cleanup
+      assertTrue(checkpointPath.mkdirs(), "Failed to create checkpoint 
directory for test");
+      assertTrue(checkpointPath.exists(), "Checkpoint directory should exist 
before defragmentation");
+
+      DBStore checkpointDBStore = mock(DBStore.class);
+      when(checkpointMetadataManager.getStore()).thenReturn(checkpointDBStore);
+      when(checkpointDBStore.getDbLocation()).thenReturn(checkpointPath);
+      doNothing().when(checkpointMetadataManager).close();
+      
doReturn(checkpointMetadataManager).when(spyDefragService).createCheckpoint(any(),
 any());

Review Comment:
   The tests do not cover the two new recovery paths. 
testCheckpointCleanupOnDefragFailure() stubs createCheckpoint(), so it does not 
run the new cleanup in that method. 
testCheckAndDefragAlreadyDefraggedSnapshot() returns version 0, so it does not 
run the deletion retry. Please add a test for a failure after checkpoint 
creation and one test that verifies deletion is retried for an already 
defragmented snapshot.



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