HADOOP-14170. FileSystemContractBaseTest is not cleaning up test directory clearly. Contributed by Mingliang Liu
This commit is contained in:
parent
e6cda5819b
commit
fa67a96d7b
@ -24,8 +24,9 @@
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.slf4j.Logger;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.permission.FsPermission;
|
import org.apache.hadoop.fs.permission.FsPermission;
|
||||||
import org.apache.hadoop.security.AccessControlException;
|
import org.apache.hadoop.security.AccessControlException;
|
||||||
@ -45,8 +46,8 @@
|
|||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public abstract class FileSystemContractBaseTest extends TestCase {
|
public abstract class FileSystemContractBaseTest extends TestCase {
|
||||||
private static final Log LOG =
|
private static final Logger LOG =
|
||||||
LogFactory.getLog(FileSystemContractBaseTest.class);
|
LoggerFactory.getLogger(FileSystemContractBaseTest.class);
|
||||||
|
|
||||||
protected final static String TEST_UMASK = "062";
|
protected final static String TEST_UMASK = "062";
|
||||||
protected FileSystem fs;
|
protected FileSystem fs;
|
||||||
@ -54,13 +55,44 @@ public abstract class FileSystemContractBaseTest extends TestCase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
try {
|
if (fs != null) {
|
||||||
if (fs != null) {
|
// some cases use this absolute path
|
||||||
fs.delete(path("/test"), true);
|
if (rootDirTestEnabled()) {
|
||||||
|
cleanupDir(path("/FileSystemContractBaseTest"));
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
// others use this relative path against test base directory
|
||||||
LOG.error("Error deleting /test: " + e, e);
|
cleanupDir(getTestBaseDir());
|
||||||
}
|
}
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cleanupDir(Path p) {
|
||||||
|
try {
|
||||||
|
LOG.info("Deleting " + p);
|
||||||
|
fs.delete(p, true);
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOG.error("Error deleting test dir: " + p, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test base directory for resolving relative test paths.
|
||||||
|
*
|
||||||
|
* The default value is /user/$USER/FileSystemContractBaseTest. Subclass may
|
||||||
|
* set specific test base directory.
|
||||||
|
*/
|
||||||
|
protected Path getTestBaseDir() {
|
||||||
|
return new Path(fs.getWorkingDirectory(), "FileSystemContractBaseTest");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For absolute path return the fully qualified path while for relative path
|
||||||
|
* return the fully qualified path against {@link #getTestBaseDir()}.
|
||||||
|
*/
|
||||||
|
protected final Path path(String pathString) {
|
||||||
|
Path p = new Path(pathString).makeQualified(fs.getUri(), getTestBaseDir());
|
||||||
|
LOG.info("Resolving {} -> {}", pathString, p);
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getBlockSize() {
|
protected int getBlockSize() {
|
||||||
@ -80,6 +112,17 @@ protected boolean renameSupported() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override this if the filesystem does not enable testing root directories.
|
||||||
|
*
|
||||||
|
* If this returns true, the test will create and delete test directories and
|
||||||
|
* files under root directory, which may have side effects, e.g. fail tests
|
||||||
|
* with PermissionDenied exceptions.
|
||||||
|
*/
|
||||||
|
protected boolean rootDirTestEnabled() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override this if the filesystem is not case sensitive
|
* Override this if the filesystem is not case sensitive
|
||||||
* @return true if the case detection/preservation tests should run
|
* @return true if the case detection/preservation tests should run
|
||||||
@ -102,24 +145,24 @@ public void testWorkingDirectory() throws Exception {
|
|||||||
Path workDir = path(getDefaultWorkingDirectory());
|
Path workDir = path(getDefaultWorkingDirectory());
|
||||||
assertEquals(workDir, fs.getWorkingDirectory());
|
assertEquals(workDir, fs.getWorkingDirectory());
|
||||||
|
|
||||||
fs.setWorkingDirectory(path("."));
|
fs.setWorkingDirectory(fs.makeQualified(new Path(".")));
|
||||||
assertEquals(workDir, fs.getWorkingDirectory());
|
assertEquals(workDir, fs.getWorkingDirectory());
|
||||||
|
|
||||||
fs.setWorkingDirectory(path(".."));
|
fs.setWorkingDirectory(fs.makeQualified(new Path("..")));
|
||||||
assertEquals(workDir.getParent(), fs.getWorkingDirectory());
|
assertEquals(workDir.getParent(), fs.getWorkingDirectory());
|
||||||
|
|
||||||
Path relativeDir = path("hadoop");
|
Path relativeDir = fs.makeQualified(new Path("testWorkingDirectory"));
|
||||||
fs.setWorkingDirectory(relativeDir);
|
fs.setWorkingDirectory(relativeDir);
|
||||||
assertEquals(relativeDir, fs.getWorkingDirectory());
|
assertEquals(relativeDir, fs.getWorkingDirectory());
|
||||||
|
|
||||||
Path absoluteDir = path("/test/hadoop");
|
Path absoluteDir = path("/FileSystemContractBaseTest/testWorkingDirectory");
|
||||||
fs.setWorkingDirectory(absoluteDir);
|
fs.setWorkingDirectory(absoluteDir);
|
||||||
assertEquals(absoluteDir, fs.getWorkingDirectory());
|
assertEquals(absoluteDir, fs.getWorkingDirectory());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMkdirs() throws Exception {
|
public void testMkdirs() throws Exception {
|
||||||
Path testDir = path("/test/hadoop");
|
Path testDir = path("testMkdirs");
|
||||||
assertFalse(fs.exists(testDir));
|
assertFalse(fs.exists(testDir));
|
||||||
assertFalse(fs.isFile(testDir));
|
assertFalse(fs.isFile(testDir));
|
||||||
|
|
||||||
@ -145,14 +188,15 @@ public void testMkdirs() throws Exception {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testMkdirsFailsForSubdirectoryOfExistingFile() throws Exception {
|
public void testMkdirsFailsForSubdirectoryOfExistingFile() throws Exception {
|
||||||
Path testDir = path("/test/hadoop");
|
Path testDir = path("testMkdirsFailsForSubdirectoryOfExistingFile");
|
||||||
assertFalse(fs.exists(testDir));
|
assertFalse(fs.exists(testDir));
|
||||||
assertTrue(fs.mkdirs(testDir));
|
assertTrue(fs.mkdirs(testDir));
|
||||||
assertTrue(fs.exists(testDir));
|
assertTrue(fs.exists(testDir));
|
||||||
|
|
||||||
createFile(path("/test/hadoop/file"));
|
createFile(path("testMkdirsFailsForSubdirectoryOfExistingFile/file"));
|
||||||
|
|
||||||
Path testSubDir = path("/test/hadoop/file/subdir");
|
Path testSubDir = path(
|
||||||
|
"testMkdirsFailsForSubdirectoryOfExistingFile/file/subdir");
|
||||||
try {
|
try {
|
||||||
fs.mkdirs(testSubDir);
|
fs.mkdirs(testSubDir);
|
||||||
fail("Should throw IOException.");
|
fail("Should throw IOException.");
|
||||||
@ -167,7 +211,8 @@ public void testMkdirsFailsForSubdirectoryOfExistingFile() throws Exception {
|
|||||||
// file missing execute permission.
|
// file missing execute permission.
|
||||||
}
|
}
|
||||||
|
|
||||||
Path testDeepSubDir = path("/test/hadoop/file/deep/sub/dir");
|
Path testDeepSubDir = path(
|
||||||
|
"testMkdirsFailsForSubdirectoryOfExistingFile/file/deep/sub/dir");
|
||||||
try {
|
try {
|
||||||
fs.mkdirs(testDeepSubDir);
|
fs.mkdirs(testDeepSubDir);
|
||||||
fail("Should throw IOException.");
|
fail("Should throw IOException.");
|
||||||
@ -190,7 +235,7 @@ public void testMkdirsWithUmask() throws Exception {
|
|||||||
String oldUmask = conf.get(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY);
|
String oldUmask = conf.get(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY);
|
||||||
try {
|
try {
|
||||||
conf.set(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY, TEST_UMASK);
|
conf.set(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY, TEST_UMASK);
|
||||||
final Path dir = path("/test/newDir");
|
final Path dir = path("newDir");
|
||||||
assertTrue(fs.mkdirs(dir, new FsPermission((short) 0777)));
|
assertTrue(fs.mkdirs(dir, new FsPermission((short) 0777)));
|
||||||
FileStatus status = fs.getFileStatus(dir);
|
FileStatus status = fs.getFileStatus(dir);
|
||||||
assertTrue(status.isDirectory());
|
assertTrue(status.isDirectory());
|
||||||
@ -223,7 +268,8 @@ private boolean isS3(FileSystem fileSystem) {
|
|||||||
public void testGetFileStatusThrowsExceptionForNonExistentFile()
|
public void testGetFileStatusThrowsExceptionForNonExistentFile()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
try {
|
try {
|
||||||
fs.getFileStatus(path("/test/hadoop/file"));
|
fs.getFileStatus(
|
||||||
|
path("testGetFileStatusThrowsExceptionForNonExistentFile/file"));
|
||||||
fail("Should throw FileNotFoundException");
|
fail("Should throw FileNotFoundException");
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
// expected
|
// expected
|
||||||
@ -232,7 +278,8 @@ public void testGetFileStatusThrowsExceptionForNonExistentFile()
|
|||||||
|
|
||||||
public void testListStatusThrowsExceptionForNonExistentFile() throws Exception {
|
public void testListStatusThrowsExceptionForNonExistentFile() throws Exception {
|
||||||
try {
|
try {
|
||||||
fs.listStatus(path("/test/hadoop/file"));
|
fs.listStatus(
|
||||||
|
path("testListStatusThrowsExceptionForNonExistentFile/file"));
|
||||||
fail("Should throw FileNotFoundException");
|
fail("Should throw FileNotFoundException");
|
||||||
} catch (FileNotFoundException fnfe) {
|
} catch (FileNotFoundException fnfe) {
|
||||||
// expected
|
// expected
|
||||||
@ -240,30 +287,32 @@ public void testListStatusThrowsExceptionForNonExistentFile() throws Exception {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testListStatus() throws Exception {
|
public void testListStatus() throws Exception {
|
||||||
Path[] testDirs = { path("/test/hadoop/a"),
|
final Path[] testDirs = {
|
||||||
path("/test/hadoop/b"),
|
path("testListStatus/a"),
|
||||||
path("/test/hadoop/c/1"), };
|
path("testListStatus/b"),
|
||||||
|
path("testListStatus/c/1")
|
||||||
|
};
|
||||||
assertFalse(fs.exists(testDirs[0]));
|
assertFalse(fs.exists(testDirs[0]));
|
||||||
|
|
||||||
for (Path path : testDirs) {
|
for (Path path : testDirs) {
|
||||||
assertTrue(fs.mkdirs(path));
|
assertTrue(fs.mkdirs(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
FileStatus[] paths = fs.listStatus(path("/test"));
|
FileStatus[] paths = fs.listStatus(path("."));
|
||||||
assertEquals(1, paths.length);
|
assertEquals(1, paths.length);
|
||||||
assertEquals(path("/test/hadoop"), paths[0].getPath());
|
assertEquals(path("testListStatus"), paths[0].getPath());
|
||||||
|
|
||||||
paths = fs.listStatus(path("/test/hadoop"));
|
paths = fs.listStatus(path("testListStatus"));
|
||||||
assertEquals(3, paths.length);
|
assertEquals(3, paths.length);
|
||||||
ArrayList<Path> list = new ArrayList<Path>();
|
ArrayList<Path> list = new ArrayList<Path>();
|
||||||
for (FileStatus fileState : paths) {
|
for (FileStatus fileState : paths) {
|
||||||
list.add(fileState.getPath());
|
list.add(fileState.getPath());
|
||||||
}
|
}
|
||||||
assertTrue(list.contains(path("/test/hadoop/a")));
|
assertTrue(list.contains(path("testListStatus/a")));
|
||||||
assertTrue(list.contains(path("/test/hadoop/b")));
|
assertTrue(list.contains(path("testListStatus/b")));
|
||||||
assertTrue(list.contains(path("/test/hadoop/c")));
|
assertTrue(list.contains(path("testListStatus/c")));
|
||||||
|
|
||||||
paths = fs.listStatus(path("/test/hadoop/a"));
|
paths = fs.listStatus(path("testListStatus/a"));
|
||||||
assertEquals(0, paths.length);
|
assertEquals(0, paths.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,12 +343,12 @@ public void testWriteReadAndDeleteTwoBlocks() throws Exception {
|
|||||||
* @throws IOException on IO failures
|
* @throws IOException on IO failures
|
||||||
*/
|
*/
|
||||||
protected void writeReadAndDelete(int len) throws IOException {
|
protected void writeReadAndDelete(int len) throws IOException {
|
||||||
Path path = path("/test/hadoop/file");
|
Path path = path("writeReadAndDelete/file");
|
||||||
writeAndRead(path, data, len, false, true);
|
writeAndRead(path, data, len, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOverwrite() throws IOException {
|
public void testOverwrite() throws IOException {
|
||||||
Path path = path("/test/hadoop/file");
|
Path path = path("testOverwrite/file");
|
||||||
|
|
||||||
fs.mkdirs(path.getParent());
|
fs.mkdirs(path.getParent());
|
||||||
|
|
||||||
@ -325,7 +374,7 @@ public void testOverwrite() throws IOException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testWriteInNonExistentDirectory() throws IOException {
|
public void testWriteInNonExistentDirectory() throws IOException {
|
||||||
Path path = path("/test/hadoop/file");
|
Path path = path("testWriteInNonExistentDirectory/file");
|
||||||
assertFalse("Parent exists", fs.exists(path.getParent()));
|
assertFalse("Parent exists", fs.exists(path.getParent()));
|
||||||
createFile(path);
|
createFile(path);
|
||||||
|
|
||||||
@ -335,15 +384,15 @@ public void testWriteInNonExistentDirectory() throws IOException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testDeleteNonExistentFile() throws IOException {
|
public void testDeleteNonExistentFile() throws IOException {
|
||||||
Path path = path("/test/hadoop/file");
|
Path path = path("testDeleteNonExistentFile/file");
|
||||||
assertFalse("Path exists: " + path, fs.exists(path));
|
assertFalse("Path exists: " + path, fs.exists(path));
|
||||||
assertFalse("No deletion", fs.delete(path, true));
|
assertFalse("No deletion", fs.delete(path, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDeleteRecursively() throws IOException {
|
public void testDeleteRecursively() throws IOException {
|
||||||
Path dir = path("/test/hadoop");
|
Path dir = path("testDeleteRecursively");
|
||||||
Path file = path("/test/hadoop/file");
|
Path file = path("testDeleteRecursively/file");
|
||||||
Path subdir = path("/test/hadoop/subdir");
|
Path subdir = path("testDeleteRecursively/subdir");
|
||||||
|
|
||||||
createFile(file);
|
createFile(file);
|
||||||
assertTrue("Created subdir", fs.mkdirs(subdir));
|
assertTrue("Created subdir", fs.mkdirs(subdir));
|
||||||
@ -369,7 +418,7 @@ public void testDeleteRecursively() throws IOException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testDeleteEmptyDirectory() throws IOException {
|
public void testDeleteEmptyDirectory() throws IOException {
|
||||||
Path dir = path("/test/hadoop");
|
Path dir = path("testDeleteEmptyDirectory");
|
||||||
assertTrue(fs.mkdirs(dir));
|
assertTrue(fs.mkdirs(dir));
|
||||||
assertTrue("Dir exists", fs.exists(dir));
|
assertTrue("Dir exists", fs.exists(dir));
|
||||||
assertTrue("Deleted", fs.delete(dir, false));
|
assertTrue("Deleted", fs.delete(dir, false));
|
||||||
@ -379,26 +428,26 @@ public void testDeleteEmptyDirectory() throws IOException {
|
|||||||
public void testRenameNonExistentPath() throws Exception {
|
public void testRenameNonExistentPath() throws Exception {
|
||||||
if (!renameSupported()) return;
|
if (!renameSupported()) return;
|
||||||
|
|
||||||
Path src = path("/test/hadoop/path");
|
Path src = path("testRenameNonExistentPath/path");
|
||||||
Path dst = path("/test/new/newpath");
|
Path dst = path("testRenameNonExistentPathNew/newpath");
|
||||||
rename(src, dst, false, false, false);
|
rename(src, dst, false, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRenameFileMoveToNonExistentDirectory() throws Exception {
|
public void testRenameFileMoveToNonExistentDirectory() throws Exception {
|
||||||
if (!renameSupported()) return;
|
if (!renameSupported()) return;
|
||||||
|
|
||||||
Path src = path("/test/hadoop/file");
|
Path src = path("testRenameFileMoveToNonExistentDirectory/file");
|
||||||
createFile(src);
|
createFile(src);
|
||||||
Path dst = path("/test/new/newfile");
|
Path dst = path("testRenameFileMoveToNonExistentDirectoryNew/newfile");
|
||||||
rename(src, dst, false, true, false);
|
rename(src, dst, false, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRenameFileMoveToExistingDirectory() throws Exception {
|
public void testRenameFileMoveToExistingDirectory() throws Exception {
|
||||||
if (!renameSupported()) return;
|
if (!renameSupported()) return;
|
||||||
|
|
||||||
Path src = path("/test/hadoop/file");
|
Path src = path("testRenameFileMoveToExistingDirectory/file");
|
||||||
createFile(src);
|
createFile(src);
|
||||||
Path dst = path("/test/new/newfile");
|
Path dst = path("testRenameFileMoveToExistingDirectoryNew/newfile");
|
||||||
fs.mkdirs(dst.getParent());
|
fs.mkdirs(dst.getParent());
|
||||||
rename(src, dst, true, false, true);
|
rename(src, dst, true, false, true);
|
||||||
}
|
}
|
||||||
@ -406,9 +455,9 @@ public void testRenameFileMoveToExistingDirectory() throws Exception {
|
|||||||
public void testRenameFileAsExistingFile() throws Exception {
|
public void testRenameFileAsExistingFile() throws Exception {
|
||||||
if (!renameSupported()) return;
|
if (!renameSupported()) return;
|
||||||
|
|
||||||
Path src = path("/test/hadoop/file");
|
Path src = path("testRenameFileAsExistingFile/file");
|
||||||
createFile(src);
|
createFile(src);
|
||||||
Path dst = path("/test/new/newfile");
|
Path dst = path("testRenameFileAsExistingFileNew/newfile");
|
||||||
createFile(dst);
|
createFile(dst);
|
||||||
rename(src, dst, false, true, true);
|
rename(src, dst, false, true, true);
|
||||||
}
|
}
|
||||||
@ -416,83 +465,81 @@ public void testRenameFileAsExistingFile() throws Exception {
|
|||||||
public void testRenameFileAsExistingDirectory() throws Exception {
|
public void testRenameFileAsExistingDirectory() throws Exception {
|
||||||
if (!renameSupported()) return;
|
if (!renameSupported()) return;
|
||||||
|
|
||||||
Path src = path("/test/hadoop/file");
|
Path src = path("testRenameFileAsExistingDirectory/file");
|
||||||
createFile(src);
|
createFile(src);
|
||||||
Path dst = path("/test/new/newdir");
|
Path dst = path("testRenameFileAsExistingDirectoryNew/newdir");
|
||||||
fs.mkdirs(dst);
|
fs.mkdirs(dst);
|
||||||
rename(src, dst, true, false, true);
|
rename(src, dst, true, false, true);
|
||||||
assertIsFile(path("/test/new/newdir/file"));
|
assertIsFile(path("testRenameFileAsExistingDirectoryNew/newdir/file"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRenameDirectoryMoveToNonExistentDirectory()
|
public void testRenameDirectoryMoveToNonExistentDirectory()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
if (!renameSupported()) return;
|
if (!renameSupported()) return;
|
||||||
|
|
||||||
Path src = path("/test/hadoop/dir");
|
Path src = path("testRenameDirectoryMoveToNonExistentDirectory/dir");
|
||||||
fs.mkdirs(src);
|
fs.mkdirs(src);
|
||||||
Path dst = path("/test/new/newdir");
|
Path dst = path("testRenameDirectoryMoveToNonExistentDirectoryNew/newdir");
|
||||||
rename(src, dst, false, true, false);
|
rename(src, dst, false, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRenameDirectoryMoveToExistingDirectory() throws Exception {
|
public void testRenameDirectoryMoveToExistingDirectory() throws Exception {
|
||||||
if (!renameSupported()) return;
|
if (!renameSupported()) return;
|
||||||
|
Path src = path("testRenameDirectoryMoveToExistingDirectory/dir");
|
||||||
Path src = path("/test/hadoop/dir");
|
|
||||||
fs.mkdirs(src);
|
fs.mkdirs(src);
|
||||||
createFile(path("/test/hadoop/dir/file1"));
|
createFile(path(src + "/file1"));
|
||||||
createFile(path("/test/hadoop/dir/subdir/file2"));
|
createFile(path(src + "/subdir/file2"));
|
||||||
|
|
||||||
Path dst = path("/test/new/newdir");
|
Path dst = path("testRenameDirectoryMoveToExistingDirectoryNew/newdir");
|
||||||
fs.mkdirs(dst.getParent());
|
fs.mkdirs(dst.getParent());
|
||||||
rename(src, dst, true, false, true);
|
rename(src, dst, true, false, true);
|
||||||
|
|
||||||
assertFalse("Nested file1 exists",
|
assertFalse("Nested file1 exists",
|
||||||
fs.exists(path("/test/hadoop/dir/file1")));
|
fs.exists(path(src + "/file1")));
|
||||||
assertFalse("Nested file2 exists",
|
assertFalse("Nested file2 exists",
|
||||||
fs.exists(path("/test/hadoop/dir/subdir/file2")));
|
fs.exists(path(src + "/subdir/file2")));
|
||||||
assertTrue("Renamed nested file1 exists",
|
assertTrue("Renamed nested file1 exists",
|
||||||
fs.exists(path("/test/new/newdir/file1")));
|
fs.exists(path(dst + "/file1")));
|
||||||
assertTrue("Renamed nested exists",
|
assertTrue("Renamed nested exists",
|
||||||
fs.exists(path("/test/new/newdir/subdir/file2")));
|
fs.exists(path(dst + "/subdir/file2")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRenameDirectoryAsExistingFile() throws Exception {
|
public void testRenameDirectoryAsExistingFile() throws Exception {
|
||||||
if (!renameSupported()) return;
|
if (!renameSupported()) return;
|
||||||
|
|
||||||
Path src = path("/test/hadoop/dir");
|
Path src = path("testRenameDirectoryAsExistingFile/dir");
|
||||||
fs.mkdirs(src);
|
fs.mkdirs(src);
|
||||||
Path dst = path("/test/new/newfile");
|
Path dst = path("testRenameDirectoryAsExistingFileNew/newfile");
|
||||||
createFile(dst);
|
createFile(dst);
|
||||||
rename(src, dst, false, true, true);
|
rename(src, dst, false, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRenameDirectoryAsExistingDirectory() throws Exception {
|
public void testRenameDirectoryAsExistingDirectory() throws Exception {
|
||||||
if (!renameSupported()) return;
|
if (!renameSupported()) return;
|
||||||
|
final Path src = path("testRenameDirectoryAsExistingDirectory/dir");
|
||||||
Path src = path("/test/hadoop/dir");
|
|
||||||
fs.mkdirs(src);
|
fs.mkdirs(src);
|
||||||
createFile(path("/test/hadoop/dir/file1"));
|
createFile(path(src + "/file1"));
|
||||||
createFile(path("/test/hadoop/dir/subdir/file2"));
|
createFile(path(src + "/subdir/file2"));
|
||||||
|
|
||||||
Path dst = path("/test/new/newdir");
|
final Path dst = path("testRenameDirectoryAsExistingDirectoryNew/newdir");
|
||||||
fs.mkdirs(dst);
|
fs.mkdirs(dst);
|
||||||
rename(src, dst, true, false, true);
|
rename(src, dst, true, false, true);
|
||||||
assertTrue("Destination changed",
|
assertTrue("Destination changed",
|
||||||
fs.exists(path("/test/new/newdir/dir")));
|
fs.exists(path(dst + "/dir")));
|
||||||
assertFalse("Nested file1 exists",
|
assertFalse("Nested file1 exists",
|
||||||
fs.exists(path("/test/hadoop/dir/file1")));
|
fs.exists(path(src + "/file1")));
|
||||||
assertFalse("Nested file2 exists",
|
assertFalse("Nested file2 exists",
|
||||||
fs.exists(path("/test/hadoop/dir/subdir/file2")));
|
fs.exists(path(src + "/dir/subdir/file2")));
|
||||||
assertTrue("Renamed nested file1 exists",
|
assertTrue("Renamed nested file1 exists",
|
||||||
fs.exists(path("/test/new/newdir/dir/file1")));
|
fs.exists(path(dst + "/dir/file1")));
|
||||||
assertTrue("Renamed nested exists",
|
assertTrue("Renamed nested exists",
|
||||||
fs.exists(path("/test/new/newdir/dir/subdir/file2")));
|
fs.exists(path(dst + "/dir/subdir/file2")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInputStreamClosedTwice() throws IOException {
|
public void testInputStreamClosedTwice() throws IOException {
|
||||||
//HADOOP-4760 according to Closeable#close() closing already-closed
|
//HADOOP-4760 according to Closeable#close() closing already-closed
|
||||||
//streams should have no effect.
|
//streams should have no effect.
|
||||||
Path src = path("/test/hadoop/file");
|
Path src = path("testInputStreamClosedTwice/file");
|
||||||
createFile(src);
|
createFile(src);
|
||||||
FSDataInputStream in = fs.open(src);
|
FSDataInputStream in = fs.open(src);
|
||||||
in.close();
|
in.close();
|
||||||
@ -502,18 +549,13 @@ public void testInputStreamClosedTwice() throws IOException {
|
|||||||
public void testOutputStreamClosedTwice() throws IOException {
|
public void testOutputStreamClosedTwice() throws IOException {
|
||||||
//HADOOP-4760 according to Closeable#close() closing already-closed
|
//HADOOP-4760 according to Closeable#close() closing already-closed
|
||||||
//streams should have no effect.
|
//streams should have no effect.
|
||||||
Path src = path("/test/hadoop/file");
|
Path src = path("testOutputStreamClosedTwice/file");
|
||||||
FSDataOutputStream out = fs.create(src);
|
FSDataOutputStream out = fs.create(src);
|
||||||
out.writeChar('H'); //write some data
|
out.writeChar('H'); //write some data
|
||||||
out.close();
|
out.close();
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Path path(String pathString) {
|
|
||||||
return new Path(pathString).makeQualified(fs.getUri(),
|
|
||||||
fs.getWorkingDirectory());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void createFile(Path path) throws IOException {
|
protected void createFile(Path path) throws IOException {
|
||||||
FSDataOutputStream out = fs.create(path);
|
FSDataOutputStream out = fs.create(path);
|
||||||
out.write(data, 0, data.length);
|
out.write(data, 0, data.length);
|
||||||
@ -541,7 +583,7 @@ public void testOverWriteAndRead() throws Exception {
|
|||||||
|
|
||||||
byte[] filedata1 = dataset(blockSize * 2, 'A', 26);
|
byte[] filedata1 = dataset(blockSize * 2, 'A', 26);
|
||||||
byte[] filedata2 = dataset(blockSize * 2, 'a', 26);
|
byte[] filedata2 = dataset(blockSize * 2, 'a', 26);
|
||||||
Path path = path("/test/hadoop/file-overwrite");
|
Path path = path("testOverWriteAndRead/file-overwrite");
|
||||||
writeAndRead(path, filedata1, blockSize, true, false);
|
writeAndRead(path, filedata1, blockSize, true, false);
|
||||||
writeAndRead(path, filedata2, blockSize, true, false);
|
writeAndRead(path, filedata2, blockSize, true, false);
|
||||||
writeAndRead(path, filedata1, blockSize * 2, true, false);
|
writeAndRead(path, filedata1, blockSize * 2, true, false);
|
||||||
@ -561,7 +603,7 @@ public void testFilesystemIsCaseSensitive() throws Exception {
|
|||||||
LOG.info("Skipping test");
|
LOG.info("Skipping test");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String mixedCaseFilename = "/test/UPPER.TXT";
|
String mixedCaseFilename = "testFilesystemIsCaseSensitive";
|
||||||
Path upper = path(mixedCaseFilename);
|
Path upper = path(mixedCaseFilename);
|
||||||
Path lower = path(StringUtils.toLowerCase(mixedCaseFilename));
|
Path lower = path(StringUtils.toLowerCase(mixedCaseFilename));
|
||||||
assertFalse("File exists" + upper, fs.exists(upper));
|
assertFalse("File exists" + upper, fs.exists(upper));
|
||||||
@ -592,7 +634,7 @@ public void testFilesystemIsCaseSensitive() throws Exception {
|
|||||||
* @throws Exception on failures
|
* @throws Exception on failures
|
||||||
*/
|
*/
|
||||||
public void testZeroByteFilesAreFiles() throws Exception {
|
public void testZeroByteFilesAreFiles() throws Exception {
|
||||||
Path src = path("/test/testZeroByteFilesAreFiles");
|
Path src = path("testZeroByteFilesAreFiles");
|
||||||
//create a zero byte file
|
//create a zero byte file
|
||||||
FSDataOutputStream out = fs.create(src);
|
FSDataOutputStream out = fs.create(src);
|
||||||
out.close();
|
out.close();
|
||||||
@ -605,7 +647,7 @@ public void testZeroByteFilesAreFiles() throws Exception {
|
|||||||
* @throws Exception on failures
|
* @throws Exception on failures
|
||||||
*/
|
*/
|
||||||
public void testMultiByteFilesAreFiles() throws Exception {
|
public void testMultiByteFilesAreFiles() throws Exception {
|
||||||
Path src = path("/test/testMultiByteFilesAreFiles");
|
Path src = path("testMultiByteFilesAreFiles");
|
||||||
FSDataOutputStream out = fs.create(src);
|
FSDataOutputStream out = fs.create(src);
|
||||||
out.writeUTF("testMultiByteFilesAreFiles");
|
out.writeUTF("testMultiByteFilesAreFiles");
|
||||||
out.close();
|
out.close();
|
||||||
@ -629,10 +671,14 @@ public void testRootDirAlwaysExists() throws Exception {
|
|||||||
* @throws Exception on failures
|
* @throws Exception on failures
|
||||||
*/
|
*/
|
||||||
public void testRenameRootDirForbidden() throws Exception {
|
public void testRenameRootDirForbidden() throws Exception {
|
||||||
|
if (!rootDirTestEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!renameSupported()) return;
|
if (!renameSupported()) return;
|
||||||
|
|
||||||
rename(path("/"),
|
rename(path("/"),
|
||||||
path("/test/newRootDir"),
|
path("testRenameRootDirForbidden"),
|
||||||
false, true, false);
|
false, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -644,7 +690,7 @@ public void testRenameRootDirForbidden() throws Exception {
|
|||||||
public void testRenameChildDirForbidden() throws Exception {
|
public void testRenameChildDirForbidden() throws Exception {
|
||||||
if (!renameSupported()) return;
|
if (!renameSupported()) return;
|
||||||
LOG.info("testRenameChildDirForbidden");
|
LOG.info("testRenameChildDirForbidden");
|
||||||
Path parentdir = path("/test/parentdir");
|
Path parentdir = path("testRenameChildDirForbidden");
|
||||||
fs.mkdirs(parentdir);
|
fs.mkdirs(parentdir);
|
||||||
Path childFile = new Path(parentdir, "childfile");
|
Path childFile = new Path(parentdir, "childfile");
|
||||||
createFile(childFile);
|
createFile(childFile);
|
||||||
@ -663,9 +709,9 @@ public void testRenameChildDirForbidden() throws Exception {
|
|||||||
*/
|
*/
|
||||||
public void testRenameToDirWithSamePrefixAllowed() throws Throwable {
|
public void testRenameToDirWithSamePrefixAllowed() throws Throwable {
|
||||||
if (!renameSupported()) return;
|
if (!renameSupported()) return;
|
||||||
Path parentdir = path("test/parentdir");
|
final Path parentdir = path("testRenameToDirWithSamePrefixAllowed");
|
||||||
fs.mkdirs(parentdir);
|
fs.mkdirs(parentdir);
|
||||||
Path dest = path("test/parentdirdest");
|
final Path dest = path("testRenameToDirWithSamePrefixAllowedDest");
|
||||||
rename(parentdir, dest, true, false, true);
|
rename(parentdir, dest, true, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -677,7 +723,7 @@ public void testRenameDirToSelf() throws Throwable {
|
|||||||
if (!renameSupported()) {
|
if (!renameSupported()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Path parentdir = path("test/parentdir");
|
Path parentdir = path("testRenameDirToSelf");
|
||||||
fs.mkdirs(parentdir);
|
fs.mkdirs(parentdir);
|
||||||
Path child = new Path(parentdir, "child");
|
Path child = new Path(parentdir, "child");
|
||||||
createFile(child);
|
createFile(child);
|
||||||
@ -696,7 +742,7 @@ public void testMoveDirUnderParent() throws Throwable {
|
|||||||
if (!renameSupported()) {
|
if (!renameSupported()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Path testdir = path("test/dir");
|
Path testdir = path("testMoveDirUnderParent");
|
||||||
fs.mkdirs(testdir);
|
fs.mkdirs(testdir);
|
||||||
Path parent = testdir.getParent();
|
Path parent = testdir.getParent();
|
||||||
//the outcome here is ambiguous, so is not checked
|
//the outcome here is ambiguous, so is not checked
|
||||||
@ -711,7 +757,7 @@ public void testMoveDirUnderParent() throws Throwable {
|
|||||||
*/
|
*/
|
||||||
public void testRenameFileToSelf() throws Throwable {
|
public void testRenameFileToSelf() throws Throwable {
|
||||||
if (!renameSupported()) return;
|
if (!renameSupported()) return;
|
||||||
Path filepath = path("test/file");
|
Path filepath = path("testRenameFileToSelf");
|
||||||
createFile(filepath);
|
createFile(filepath);
|
||||||
//HDFS expects rename src, src -> true
|
//HDFS expects rename src, src -> true
|
||||||
rename(filepath, filepath, true, true, true);
|
rename(filepath, filepath, true, true, true);
|
||||||
@ -725,7 +771,7 @@ public void testRenameFileToSelf() throws Throwable {
|
|||||||
*/
|
*/
|
||||||
public void testMoveFileUnderParent() throws Throwable {
|
public void testMoveFileUnderParent() throws Throwable {
|
||||||
if (!renameSupported()) return;
|
if (!renameSupported()) return;
|
||||||
Path filepath = path("test/file");
|
Path filepath = path("testMoveFileUnderParent");
|
||||||
createFile(filepath);
|
createFile(filepath);
|
||||||
//HDFS expects rename src, src -> true
|
//HDFS expects rename src, src -> true
|
||||||
rename(filepath, filepath, true, true, true);
|
rename(filepath, filepath, true, true, true);
|
||||||
@ -734,15 +780,23 @@ public void testMoveFileUnderParent() throws Throwable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testLSRootDir() throws Throwable {
|
public void testLSRootDir() throws Throwable {
|
||||||
|
if (!rootDirTestEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Path dir = path("/");
|
Path dir = path("/");
|
||||||
Path child = path("/test");
|
Path child = path("/FileSystemContractBaseTest");
|
||||||
createFile(child);
|
createFile(child);
|
||||||
assertListFilesFinds(dir, child);
|
assertListFilesFinds(dir, child);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testListStatusRootDir() throws Throwable {
|
public void testListStatusRootDir() throws Throwable {
|
||||||
|
if (!rootDirTestEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Path dir = path("/");
|
Path dir = path("/");
|
||||||
Path child = path("/test");
|
Path child = path("/FileSystemContractBaseTest");
|
||||||
createFile(child);
|
createFile(child);
|
||||||
assertListStatusFinds(dir, child);
|
assertListStatusFinds(dir, child);
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,8 @@ public class TestRawLocalFileSystemContract extends FileSystemContractBaseTest {
|
|||||||
|
|
||||||
private static final Logger LOG =
|
private static final Logger LOG =
|
||||||
LoggerFactory.getLogger(TestRawLocalFileSystemContract.class);
|
LoggerFactory.getLogger(TestRawLocalFileSystemContract.class);
|
||||||
|
private final static Path TEST_BASE_DIR =
|
||||||
|
new Path(GenericTestUtils.getTempPath(""));
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
@ -51,21 +53,25 @@ protected boolean renameSupported() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disabling testing root operation.
|
||||||
|
*
|
||||||
|
* Writing to root directory on the local file system may get permission
|
||||||
|
* denied exception, or even worse, delete/overwrite files accidentally.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected boolean rootDirTestEnabled() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDefaultWorkingDirectory() {
|
public String getDefaultWorkingDirectory() {
|
||||||
return fs.getWorkingDirectory().toUri().getPath();
|
return fs.getWorkingDirectory().toUri().getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Path path(String pathString) {
|
protected Path getTestBaseDir() {
|
||||||
// For testWorkingDirectory
|
return TEST_BASE_DIR;
|
||||||
if (pathString.equals(getDefaultWorkingDirectory()) ||
|
|
||||||
pathString.equals(".") || pathString.equals("..")) {
|
|
||||||
return super.path(pathString);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Path(GenericTestUtils.getTempPath(pathString)).
|
|
||||||
makeQualified(fs.getUri(), fs.getWorkingDirectory());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,30 +57,13 @@ public void setUp() throws Exception {
|
|||||||
|
|
||||||
fs = S3ATestUtils.createTestFileSystem(conf);
|
fs = S3ATestUtils.createTestFileSystem(conf);
|
||||||
basePath = fs.makeQualified(
|
basePath = fs.makeQualified(
|
||||||
S3ATestUtils.createTestPath(new Path("/s3afilesystemcontract")));
|
S3ATestUtils.createTestPath(new Path("s3afilesystemcontract")));
|
||||||
super.setUp();
|
super.setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This path explicitly places all absolute paths under the per-test suite
|
|
||||||
* path directory; this allows the test to run in parallel.
|
|
||||||
* @param pathString path string as input
|
|
||||||
* @return a qualified path string.
|
|
||||||
*/
|
|
||||||
protected Path path(String pathString) {
|
|
||||||
if (pathString.startsWith("/")) {
|
|
||||||
return fs.makeQualified(new Path(basePath, pathString));
|
|
||||||
} else {
|
|
||||||
return super.path(pathString);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void tearDown() throws Exception {
|
public Path getTestBaseDir() {
|
||||||
if (fs != null) {
|
return basePath;
|
||||||
fs.delete(basePath, true);
|
|
||||||
}
|
|
||||||
super.tearDown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -94,22 +77,22 @@ public void testRenameDirectoryAsExistingDirectory() throws Exception {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Path src = path("/test/hadoop/dir");
|
Path src = path("testRenameDirectoryAsExisting/dir");
|
||||||
fs.mkdirs(src);
|
fs.mkdirs(src);
|
||||||
createFile(path("/test/hadoop/dir/file1"));
|
createFile(path(src + "/file1"));
|
||||||
createFile(path("/test/hadoop/dir/subdir/file2"));
|
createFile(path(src + "/subdir/file2"));
|
||||||
|
|
||||||
Path dst = path("/test/new/newdir");
|
Path dst = path("testRenameDirectoryAsExistingNew/newdir");
|
||||||
fs.mkdirs(dst);
|
fs.mkdirs(dst);
|
||||||
rename(src, dst, true, false, true);
|
rename(src, dst, true, false, true);
|
||||||
assertFalse("Nested file1 exists",
|
assertFalse("Nested file1 exists",
|
||||||
fs.exists(path("/test/hadoop/dir/file1")));
|
fs.exists(path(src + "/file1")));
|
||||||
assertFalse("Nested file2 exists",
|
assertFalse("Nested file2 exists",
|
||||||
fs.exists(path("/test/hadoop/dir/subdir/file2")));
|
fs.exists(path(src + "/subdir/file2")));
|
||||||
assertTrue("Renamed nested file1 exists",
|
assertTrue("Renamed nested file1 exists",
|
||||||
fs.exists(path("/test/new/newdir/file1")));
|
fs.exists(path(dst + "/file1")));
|
||||||
assertTrue("Renamed nested exists",
|
assertTrue("Renamed nested exists",
|
||||||
fs.exists(path("/test/new/newdir/subdir/file2")));
|
fs.exists(path(dst + "/subdir/file2")));
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
|
Loading…
Reference in New Issue
Block a user