From e28570264dc4c3c3ad02bf45f1d609b4aba226bc Mon Sep 17 00:00:00 2001 From: Arun Sarin Date: Thu, 2 Apr 2026 03:36:08 +0530 Subject: [PATCH] HDDS-13661. Fix flaky TestKeyDeletingService#testPurgeKeysRequestBatching --- .../om/service/TestKeyDeletingService.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestKeyDeletingService.java b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestKeyDeletingService.java index 5111710651bd..0ee43d949ff6 100644 --- a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestKeyDeletingService.java +++ b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestKeyDeletingService.java @@ -1166,18 +1166,19 @@ void cleanup() { } private void customizeConfig() { - // Define a small Ratis limit to force multiple batches for testing - // The actual byte size of protobuf messages depends on content. - // A small value like 1KB or 2KB should ensure batching for ~10-20 keys. - final int testRatisLimitBytes = 1024; // 2 KB to encourage multiple batches, 90% of the actualRatisLimitBytes. - // Set the specific Ratis limit for this test + // Define a small Ratis limit to force multiple batches for testing. + // With 50 keys and 1024 bytes limit (90% = ~921 bytes effective), this + // produces ~7 batches, confirming the batching logic works correctly. + final int testRatisLimitBytes = 1024; conf.setStorageSize(OMConfigKeys.OZONE_OM_RATIS_LOG_APPENDER_QUEUE_BYTE_LIMIT, testRatisLimitBytes, StorageUnit.BYTES); + // Use a very large service interval so the background thread never fires + // during the test, preventing concurrent processing with runPeriodicalTaskNow(). + conf.setTimeDuration(OZONE_BLOCK_DELETING_SERVICE_INTERVAL, 1, TimeUnit.DAYS); } @Test @DisplayName("Verify PurgeKeysRequest is batched according to Ratis byte limit") - @Flaky("HDDS-13661") void testPurgeKeysRequestBatching() throws Exception { keyDeletingService.suspend(); @@ -1191,20 +1192,19 @@ void testPurgeKeysRequestBatching() throws Exception { // Mock submitRequest to capture requests and return success mockedRatisUtils.when(() -> OzoneManagerRatisUtils.submitRequest( any(OzoneManager.class), - requestCaptor.capture(), // Capture the OMRequest here + requestCaptor.capture(), any(), anyLong())) - .thenAnswer(invocation -> { - // Return a successful OMResponse for each captured request - return OzoneManagerProtocolProtos.OMResponse.newBuilder() - .setCmdType(OzoneManagerProtocolProtos.Type.PurgeKeys) - .setStatus(OzoneManagerProtocolProtos.Status.OK) - .build(); - }); + .thenAnswer(invocation -> OzoneManagerProtocolProtos.OMResponse.newBuilder() + .setCmdType(OzoneManagerProtocolProtos.Type.PurgeKeys) + .setStatus(OzoneManagerProtocolProtos.Status.OK) + .build()); - final int numKeysToCreate = 50; // Create enough keys to ensure multiple batches - // Create and delete keys using the test-specific managers + final int numKeysToCreate = 50; createAndDeleteKeys(numKeysToCreate, 1); + // Wait for all delete operations to be flushed from the DoubleBuffer to + // RocksDB, so that getPendingDeletionKeys() can see all 50 entries. + om.awaitDoubleBufferFlush(); keyDeletingService.resume();