sumitagrawl commented on code in PR #4021:
URL: https://github.com/apache/ozone/pull/4021#discussion_r1051884461


##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/key/TestOMDirectoriesPurgeRequestAndResponse.java:
##########
@@ -225,4 +225,73 @@ public void testValidateAndUpdateCacheCheckQuota() throws 
Exception {
           deletedKey));
     }
   }
+
+  @Test
+  public void testValidateAndUpdateCacheQuotaBucketRecreated()
+      throws Exception {
+    // Create and Delete keys. The keys should be moved to DeletedKeys table
+    List<OmKeyInfo> deletedKeyInfos = createAndDeleteKeys(1, null);
+    // The keys should be present in the DeletedKeys table before purging
+    List<String> deletedKeyNames = new ArrayList<>();
+    for (OmKeyInfo deletedKey : deletedKeyInfos) {
+      String keyName = 
omMetadataManager.getOzoneKey(deletedKey.getVolumeName(),
+          deletedKey.getBucketName(), deletedKey.getKeyName());
+      Assert.assertTrue(omMetadataManager.getDeletedTable().isExist(
+          keyName));
+      deletedKeyNames.add(keyName);
+    }
+
+
+    // Create PurgeKeysRequest to purge the deleted keys
+    String bucketKey = omMetadataManager.getBucketKey(volumeName, bucketName);
+    OmBucketInfo omBucketInfo = omMetadataManager.getBucketTable().get(
+        bucketKey);
+    OMRequest omRequest = createPurgeKeysRequest(
+        null, deletedKeyInfos, omBucketInfo);
+    OMRequest preExecutedRequest = preExecute(omRequest);
+    OMDirectoriesPurgeRequestWithFSO omKeyPurgeRequest =
+        new OMDirectoriesPurgeRequestWithFSO(preExecutedRequest);
+
+    // recreate bucket
+    omMetadataManager.getBucketTable().delete(bucketKey);
+    OMRequestTestUtils.addBucketToDB(volumeName, bucketName,
+        omMetadataManager);
+    omBucketInfo = omMetadataManager.getBucketTable().get(
+        bucketKey);
+    omBucketInfo.incrUsedBytes(1000);
+    omBucketInfo.incrUsedNamespace(100L);
+    omMetadataManager.getBucketTable().addCacheEntry(new CacheKey<>(bucketKey),
+        new CacheValue<>(Optional.of(omBucketInfo), 1L));
+    omMetadataManager.getBucketTable().put(bucketKey, omBucketInfo);
+
+    // prevalidate bucket
+    omBucketInfo = omMetadataManager.getBucketTable().get(bucketKey);
+    Assert.assertEquals(1000L, omBucketInfo.getUsedBytes());
+    
+    // perform delete
+    OMDirectoriesPurgeResponseWithFSO omClientResponse
+        = (OMDirectoriesPurgeResponseWithFSO) omKeyPurgeRequest
+        .validateAndUpdateCache(ozoneManager, 100L,
+            ozoneManagerDoubleBufferHelper);
+    
+    // validate bucket info, no change expected
+    omBucketInfo = omMetadataManager.getBucketTable().get(
+        bucketKey);
+    Assert.assertEquals(1000L, omBucketInfo.getUsedBytes());
+
+    try (BatchOperation batchOperation =
+             omMetadataManager.getStore().initBatchOperation()) {
+
+      omClientResponse.addToDBBatch(omMetadataManager, batchOperation);
+
+      // Do manual commit and see whether addToBatch is successful or not.
+      omMetadataManager.getStore().commitBatchOperation(batchOperation);
+    }
+

Review Comment:
   Updated... @neils-dev 



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