priyeshkaratha commented on code in PR #9635:
URL: https://github.com/apache/ozone/pull/9635#discussion_r2720129071
##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestKeyDeletingService.java:
##########
@@ -246,6 +248,60 @@ void checkIfDeleteServiceIsDeletingKeys()
}
}
+ /**
+ * Test that verifies zero-sized keys (keys with no blocks) are not sent
to SCM.
+ * The KeyDeletingService should filter out empty keys before calling SCM.
+ */
+ @Test
+ void checkIfDeleteServiceIsDeletingZeroSizedKeys()
+ throws IOException, TimeoutException, InterruptedException {
+ // Spy on the SCM client to verify it's not called for empty keys
+ ScmBlockLocationTestingClient scmClientSpy =
Mockito.spy(scmBlockTestingClient);
+ // Create a KeyDeletingService with the spied client
+ KeyDeletingService testService = new KeyDeletingService(
+ om, scmClientSpy, 100, 10000, conf, 10, false);
+ // Create a BlockGroup with empty deleted blocks list (zero-sized key)
+ BlockGroup blockGroup = BlockGroup.newBuilder().setKeyName("key1/1")
+ .addAllDeletedBlocks(new ArrayList<>()).build();
+ Map<String, PurgedKey> blockGroups = Collections.singletonMap(
+ blockGroup.getGroupID(),
+ new PurgedKey("vol", "buck", 1, blockGroup, "key1", 0, true));
+ // Process the key deletion
+ testService.processKeyDeletes(blockGroups, new HashMap<>(), new
ArrayList<>(), null, null);
+ // Verify that SCM's deleteKeyBlocks was never called (empty keys are
filtered out)
+ verify(scmClientSpy, never()).deleteKeyBlocks(any());
+ // Cleanup
+ testService.shutdown();
+ }
+
+ @Test
+ void checkIfDeleteServiceIsDeletingMixedSizedKeys()
+ throws IOException, TimeoutException, InterruptedException {
+ // Spy on the SCM client to verify it's not called for empty keys
+ ScmBlockLocationTestingClient scmClientSpy =
Mockito.spy(scmBlockTestingClient);
+ // Create a KeyDeletingService with the spied client
+ KeyDeletingService testService = new KeyDeletingService(
+ om, scmClientSpy, 100, 10000, conf, 10, false);
+ // Create a BlockGroup with empty deleted blocks list (zero-sized key)
+ BlockGroup blockGroup1 = BlockGroup.newBuilder().setKeyName("key1/1")
+ .addAllDeletedBlocks(new ArrayList<>()).build();
+ //Create a BlockGroup with non-empty deleted blocks
+ List<DeletedBlock> deletedBlocks = Collections.singletonList(new
DeletedBlock(new BlockID(1, 1), 1, 3));
+ BlockGroup blockGroup2 = BlockGroup.newBuilder().setKeyName("key2/2")
+ .addAllDeletedBlocks(deletedBlocks).build();
+ Map<String, PurgedKey> blockGroups = new HashMap<>();
+
+ blockGroups.put(blockGroup1.getGroupID(), new PurgedKey("vol", "buck",
1, blockGroup1, "key1", 0, true));
+ blockGroups.put(blockGroup2.getGroupID(), new PurgedKey("vol", "buck",
1, blockGroup2, "key2", 0, true));
+
+ // Process the key deletion
+ testService.processKeyDeletes(blockGroups, new HashMap<>(), new
ArrayList<>(), null, null);
+ // Verify that SCM's deleteKeyBlocks was never called (empty keys are
filtered out)
Review Comment:
Addressed in latest commit
--
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]