xiaoyuyao commented on a change in pull request #1089:
URL: https://github.com/apache/hadoop-ozone/pull/1089#discussion_r451103682



##########
File path: 
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedOzoneFileSystem.java
##########
@@ -871,4 +876,103 @@ public void testFailToDeleteRoot() throws IOException {
     Assert.assertFalse(fs.delete(new Path("/"), true));
   }
 
+  /**
+   * Test getTrashRoots() in OFS. Different from the existing test for o3fs.
+   */
+  @Test
+  public void testGetTrashRoots() throws IOException {
+    String username = UserGroupInformation.getCurrentUser().getShortUserName();
+    OzoneVolume volume1 = objectStore.getVolume(volumeName);
+    String prevOwner = volume1.getOwner();
+    // Set owner of the volume to current user, so it will show up in vol list
+    Assert.assertTrue(volume1.setOwner(username));
+
+    Path trashRoot1 = new Path(bucketPath, TRASH_PREFIX);
+    Path user1Trash1 = new Path(trashRoot1, username);
+    // When user trash dir isn't been created
+    Assert.assertEquals(0, fs.getTrashRoots(false).size());
+    Assert.assertEquals(0, fs.getTrashRoots(true).size());
+    // Let's create our first user1 (current user) trash dir.
+    fs.mkdirs(user1Trash1);
+    // Results should be getTrashRoots(false)=1, gTR(true)=1
+    Collection<FileStatus> res = fs.getTrashRoots(false);
+    Assert.assertEquals(1, res.size());
+    res.forEach(e -> Assert.assertEquals(
+        user1Trash1.toString(), e.getPath().toUri().getPath()));
+    res = fs.getTrashRoots(true);
+    Assert.assertEquals(1, res.size());
+    res.forEach(e -> Assert.assertEquals(
+        user1Trash1.toString(), e.getPath().toUri().getPath()));
+
+    // Create one more trash for user2 in the same bucket
+    Path user2Trash1 = new Path(trashRoot1, "testuser2");
+    fs.mkdirs(user2Trash1);
+    // Results should be getTrashRoots(false)=1, gTR(true)=2
+    Assert.assertEquals(1, fs.getTrashRoots(false).size());
+    Assert.assertEquals(2, fs.getTrashRoots(true).size());
+
+    // Create a new bucket in the same volume
+    final String bucketName2 = "trashroottest2";
+    volume1.createBucket(bucketName2);
+    Path bucketPath2 = new Path(volumePath, bucketName2);
+    Path trashRoot2 = new Path(bucketPath2, TRASH_PREFIX);
+    Path user1Trash2 = new Path(trashRoot2, username);
+    // Create a file at the trash location, it shouldn't be recognized as trash
+    try (FSDataOutputStream out1 = fs.create(user1Trash2)) {
+      out1.write(123);
+    }
+    // Results should still be getTrashRoots(false)=1, gTR(true)=2
+    Assert.assertEquals(1, fs.getTrashRoots(false).size());
+    res.forEach(e -> Assert.assertEquals(

Review comment:
       I see you have the assertion here for user1Trash1. So you can ignore the 
previous comment. 




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: ozone-issues-h...@hadoop.apache.org

Reply via email to