dengziming commented on a change in pull request #10021: URL: https://github.com/apache/kafka/pull/10021#discussion_r590923649
########## File path: raft/src/test/java/org/apache/kafka/snapshot/SnapshotsTest.java ########## @@ -74,5 +79,44 @@ public void testInvalidSnapshotFilenames() { assertEquals(Optional.empty(), Snapshots.parse(root.resolve("leader-epoch-checkpoint"))); // partition metadata assertEquals(Optional.empty(), Snapshots.parse(root.resolve("partition.metadata"))); + // deleted file + assertEquals(Optional.empty(), Snapshots.parse(root.resolve("00000000000000000000.deleted"))); + } + + @Test + public void testDeleteSnapshot() throws IOException { + + OffsetAndEpoch snapshotId = new OffsetAndEpoch( + TestUtils.RANDOM.nextInt(Integer.MAX_VALUE), + TestUtils.RANDOM.nextInt(Integer.MAX_VALUE) + ); + + Path logDirPath = TestUtils.tempDirectory().toPath(); + try (FileRawSnapshotWriter snapshot = FileRawSnapshotWriter.create(logDirPath, snapshotId, Optional.empty())) { + snapshot.freeze(); + + Path snapshotPath = Snapshots.snapshotPath(logDirPath, snapshotId); + assertTrue(Files.exists(snapshotPath)); + + // delete snapshot directly + assertTrue(Snapshots.deleteSnapshotIfExists(logDirPath, snapshot.snapshotId())); + assertFalse(Files.exists(snapshotPath)); + assertFalse(Files.exists(Snapshots.deleteRename(snapshotPath, snapshotId))); + } + + try (FileRawSnapshotWriter snapshot = FileRawSnapshotWriter.create(logDirPath, snapshotId, Optional.empty())) { + snapshot.freeze(); + + Path snapshotPath = Snapshots.snapshotPath(logDirPath, snapshotId); + assertTrue(Files.exists(snapshotPath)); + + // rename snapshot before deleting + Utils.atomicMoveWithFallback(snapshotPath, Snapshots.deleteRename(snapshotPath, snapshotId)); Review comment: Firstly I didn't understand and now I got it! ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org