Skip to content

Commit 095dacc

Browse files
author
Xing Lin
committed
Added and overwrite getTrashRootInFallBackFS()
1 parent 78b66f7 commit 095dacc

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemLocalFileSystem.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import org.apache.hadoop.fs.FileStatus;
3434
import org.apache.hadoop.fs.FileSystem;
3535
import org.apache.hadoop.fs.Path;
36+
import static org.apache.hadoop.fs.FileSystem.TRASH_PREFIX;
37+
import org.apache.hadoop.security.UserGroupInformation;
3638

3739
import org.junit.After;
3840
import org.junit.Before;
@@ -61,6 +63,13 @@ public void setUp() throws Exception {
6163

6264
}
6365

66+
@Override
67+
Path getTrashRootInFallBackFS() throws IOException {
68+
return new Path(
69+
"/" + TRASH_PREFIX + "/" + UserGroupInformation.getCurrentUser()
70+
.getShortUserName());
71+
}
72+
6473
@Test
6574
public void testNflyWriteSimple() throws IOException {
6675
LOG.info("Starting testNflyWriteSimple");

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemWithAuthorityLocalFileSystem.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import org.apache.hadoop.fs.FileSystemTestHelper;
2626
import org.apache.hadoop.fs.FsConstants;
2727
import org.apache.hadoop.fs.Path;
28+
import static org.apache.hadoop.fs.FileSystem.TRASH_PREFIX;
29+
import org.apache.hadoop.security.UserGroupInformation;
30+
import java.io.IOException;
2831

2932
import org.junit.After;
3033
import org.junit.Assert;
@@ -63,6 +66,13 @@ public void tearDown() throws Exception {
6366
super.tearDown();
6467
}
6568

69+
@Override
70+
Path getTrashRootInFallBackFS() throws IOException {
71+
return new Path(
72+
"/" + TRASH_PREFIX + "/" + UserGroupInformation.getCurrentUser()
73+
.getShortUserName());
74+
}
75+
6676
@Override
6777
@Test
6878
public void testBasicPaths() {

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,9 +1104,13 @@ public void testTrashRoot() throws IOException {
11041104
Assert.assertTrue("", fsView.getTrashRoots(true).size() > 0);
11051105
}
11061106

1107-
private String getTrashRootForPathInFallBackFS() {
1108-
return fsTarget.getHomeDirectory().toUri().getPath() + "/" + TRASH_PREFIX;
1107+
// Default implementation of getTrashRoot for a fallback FS mounted at root:
1108+
// e.g., fallbackFS.uri.getPath = '/'
1109+
Path getTrashRootInFallBackFS() throws IOException {
1110+
return new Path(fsTarget.getHomeDirectory().toUri().getPath(),
1111+
TRASH_PREFIX);
11091112
}
1113+
11101114
/**
11111115
* Test TRASH_FORCE_INSIDE_MOUNT_POINT feature for getTrashRoot.
11121116
*/
@@ -1128,15 +1132,8 @@ public void testTrashRootForceInsideMountPoint() throws IOException {
11281132
// Case 2: path p not found in mount table, fall back to the default FS
11291133
// Return a trash root in mount point "/"
11301134
Path nonExistentPath = new Path("/nonExistentDir/nonExistentFile");
1131-
Path expectedTrash;
1132-
if (targetTestRoot.toUri().getPath().equals("/")) {
1133-
expectedTrash =
1134-
fsView2.makeQualified(new Path(fsTarget.getHomeDirectory().toUri().getPath(),
1135-
TRASH_PREFIX));
1136-
} else {
1137-
expectedTrash =
1138-
fsView2.makeQualified(new Path("/" + TRASH_PREFIX + "/" + ugi.getShortUserName()));
1139-
}
1135+
Path expectedTrash =
1136+
fsView2.makeQualified(getTrashRootInFallBackFS());
11401137

11411138
Assert.assertEquals(expectedTrash, fsView2.getTrashRoot(nonExistentPath));
11421139

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemHdfs.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.apache.hadoop.test.GenericTestUtils;
5656
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_TRASH_INTERVAL_KEY;
5757
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY;
58+
import static org.apache.hadoop.fs.FileSystem.TRASH_PREFIX;
5859

5960
import org.junit.After;
6061
import org.junit.AfterClass;
@@ -181,6 +182,13 @@ int getExpectedDelegationTokenCountWithCredentials() {
181182
return 2;
182183
}
183184

185+
@Override
186+
Path getTrashRootInFallBackFS() throws IOException {
187+
return new Path(
188+
"/" + TRASH_PREFIX + "/" + UserGroupInformation.getCurrentUser()
189+
.getShortUserName());
190+
}
191+
184192
@Test
185193
public void testTrashRootsAfterEncryptionZoneDeletion() throws Exception {
186194
final Path zone = new Path("/EZ");

0 commit comments

Comments
 (0)