You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ra...@apache.org on 2008/04/10 22:48:07 UTC

svn commit: r646952 - in /hadoop/core/branches/branch-0.17: CHANGES.txt src/java/org/apache/hadoop/fs/FsShell.java src/test/org/apache/hadoop/dfs/TestDFSShell.java

Author: rangadi
Date: Thu Apr 10 13:48:05 2008
New Revision: 646952

URL: http://svn.apache.org/viewvc?rev=646952&view=rev
Log:
 HADOOP-3224. 'dfs -du /dir' does not return correct size. (Lohit Vjayarenu via rangadi)

Modified:
    hadoop/core/branches/branch-0.17/CHANGES.txt
    hadoop/core/branches/branch-0.17/src/java/org/apache/hadoop/fs/FsShell.java
    hadoop/core/branches/branch-0.17/src/test/org/apache/hadoop/dfs/TestDFSShell.java

Modified: hadoop/core/branches/branch-0.17/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.17/CHANGES.txt?rev=646952&r1=646951&r2=646952&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.17/CHANGES.txt (original)
+++ hadoop/core/branches/branch-0.17/CHANGES.txt Thu Apr 10 13:48:05 2008
@@ -542,6 +542,9 @@
     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

Modified: hadoop/core/branches/branch-0.17/src/java/org/apache/hadoop/fs/FsShell.java
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.17/src/java/org/apache/hadoop/fs/FsShell.java?rev=646952&r1=646951&r2=646952&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.17/src/java/org/apache/hadoop/fs/FsShell.java (original)
+++ hadoop/core/branches/branch-0.17/src/java/org/apache/hadoop/fs/FsShell.java Thu Apr 10 13:48:05 2008
@@ -671,7 +671,9 @@
     } 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());
       }
     }
   }

Modified: hadoop/core/branches/branch-0.17/src/test/org/apache/hadoop/dfs/TestDFSShell.java
URL: http://svn.apache.org/viewvc/hadoop/core/branches/branch-0.17/src/test/org/apache/hadoop/dfs/TestDFSShell.java?rev=646952&r1=646951&r2=646952&view=diff
==============================================================================
--- hadoop/core/branches/branch-0.17/src/test/org/apache/hadoop/dfs/TestDFSShell.java (original)
+++ hadoop/core/branches/branch-0.17/src/test/org/apache/hadoop/dfs/TestDFSShell.java Thu Apr 10 13:48:05 2008
@@ -134,7 +134,55 @@
     }
   }
     
-  
+  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);