use of org.apache.hadoop.fs.FileStatus in project hadoop by apache.
the class TestPermission method checkPermission.
static FsPermission checkPermission(FileSystem fs, String path, FsPermission expected) throws IOException {
FileStatus s = fs.getFileStatus(new Path(path));
LOG.info(s.getPath() + ": " + s.isDirectory() + " " + s.getPermission() + ":" + s.getOwner() + ":" + s.getGroup());
if (expected != null) {
assertEquals(expected, s.getPermission());
assertEquals(expected.toShort(), s.getPermission().toShort());
}
return s.getPermission();
}
use of org.apache.hadoop.fs.FileStatus in project hadoop by apache.
the class TestRollingFileSystemSinkWithHdfs method testFlushThread.
/**
* This test specifically checks whether the flusher thread is automatically
* flushing the files. It unfortunately can only test with the alternative
* flushing schedule (because of test timing), but it's better than nothing.
*
* @throws Exception thrown if something breaks
*/
@Test
public void testFlushThread() throws Exception {
// Cause the sink's flush thread to be run immediately after the second
// metrics log is written
RollingFileSystemSink.forceFlush = true;
String path = "hdfs://" + cluster.getNameNode().getHostAndPort() + "/tmp";
MetricsSystem ms = initMetricsSystem(path, true, false, false);
new MyMetrics1().registerWith(ms);
// Publish the metrics
ms.publishMetricsNow();
// Pubish again because the first write seems to get properly flushed
// regardless.
ms.publishMetricsNow();
int count = 0;
try {
// sleep, but the sleep is here to make sure this test isn't flakey.
while (!RollingFileSystemSink.hasFlushed) {
Thread.sleep(10L);
if (++count > 1000) {
fail("Flush thread did not run within 10 seconds");
}
}
Calendar now = Calendar.getInstance();
Path currentDir = new Path(path, DATE_FORMAT.format(now.getTime()) + "00");
FileSystem fs = FileSystem.newInstance(new URI(path), new Configuration());
Path currentFile = findMostRecentLogFile(fs, new Path(currentDir, getLogFilename()));
FileStatus status = fs.getFileStatus(currentFile);
// Each metrics record is 118+ bytes, depending on hostname
assertTrue("The flusher thread didn't flush the log contents. Expected " + "at least 236 bytes in the log file, but got " + status.getLen(), status.getLen() >= 236);
} finally {
RollingFileSystemSink.forceFlush = false;
try {
ms.stop();
} finally {
ms.shutdown();
}
}
}
use of org.apache.hadoop.fs.FileStatus in project hadoop by apache.
the class TestMove method testMoveTargetExistsWithoutExplicitRename.
@Test
public void testMoveTargetExistsWithoutExplicitRename() throws Exception {
Path srcPath = new Path("mockfs:/file");
Path targetPath = new Path("mockfs:/fold0");
Path dupPath = new Path("mockfs:/fold0/file");
Path srcPath2 = new Path("mockfs://user/file");
Path targetPath2 = new Path("mockfs://user/fold0");
Path dupPath2 = new Path("mockfs://user/fold0/file");
InstrumentedRenameCommand cmd;
String[] cmdargs = new String[] { "mockfs:/file", "mockfs:/fold0" };
FileStatus src_fileStat, target_fileStat, dup_fileStat;
URI myuri;
src_fileStat = mock(FileStatus.class);
target_fileStat = mock(FileStatus.class);
dup_fileStat = mock(FileStatus.class);
myuri = new URI("mockfs://user");
when(src_fileStat.isDirectory()).thenReturn(false);
when(target_fileStat.isDirectory()).thenReturn(true);
when(dup_fileStat.isDirectory()).thenReturn(false);
when(src_fileStat.getPath()).thenReturn(srcPath2);
when(target_fileStat.getPath()).thenReturn(targetPath2);
when(dup_fileStat.getPath()).thenReturn(dupPath2);
when(mockFs.getFileStatus(eq(srcPath))).thenReturn(src_fileStat);
when(mockFs.getFileStatus(eq(targetPath))).thenReturn(target_fileStat);
when(mockFs.getFileStatus(eq(dupPath))).thenReturn(dup_fileStat);
when(mockFs.getFileStatus(eq(srcPath2))).thenReturn(src_fileStat);
when(mockFs.getFileStatus(eq(targetPath2))).thenReturn(target_fileStat);
when(mockFs.getFileStatus(eq(dupPath2))).thenReturn(dup_fileStat);
when(mockFs.getUri()).thenReturn(myuri);
cmd = new InstrumentedRenameCommand();
cmd.setConf(conf);
cmd.setOverwrite(true);
cmd.run(cmdargs);
// make sure command failed with the proper exception
assertTrue("Rename should have failed with path exists exception", cmd.error instanceof PathExistsException);
}
use of org.apache.hadoop.fs.FileStatus in project hadoop by apache.
the class AbstractContractGetFileStatusTest method testGetFileStatusNonexistentFile.
@Test
public void testGetFileStatusNonexistentFile() throws Throwable {
try {
FileStatus status = getFileSystem().getFileStatus(target);
//got here: trouble
fail("expected a failure, got " + status);
} catch (FileNotFoundException e) {
//expected
handleExpectedException(e);
}
}
use of org.apache.hadoop.fs.FileStatus in project hadoop by apache.
the class AbstractContractGetFileStatusTest method verifyStatusArrayMatchesFile.
/**
* Verify a returned status array matches a single named file.
* @param f filename
* @param status status array
*/
private void verifyStatusArrayMatchesFile(Path f, FileStatus[] status) {
assertEquals(1, status.length);
FileStatus fileStatus = status[0];
assertIsNamedFile(f, fileStatus);
}
Aggregations