Przeglądaj źródła

HADOOP-3224. 'dfs -du /dir' does not return correct size. (Lohit Vjayarenu via rangadi)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.17@646952 13f79535-47bb-0310-9956-ffa450edef68
Raghu Angadi 17 lat temu
rodzic
commit
ddde3fe1c4

+ 3 - 0
CHANGES.txt

@@ -542,6 +542,9 @@ Release 0.17.0 - Unreleased
     HADOOP-3208. Fix WritableDeserializer to set the Configuration on
     deserialized Writables. (Enis Soztutar via cdouglas)
 
+   HADOOP-3224. 'dfs -du /dir' does not return correct size.
+   (Lohit Vjayarenu via rangadi)
+
 Release 0.16.3 - Unreleased
 
   BUG FIXES

+ 3 - 1
src/java/org/apache/hadoop/fs/FsShell.java

@@ -671,7 +671,9 @@ public class FsShell extends Configured implements Tool {
     } else {
       System.out.println("Found " + items.length + " items");
       for (int i = 0; i < items.length; i++) {
-        System.out.println(items[i].getPath() + "\t" + items[i].getLen());
+        System.out.println(items[i].getPath() + "\t" + 
+                           srcFs.getContentSummary(items[i].getPath()).
+                           getLength());
       }
     }
   }

+ 49 - 1
src/test/org/apache/hadoop/dfs/TestDFSShell.java

@@ -134,7 +134,55 @@ public class TestDFSShell extends TestCase {
     }
   }
     
-  
+  public void testDu() throws IOException {
+    Configuration conf = new Configuration();
+    MiniDFSCluster cluster = new MiniDFSCluster(conf, 2, true, null);
+    FileSystem fs = cluster.getFileSystem();
+    assertTrue("Not a HDFS: "+fs.getUri(),
+                fs instanceof DistributedFileSystem);
+    final DistributedFileSystem dfs = (DistributedFileSystem)fs;
+    PrintStream psBackup = System.out;
+    ByteArrayOutputStream out = new ByteArrayOutputStream();
+    PrintStream psOut = new PrintStream(out);
+    System.setOut(psOut);
+    FsShell shell = new FsShell();
+    shell.setConf(conf);
+    
+    try {
+      Path myPath = new Path("/test/dir");
+      assertTrue(fs.mkdirs(myPath));
+      assertTrue(fs.exists(myPath));
+      Path myFile = new Path("/test/dir/file");
+      writeFile(fs, myFile);
+      assertTrue(fs.exists(myFile));
+      Path myFile2 = new Path("/test/dir/file2");
+      writeFile(fs, myFile2);
+      assertTrue(fs.exists(myFile2));
+      
+      String[] args = new String[2];
+      args[0] = "-du";
+      args[1] = "/test/dir";
+      int val = -1;
+      try {
+        val = shell.run(args);
+      } catch (Exception e) {
+        System.err.println("Exception raised from DFSShell.run " +
+                            e.getLocalizedMessage());
+      }
+      assertTrue(val == 0);
+      String returnString = out.toString();
+      out.reset();
+      // Check if size matchs as expected
+      assertTrue(returnString.contains("22"));
+      assertTrue(returnString.contains("23"));
+      
+    } finally {
+      try {dfs.close();} catch (Exception e) {}
+      System.setOut(psBackup);
+      cluster.shutdown();
+    }
+                                  
+  }
   public void testPut() throws IOException {
     Configuration conf = new Configuration();
     MiniDFSCluster cluster = new MiniDFSCluster(conf, 2, true, null);