|
17 | 17 | */ |
18 | 18 | package org.apache.hadoop.fs.viewfs; |
19 | 19 |
|
| 20 | +import java.io.DataOutputStream; |
| 21 | +import java.io.IOException; |
20 | 22 | import org.apache.hadoop.conf.Configuration; |
21 | 23 | import org.apache.hadoop.fs.FileSystem; |
22 | 24 | import org.apache.hadoop.fs.FileSystemTestHelper; |
23 | 25 | import org.apache.hadoop.fs.FsConstants; |
| 26 | +import org.apache.hadoop.fs.LocalFileSystem; |
24 | 27 | import org.apache.hadoop.fs.Path; |
25 | 28 | import org.apache.hadoop.fs.TestTrash; |
| 29 | +import org.apache.hadoop.fs.Trash; |
| 30 | +import org.apache.hadoop.fs.TrashPolicyDefault; |
26 | 31 | import org.junit.After; |
27 | 32 | import org.junit.Before; |
28 | 33 | import org.junit.Test; |
| 34 | +import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.*; |
| 35 | +import static org.apache.hadoop.fs.viewfs.Constants.*; |
| 36 | +import static org.junit.Assert.*; |
29 | 37 |
|
30 | 38 | public class TestViewFsTrash { |
31 | 39 | FileSystem fsTarget; // the target file system - the mount will point here |
@@ -65,5 +73,39 @@ public void testTrash() throws Exception { |
65 | 73 | TestTrash.trashShell(conf, fileSystemTestHelper.getTestRootPath(fsView), |
66 | 74 | fsView, new Path(fileSystemTestHelper.getTestRootPath(fsView), ".Trash/Current")); |
67 | 75 | } |
68 | | - |
| 76 | + |
| 77 | + @Test |
| 78 | + public void testLocalizedTrashInMoveToAppropriateTrash() throws IOException { |
| 79 | + Configuration conf2 = new Configuration(conf); |
| 80 | + |
| 81 | + // Enable moveToTrash and add a mount point for /data |
| 82 | + conf2.setLong(FS_TRASH_INTERVAL_KEY, 1); |
| 83 | + ConfigUtil.addLink(conf2, "/data", new Path(fileSystemTestHelper.getAbsoluteTestRootPath(fsTarget), "data").toUri()); |
| 84 | + |
| 85 | + // Default case. file should be moved to fsTarget.getTrashRoot()/resolvedPath |
| 86 | + conf2.setBoolean(CONFIG_VIEWFS_TRASH_FORCE_INSIDE_MOUNT_POINT, false); |
| 87 | + FileSystem fsView2 = FileSystem.get(conf2); |
| 88 | + Path f = new Path("/data/testfile.txt"); |
| 89 | + DataOutputStream out = fsView2.create(f); |
| 90 | + out.writeBytes("testfile.txt:" + f); |
| 91 | + out.close(); |
| 92 | + Path resolvedFile = fsView2.resolvePath(f); |
| 93 | + |
| 94 | + Trash.moveToAppropriateTrash(fsView2, f, conf2); |
| 95 | + Trash trash = new Trash(fsTarget, conf2); |
| 96 | + Path movedPath = Path.mergePaths(trash.getCurrentTrashDir(f), resolvedFile); |
| 97 | + assertTrue("File not in trash", fsTarget.exists(movedPath)); |
| 98 | + |
| 99 | + // Turn on localized trash. File should be moved to viewfs:/data/.Trash/{user}/Current. |
| 100 | + conf2.setBoolean(CONFIG_VIEWFS_TRASH_FORCE_INSIDE_MOUNT_POINT, true); |
| 101 | + fsView2 = FileSystem.get(conf2); |
| 102 | + out = fsView2.create(f); |
| 103 | + out.writeBytes("testfile.txt:" + f); |
| 104 | + out.close(); |
| 105 | + |
| 106 | + Trash.moveToAppropriateTrash(fsView2, f, conf2); |
| 107 | + trash = new Trash(fsView2, conf2); |
| 108 | + movedPath = Path.mergePaths(trash.getCurrentTrashDir(f), f); |
| 109 | + assertTrue("File not in localized trash", fsView2.exists(movedPath)); |
| 110 | + } |
69 | 111 | } |
0 commit comments