+ " replicas.");
checkFile(fs, file1, 1);
System.out.println("Path : \"" + file1 + "\"");
// test getFileStatus on a file
FileStatus status = fs.getFileStatus(file1);
assertTrue(file1 + " should be a file",
status.isDir() == false);
assertTrue(status.getBlockSize() == blockSize);
assertTrue(status.getReplication() == 1);
assertTrue(status.getLen() == fileSize);
assertEquals(fs.makeQualified(file1).toString(),
status.getPath().toString());
// test getVisbileLen
DFSDataInputStream fin = (DFSDataInputStream)fs.open(file1);
assertEquals(status.getLen(), fin.getVisibleLength());
// test listStatus on a file
FileStatus[] stats = fs.listStatus(file1);
assertEquals(1, stats.length);
status = stats[0];
assertTrue(file1 + " should be a file",
status.isDir() == false);
assertTrue(status.getBlockSize() == blockSize);
assertTrue(status.getReplication() == 1);
assertTrue(status.getLen() == fileSize);
assertEquals(fs.makeQualified(file1).toString(),
status.getPath().toString());
// test file status on a directory
Path dir = new Path("/test/mkdirs");
// test listStatus on a non-existent file/directory
stats = fs.listStatus(dir);
assertEquals(null, stats);
try {
status = fs.getFileStatus(dir);
fail("getFileStatus of non-existent path should fail");
} catch (FileNotFoundException fe) {
assertTrue(fe.getMessage().startsWith("File does not exist"));
}
// create the directory
assertTrue(fs.mkdirs(dir));
assertTrue(fs.exists(dir));
System.out.println("Dir : \"" + dir + "\"");
// test getFileStatus on an empty directory
status = fs.getFileStatus(dir);
assertTrue(dir + " should be a directory", status.isDir());
assertTrue(dir + " should be zero size ", status.getLen() == 0);
assertEquals(fs.makeQualified(dir).toString(),
status.getPath().toString());
// test listStatus on an empty directory
stats = fs.listStatus(dir);
assertEquals(dir + " should be empty", 0, stats.length);
assertEquals(dir + " should be zero size ",
0, fs.getContentSummary(dir).getLength());
assertEquals(dir + " should be zero size using hftp",
0, hftpfs.getContentSummary(dir).getLength());
assertTrue(dir + " should be zero size ",
fs.getFileStatus(dir).getLen() == 0);
System.out.println("Dir : \"" + dir + "\"");
// create another file that is smaller than a block.
//
Path file2 = new Path(dir, "filestatus2.dat");
writeFile(fs, file2, 1, blockSize/4, blockSize);
System.out.println("Created file filestatus2.dat with one "
+ " replicas.");
checkFile(fs, file2, 1);
System.out.println("Path : \"" + file2 + "\"");
// verify file attributes
status = fs.getFileStatus(file2);
assertTrue(status.getBlockSize() == blockSize);
assertTrue(status.getReplication() == 1);
file2 = fs.makeQualified(file2);
assertEquals(file2.toString(), status.getPath().toString());
// create another file in the same directory
Path file3 = new Path(dir, "filestatus3.dat");
writeFile(fs, file3, 1, blockSize/4, blockSize);
System.out.println("Created file filestatus3.dat with one "