HADOOP-11657. Align the output of hadoop fs -du
to be more Unix-like. (aajisaka)
This commit is contained in:
parent
e9ac88aac7
commit
30e73ebc77
@ -13,6 +13,9 @@ Trunk (Unreleased)
|
||||
|
||||
HADOOP-10950. rework heap management vars (John Smith via aw)
|
||||
|
||||
HADOOP-11657. Align the output of `hadoop fs -du` to be more Unix-like.
|
||||
(aajisaka)
|
||||
|
||||
NEW FEATURES
|
||||
|
||||
HADOOP-6590. Add a username check for hadoop sub-commands (John Smith via aw)
|
||||
|
@ -132,15 +132,23 @@ protected void processOptions(LinkedList<String> args) throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processPathArgument(PathData item) throws IOException {
|
||||
protected void processArguments(LinkedList<PathData> args)
|
||||
throws IOException {
|
||||
usagesTable = new TableBuilder(3);
|
||||
super.processArguments(args);
|
||||
if (!usagesTable.isEmpty()) {
|
||||
usagesTable.printToStream(out);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processPathArgument(PathData item) throws IOException {
|
||||
// go one level deep on dirs from cmdline unless in summary mode
|
||||
if (!summary && item.stat.isDirectory()) {
|
||||
recursePath(item);
|
||||
} else {
|
||||
super.processPathArgument(item);
|
||||
}
|
||||
usagesTable.printToStream(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -95,6 +95,14 @@ static Path writeFile(FileSystem fs, Path f) throws IOException {
|
||||
return f;
|
||||
}
|
||||
|
||||
static Path writeByte(FileSystem fs, Path f) throws IOException {
|
||||
DataOutputStream out = fs.create(f);
|
||||
out.writeByte(1);
|
||||
out.close();
|
||||
assertTrue(fs.exists(f));
|
||||
return f;
|
||||
}
|
||||
|
||||
static Path mkdir(FileSystem fs, Path p) throws IOException {
|
||||
assertTrue(fs.mkdirs(p));
|
||||
assertTrue(fs.exists(p));
|
||||
@ -272,6 +280,27 @@ public void testDu() throws IOException {
|
||||
Long combinedDiskUsed = myFileDiskUsed + myFile2DiskUsed;
|
||||
assertThat(returnString, containsString(combinedLength.toString()));
|
||||
assertThat(returnString, containsString(combinedDiskUsed.toString()));
|
||||
|
||||
// Check if output is rendered properly with multiple input paths
|
||||
Path myFile3 = new Path("/test/dir/file3");
|
||||
writeByte(fs, myFile3);
|
||||
assertTrue(fs.exists(myFile3));
|
||||
args = new String[3];
|
||||
args[0] = "-du";
|
||||
args[1] = "/test/dir/file3";
|
||||
args[2] = "/test/dir/file2";
|
||||
val = -1;
|
||||
try {
|
||||
val = shell.run(args);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Exception raised from DFSShell.run " +
|
||||
e.getLocalizedMessage());
|
||||
}
|
||||
assertEquals("Return code should be 0.", 0, val);
|
||||
returnString = out.toString();
|
||||
out.reset();
|
||||
assertTrue(returnString.contains("1 2 /test/dir/file3"));
|
||||
assertTrue(returnString.contains("23 46 /test/dir/file2"));
|
||||
} finally {
|
||||
System.setOut(psBackup);
|
||||
cluster.shutdown();
|
||||
|
Loading…
Reference in New Issue
Block a user