echonesis commented on code in PR #11889:
URL: https://github.com/apache/ozone/pull/11889#discussion_r4440929509


##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/key/TestOMKeyRenameRequestWithFSO.java:
##########
@@ -347,6 +407,23 @@ private OMRequest doPreExecute(OMRequest 
originalOmRequest) throws Exception {
     return modifiedOmRequest;
   }
 
+  private OzoneManagerProtocolProtos.Status renameToBucketRoot(String fromKey) 
throws Exception {
+    OMRequest omRequest = doPreExecute(createRenameKeyRequest(volumeName, 
bucketName, fromKey, ""));
+    return 
getOMKeyRenameRequest(omRequest).validateAndUpdateCache(ozoneManager, 
100L).getOMResponse().getStatus();

Review Comment:
   nit: Could we retain the response and flush a successful rename through a DB 
batch in at least one test? Assertions using `getSkipCache()` would help verify 
that the destination is persisted and the source is removed.



##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/key/TestOMKeyRenameRequestWithFSO.java:
##########
@@ -171,6 +169,68 @@ public void testValidateAndUpdateCacheWithEmptyToKey() 
throws Exception {
     assertEquals(omRequest.getRenameKeyRequest().getToKeyName(), "");
   }
 
+  @Test
+  public void testRenameToBucketRootKeepsFileName() throws Exception {
+    addKeyToTable(fromKeyInfo);
+
+    assertEquals(OzoneManagerProtocolProtos.Status.OK, 
renameToBucketRoot(fromKeyName));
+
+    
assertThat(omMetadataManager.getKeyTable(getBucketLayout()).get(getBucketRootDBKey("fromKey")).getObjectID())
+        .isEqualTo(fromKeyInfo.getObjectID());
+  }
+
+  @Test
+  public void testRenameBucketRootFileToBucketRoot() throws Exception {
+    OmKeyInfo rootFile = addFileToBucketRoot("fromKey");
+
+    assertEquals(OzoneManagerProtocolProtos.Status.OK, 
renameToBucketRoot("fromKey"));
+
+    
assertThat(omMetadataManager.getKeyTable(getBucketLayout()).get(getBucketRootDBKey("fromKey")).getObjectID())
+        .isEqualTo(rootFile.getObjectID());
+  }
+
+  @Test
+  public void testRenameToBucketRootWithExistingFile() throws Exception {
+    addKeyToTable(fromKeyInfo);
+    OmKeyInfo rootFile = addFileToBucketRoot("fromKey");
+
+    assertEquals(OzoneManagerProtocolProtos.Status.KEY_ALREADY_EXISTS, 
renameToBucketRoot(fromKeyName));
+
+    
assertThat(omMetadataManager.getKeyTable(getBucketLayout()).get(getBucketRootDBKey("fromKey")).getObjectID())
+        .isEqualTo(rootFile.getObjectID());
+  }
+
+  @Test
+  public void testRenameToBucketRootWithExistingDirectory() throws Exception {
+    addKeyToTable(fromKeyInfo);
+    OmKeyInfo rootDir = getOmKeyInfo("fromKey")
+        .setParentObjectID(omMetadataManager.getBucketId(volumeName, 
bucketName))
+        .build();
+    OMRequestTestUtils.addDirKeyToDirTable(false, 
OMFileRequest.getDirectoryInfo(rootDir), volumeName, bucketName,
+        txnLogId, omMetadataManager);
+
+    assertEquals(OzoneManagerProtocolProtos.Status.KEY_ALREADY_EXISTS, 
renameToBucketRoot(fromKeyName));
+
+    
assertThat(omMetadataManager.getKeyTable(getBucketLayout()).get(getBucketRootDBKey("fromKey"))).isNull();
+  }
+
+  @Test
+  public void testRenameDirectoryToBucketRootOntoItsParent() throws Exception {
+    // The source directory has the same name as its parent, which sits at the 
bucket root.
+    String parentName = fromKeyParentInfo.getKeyName();
+    OmKeyInfo sameNameChild = getOmKeyInfo(new Path(parentName, 
parentName).toString())
+        .setParentObjectID(fromKeyParentInfo.getObjectID())
+        .build();
+    OMRequestTestUtils.addDirKeyToDirTable(false, 
OMFileRequest.getDirectoryInfo(sameNameChild), volumeName,
+        bucketName, txnLogId, omMetadataManager);
+
+    assertEquals(OzoneManagerProtocolProtos.Status.KEY_ALREADY_EXISTS,

Review Comment:
   nit: Could we also assert that the source directory remains present after 
the rejected rename?



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