|
@@ -52,7 +52,8 @@ public class TestLocalFileSystem {
|
|
|
|
|
|
@Before
|
|
|
public void setup() throws IOException {
|
|
|
- conf = new Configuration();
|
|
|
+ conf = new Configuration(false);
|
|
|
+ conf.set("fs.file.impl", LocalFileSystem.class.getName());
|
|
|
fileSys = FileSystem.getLocal(conf);
|
|
|
fileSys.delete(new Path(TEST_ROOT_DIR), true);
|
|
|
}
|
|
@@ -67,7 +68,7 @@ public class TestLocalFileSystem {
|
|
|
/**
|
|
|
* Test the capability of setting the working directory.
|
|
|
*/
|
|
|
- @Test
|
|
|
+ @Test(timeout = 1000)
|
|
|
public void testWorkingDirectory() throws IOException {
|
|
|
Path origDir = fileSys.getWorkingDirectory();
|
|
|
Path subdir = new Path(TEST_ROOT_DIR, "new");
|
|
@@ -121,10 +122,9 @@ public class TestLocalFileSystem {
|
|
|
* test Syncable interface on raw local file system
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- @Test
|
|
|
+ @Test(timeout = 1000)
|
|
|
public void testSyncable() throws IOException {
|
|
|
- Configuration conf = new Configuration();
|
|
|
- FileSystem fs = FileSystem.getLocal(conf).getRawFileSystem();
|
|
|
+ FileSystem fs = fileSys.getRawFileSystem();
|
|
|
Path file = new Path(TEST_ROOT_DIR, "syncable");
|
|
|
FSDataOutputStream out = fs.create(file);;
|
|
|
final int bytesWritten = 1;
|
|
@@ -155,76 +155,68 @@ public class TestLocalFileSystem {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
+ @Test(timeout = 1000)
|
|
|
public void testCopy() throws IOException {
|
|
|
- Configuration conf = new Configuration();
|
|
|
- LocalFileSystem fs = FileSystem.getLocal(conf);
|
|
|
Path src = new Path(TEST_ROOT_DIR, "dingo");
|
|
|
Path dst = new Path(TEST_ROOT_DIR, "yak");
|
|
|
- writeFile(fs, src, 1);
|
|
|
- assertTrue(FileUtil.copy(fs, src, fs, dst, true, false, conf));
|
|
|
- assertTrue(!fs.exists(src) && fs.exists(dst));
|
|
|
- assertTrue(FileUtil.copy(fs, dst, fs, src, false, false, conf));
|
|
|
- assertTrue(fs.exists(src) && fs.exists(dst));
|
|
|
- assertTrue(FileUtil.copy(fs, src, fs, dst, true, true, conf));
|
|
|
- assertTrue(!fs.exists(src) && fs.exists(dst));
|
|
|
- fs.mkdirs(src);
|
|
|
- assertTrue(FileUtil.copy(fs, dst, fs, src, false, false, conf));
|
|
|
+ writeFile(fileSys, src, 1);
|
|
|
+ assertTrue(FileUtil.copy(fileSys, src, fileSys, dst, true, false, conf));
|
|
|
+ assertTrue(!fileSys.exists(src) && fileSys.exists(dst));
|
|
|
+ assertTrue(FileUtil.copy(fileSys, dst, fileSys, src, false, false, conf));
|
|
|
+ assertTrue(fileSys.exists(src) && fileSys.exists(dst));
|
|
|
+ assertTrue(FileUtil.copy(fileSys, src, fileSys, dst, true, true, conf));
|
|
|
+ assertTrue(!fileSys.exists(src) && fileSys.exists(dst));
|
|
|
+ fileSys.mkdirs(src);
|
|
|
+ assertTrue(FileUtil.copy(fileSys, dst, fileSys, src, false, false, conf));
|
|
|
Path tmp = new Path(src, dst.getName());
|
|
|
- assertTrue(fs.exists(tmp) && fs.exists(dst));
|
|
|
- assertTrue(FileUtil.copy(fs, dst, fs, src, false, true, conf));
|
|
|
- assertTrue(fs.delete(tmp, true));
|
|
|
- fs.mkdirs(tmp);
|
|
|
+ assertTrue(fileSys.exists(tmp) && fileSys.exists(dst));
|
|
|
+ assertTrue(FileUtil.copy(fileSys, dst, fileSys, src, false, true, conf));
|
|
|
+ assertTrue(fileSys.delete(tmp, true));
|
|
|
+ fileSys.mkdirs(tmp);
|
|
|
try {
|
|
|
- FileUtil.copy(fs, dst, fs, src, true, true, conf);
|
|
|
+ FileUtil.copy(fileSys, dst, fileSys, src, true, true, conf);
|
|
|
fail("Failed to detect existing dir");
|
|
|
} catch (IOException e) {
|
|
|
// Expected
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
+ @Test(timeout = 1000)
|
|
|
public void testHomeDirectory() throws IOException {
|
|
|
- Configuration conf = new Configuration();
|
|
|
- FileSystem fileSys = FileSystem.getLocal(conf);
|
|
|
Path home = new Path(System.getProperty("user.home"))
|
|
|
.makeQualified(fileSys);
|
|
|
Path fsHome = fileSys.getHomeDirectory();
|
|
|
assertEquals(home, fsHome);
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
+ @Test(timeout = 1000)
|
|
|
public void testPathEscapes() throws IOException {
|
|
|
- Configuration conf = new Configuration();
|
|
|
- FileSystem fs = FileSystem.getLocal(conf);
|
|
|
Path path = new Path(TEST_ROOT_DIR, "foo%bar");
|
|
|
- writeFile(fs, path, 1);
|
|
|
- FileStatus status = fs.getFileStatus(path);
|
|
|
- assertEquals(path.makeQualified(fs), status.getPath());
|
|
|
- cleanupFile(fs, path);
|
|
|
+ writeFile(fileSys, path, 1);
|
|
|
+ FileStatus status = fileSys.getFileStatus(path);
|
|
|
+ assertEquals(path.makeQualified(fileSys), status.getPath());
|
|
|
+ cleanupFile(fileSys, path);
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
+ @Test(timeout = 1000)
|
|
|
public void testMkdirs() throws IOException {
|
|
|
- Configuration conf = new Configuration();
|
|
|
- LocalFileSystem fs = FileSystem.getLocal(conf);
|
|
|
Path test_dir = new Path(TEST_ROOT_DIR, "test_dir");
|
|
|
Path test_file = new Path(TEST_ROOT_DIR, "file1");
|
|
|
- assertTrue(fs.mkdirs(test_dir));
|
|
|
+ assertTrue(fileSys.mkdirs(test_dir));
|
|
|
|
|
|
- writeFile(fs, test_file, 1);
|
|
|
+ writeFile(fileSys, test_file, 1);
|
|
|
// creating dir over a file
|
|
|
Path bad_dir = new Path(test_file, "another_dir");
|
|
|
|
|
|
try {
|
|
|
- fs.mkdirs(bad_dir);
|
|
|
+ fileSys.mkdirs(bad_dir);
|
|
|
fail("Failed to detect existing file in path");
|
|
|
} catch (FileAlreadyExistsException e) {
|
|
|
// Expected
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- fs.mkdirs(null);
|
|
|
+ fileSys.mkdirs(null);
|
|
|
fail("Failed to detect null in mkdir arg");
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
// Expected
|
|
@@ -232,26 +224,23 @@ public class TestLocalFileSystem {
|
|
|
}
|
|
|
|
|
|
/** Test deleting a file, directory, and non-existent path */
|
|
|
- @Test
|
|
|
+ @Test(timeout = 1000)
|
|
|
public void testBasicDelete() throws IOException {
|
|
|
- Configuration conf = new Configuration();
|
|
|
- LocalFileSystem fs = FileSystem.getLocal(conf);
|
|
|
Path dir1 = new Path(TEST_ROOT_DIR, "dir1");
|
|
|
Path file1 = new Path(TEST_ROOT_DIR, "file1");
|
|
|
Path file2 = new Path(TEST_ROOT_DIR+"/dir1", "file2");
|
|
|
Path file3 = new Path(TEST_ROOT_DIR, "does-not-exist");
|
|
|
- assertTrue(fs.mkdirs(dir1));
|
|
|
- writeFile(fs, file1, 1);
|
|
|
- writeFile(fs, file2, 1);
|
|
|
+ assertTrue(fileSys.mkdirs(dir1));
|
|
|
+ writeFile(fileSys, file1, 1);
|
|
|
+ writeFile(fileSys, file2, 1);
|
|
|
assertFalse("Returned true deleting non-existant path",
|
|
|
- fs.delete(file3));
|
|
|
- assertTrue("Did not delete file", fs.delete(file1));
|
|
|
- assertTrue("Did not delete non-empty dir", fs.delete(dir1));
|
|
|
+ fileSys.delete(file3));
|
|
|
+ assertTrue("Did not delete file", fileSys.delete(file1));
|
|
|
+ assertTrue("Did not delete non-empty dir", fileSys.delete(dir1));
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
+ @Test(timeout = 1000)
|
|
|
public void testStatistics() throws Exception {
|
|
|
- FileSystem.getLocal(new Configuration());
|
|
|
int fileSchemeCount = 0;
|
|
|
for (Statistics stats : FileSystem.getAllStatistics()) {
|
|
|
if (stats.getScheme().equals("file")) {
|
|
@@ -261,12 +250,10 @@ public class TestLocalFileSystem {
|
|
|
assertEquals(1, fileSchemeCount);
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
+ @Test(timeout = 1000)
|
|
|
public void testHasFileDescriptor() throws IOException {
|
|
|
- Configuration conf = new Configuration();
|
|
|
- LocalFileSystem fs = FileSystem.getLocal(conf);
|
|
|
Path path = new Path(TEST_ROOT_DIR, "test-file");
|
|
|
- writeFile(fs, path, 1);
|
|
|
+ writeFile(fileSys, path, 1);
|
|
|
BufferedFSInputStream bis = null;
|
|
|
try {
|
|
|
bis = new BufferedFSInputStream(new RawLocalFileSystem()
|
|
@@ -277,20 +264,18 @@ public class TestLocalFileSystem {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
+ @Test(timeout = 1000)
|
|
|
public void testListStatusWithColons() throws IOException {
|
|
|
assumeTrue(!Shell.WINDOWS);
|
|
|
- Configuration conf = new Configuration();
|
|
|
- LocalFileSystem fs = FileSystem.getLocal(conf);
|
|
|
File colonFile = new File(TEST_ROOT_DIR, "foo:bar");
|
|
|
colonFile.mkdirs();
|
|
|
- FileStatus[] stats = fs.listStatus(new Path(TEST_ROOT_DIR));
|
|
|
+ FileStatus[] stats = fileSys.listStatus(new Path(TEST_ROOT_DIR));
|
|
|
assertEquals("Unexpected number of stats", 1, stats.length);
|
|
|
assertEquals("Bad path from stat", colonFile.getAbsolutePath(),
|
|
|
stats[0].getPath().toUri().getPath());
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
+ @Test(timeout = 1000)
|
|
|
public void testReportChecksumFailure() throws IOException {
|
|
|
base.mkdirs();
|
|
|
assertTrue(base.exists() && base.isDirectory());
|
|
@@ -363,4 +348,23 @@ public class TestLocalFileSystem {
|
|
|
assertTrue(checksumFileFound);
|
|
|
}
|
|
|
|
|
|
+ @Test(timeout = 1000)
|
|
|
+ public void testSetTimes() throws Exception {
|
|
|
+ Path path = new Path(TEST_ROOT_DIR, "set-times");
|
|
|
+ writeFile(fileSys, path, 1);
|
|
|
+
|
|
|
+ // test only to the nearest second, as the raw FS may not
|
|
|
+ // support millisecond timestamps
|
|
|
+ long newModTime = 12345000;
|
|
|
+
|
|
|
+ FileStatus status = fileSys.getFileStatus(path);
|
|
|
+ assertTrue("check we're actually changing something", newModTime != status.getModificationTime());
|
|
|
+ assertEquals(0, status.getAccessTime());
|
|
|
+
|
|
|
+ fileSys.setTimes(path, newModTime, -1);
|
|
|
+ status = fileSys.getFileStatus(path);
|
|
|
+ assertEquals(newModTime, status.getModificationTime());
|
|
|
+ assertEquals(0, status.getAccessTime());
|
|
|
+}
|
|
|
+
|
|
|
}
|