hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ji...@apache.org
Subject svn commit: r1570464 - in /hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common: CHANGES.txt src/test/java/org/apache/hadoop/fs/loadGenerator/LoadGenerator.java
Date Fri, 21 Feb 2014 06:17:59 GMT
Author: jing9
Date: Fri Feb 21 06:17:59 2014
New Revision: 1570464

URL: http://svn.apache.org/r1570464
Log:
HADOOP-10355. Merge change r1570460 from trunk.

Modified:
    hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt
    hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/loadGenerator/LoadGenerator.java

Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1570464&r1=1570463&r2=1570464&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt (original)
+++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt Fri Feb
21 06:17:59 2014
@@ -64,6 +64,8 @@ Release 2.4.0 - UNRELEASED
     HADOOP-10328. loadGenerator exit code is not reliable.
     (Haohui Mai via cnauroth)
 
+    HADOOP-10355. Fix TestLoadGenerator#testLoadGenerator. (Haohui Mai via jing9)
+
 Release 2.3.1 - UNRELEASED
 
   INCOMPATIBLE CHANGES

Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/loadGenerator/LoadGenerator.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/loadGenerator/LoadGenerator.java?rev=1570464&r1=1570463&r2=1570464&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/loadGenerator/LoadGenerator.java
(original)
+++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/loadGenerator/LoadGenerator.java
Fri Feb 21 06:17:59 2014
@@ -45,6 +45,8 @@ import org.apache.hadoop.util.Time;
 import org.apache.hadoop.util.Tool;
 import org.apache.hadoop.util.ToolRunner;
 
+import com.google.common.base.Preconditions;
+
 /** The load generator is a tool for testing NameNode behavior under
  * different client loads.
  * It allows the user to generate different mixes of read, write,
@@ -488,7 +490,35 @@ public class LoadGenerator extends Confi
     
     return initFileDirTables();
   }
-  
+
+  private static void parseScriptLine(String line, ArrayList<Long> duration,
+      ArrayList<Double> readProb, ArrayList<Double> writeProb) {
+    String[] a = line.split("\\s");
+
+    if (a.length != 3) {
+      throw new IllegalArgumentException("Incorrect number of parameters: "
+          + line);
+    }
+
+    try {
+      long d = Long.parseLong(a[0]);
+      double r = Double.parseDouble(a[1]);
+      double w = Double.parseDouble(a[2]);
+
+      Preconditions.checkArgument(d >= 0, "Invalid duration: " + d);
+      Preconditions.checkArgument(0 <= r && r <= 1.0,
+          "The read probability must be [0, 1]: " + r);
+      Preconditions.checkArgument(0 <= w && w <= 1.0,
+          "The read probability must be [0, 1]: " + w);
+
+      readProb.add(r);
+      duration.add(d);
+      writeProb.add(w);
+    } catch (NumberFormatException nfe) {
+      throw new IllegalArgumentException("Cannot parse: " + line);
+    }
+  }
+
   /**
    * Read a script file of the form: lines of text with duration in seconds,
    * read probability and write probability, separated by white space.
@@ -508,47 +538,19 @@ public class LoadGenerator extends Confi
     String line;
     // Read script, parse values, build array of duration, read and write probs
 
-    while ((line = br.readLine()) != null) {
-      lineNum++;
-      if (line.startsWith("#") || line.isEmpty()) // skip comments and blanks
-        continue;
-
-      String[] a = line.split("\\s");
-      if (a.length != 3) {
-        System.err.println("Line " + lineNum
-            + ": Incorrect number of parameters: " + line);
-      }
-
-      try {
-        long d = Long.parseLong(a[0]);
-        if (d < 0) {
-          System.err.println("Line " + lineNum + ": Invalid duration: " + d);
-          return -1;
-        }
-
-        double r = Double.parseDouble(a[1]);
-        if (r < 0.0 || r > 1.0) {
-          System.err.println("Line " + lineNum
-              + ": The read probability must be [0, 1]: " + r);
-          return -1;
-        }
-
-        double w = Double.parseDouble(a[2]);
-        if (w < 0.0 || w > 1.0) {
-          System.err.println("Line " + lineNum
-              + ": The read probability must be [0, 1]: " + r);
-          return -1;
-        }
+    try {
+      while ((line = br.readLine()) != null) {
+        lineNum++;
+        if (line.startsWith("#") || line.isEmpty()) // skip comments and blanks
+          continue;
 
-        readProb.add(r);
-        duration.add(d);
-        writeProb.add(w);
-      } catch (NumberFormatException nfe) {
-        System.err.println(lineNum + ": Can't parse: " + line);
-        return -1;
-      } finally {
-        IOUtils.cleanup(LOG, br);
+        parseScriptLine(line, duration, readProb, writeProb);
       }
+    } catch (IllegalArgumentException e) {
+      System.err.println("Line: " + lineNum + ", " + e.getMessage());
+      return -1;
+    } finally {
+      IOUtils.cleanup(LOG, br);
     }
     
     // Copy vectors to arrays of values, to avoid autoboxing overhead later



Mime
View raw message