smengcl commented on code in PR #4236:
URL: https://github.com/apache/ozone/pull/4236#discussion_r1096209540


##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestKeyManagerImpl.java:
##########
@@ -1351,6 +1353,51 @@ public void testGetFileStatusWithFakeDir() throws 
IOException {
     Assert.assertTrue(ozoneFileStatus.isFile());
   }
 
+  @Test
+  public void testGetFileStatusWithFakeDirForHDDS7871() throws IOException {
+    String dirName = "foo2";
+    String fileName = "bar2";
+    String keyName1 = "foo1";
+    // keyName2 = "foo2/bar2"
+    String keyName2 = dirName + OZONE_URI_DELIMITER + fileName;
+    OzoneFileStatus ozoneFileStatus;
+
+    // create a key "foo1" in bucket1
+    OmKeyArgs keyArgs = 
createBuilder(BUCKET_NAME).setKeyName(keyName1).build();
+    OpenKeySession keySession = writeClient.openKey(keyArgs);
+    keyArgs.setLocationInfoList(
+        keySession.getKeyInfo().getLatestVersionLocations().getLocationList());
+    writeClient.commitKey(keyArgs, keySession.getId());
+
+    // create a key "foo2/bar2" in bucket2
+    keyArgs = createBuilder(BUCKET2_NAME).setKeyName(keyName2).build();
+    keySession = writeClient.createFile(keyArgs, true, true);
+    keyArgs.setLocationInfoList(
+        keySession.getKeyInfo().getLatestVersionLocations().getLocationList());
+    writeClient.commitKey(keyArgs, keySession.getId());
+
+    // Verify the following dbKeys in key table:
+    // 1. "volume1/bucket1/foo1"
+    // 2. "volume1/bucket2/foo2/bar2"
+    Assert.assertNotNull(metadataManager.getKeyTable(getDefaultBucketLayout())
+        .get(metadataManager.getOzoneKey(VOLUME_NAME, BUCKET_NAME, keyName1)));
+    Assert.assertNotNull(metadataManager.getKeyTable(getDefaultBucketLayout())
+        .get(metadataManager.getOzoneKey(VOLUME_NAME, BUCKET2_NAME, 
keyName2)));
+
+    // get a non-existing "foo2" from bucket1, RocksIter#seek() will find the
+    // 2nd dbKey "volume1/bucket2/foo2/bar2", which is not belong to bucket1.
+    keyArgs = createBuilder(BUCKET_NAME).setKeyName(dirName).build();
+    OmKeyArgs finalKeyArgs = keyArgs;
+    Assert.assertThrows(OMException.class, () -> keyManager.getFileStatus(
+        finalKeyArgs));
+

Review Comment:
   nit: check the ResultCode as well (`FILE_NOT_FOUND`)



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