HADOOP-10355. Fix TestLoadGenerator#testLoadGenerator. Contributed by Haohui Mai.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1570460 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jing Zhao 2014-02-21 06:09:52 +00:00
parent b00817b54a
commit c316cd6271
2 changed files with 44 additions and 40 deletions

View File

@ -396,6 +396,8 @@ Release 2.4.0 - UNRELEASED
HADOOP-10328. loadGenerator exit code is not reliable. HADOOP-10328. loadGenerator exit code is not reliable.
(Haohui Mai via cnauroth) (Haohui Mai via cnauroth)
HADOOP-10355. Fix TestLoadGenerator#testLoadGenerator. (Haohui Mai via jing9)
Release 2.3.1 - UNRELEASED Release 2.3.1 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -45,6 +45,8 @@ import org.apache.hadoop.util.Time;
import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner; import org.apache.hadoop.util.ToolRunner;
import com.google.common.base.Preconditions;
/** The load generator is a tool for testing NameNode behavior under /** The load generator is a tool for testing NameNode behavior under
* different client loads. * different client loads.
* It allows the user to generate different mixes of read, write, * It allows the user to generate different mixes of read, write,
@ -489,6 +491,34 @@ public class LoadGenerator extends Configured implements Tool {
return initFileDirTables(); 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 a script file of the form: lines of text with duration in seconds,
* read probability and write probability, separated by white space. * read probability and write probability, separated by white space.
@ -508,48 +538,20 @@ public class LoadGenerator extends Configured implements Tool {
String line; String line;
// Read script, parse values, build array of duration, read and write probs // Read script, parse values, build array of duration, read and write probs
try {
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
lineNum++; lineNum++;
if (line.startsWith("#") || line.isEmpty()) // skip comments and blanks if (line.startsWith("#") || line.isEmpty()) // skip comments and blanks
continue; continue;
String[] a = line.split("\\s"); parseScriptLine(line, duration, readProb, writeProb);
if (a.length != 3) {
System.err.println("Line " + lineNum
+ ": Incorrect number of parameters: " + line);
} }
} catch (IllegalArgumentException e) {
try { System.err.println("Line: " + lineNum + ", " + e.getMessage());
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;
}
readProb.add(r);
duration.add(d);
writeProb.add(w);
} catch (NumberFormatException nfe) {
System.err.println(lineNum + ": Can't parse: " + line);
return -1; return -1;
} finally { } finally {
IOUtils.cleanup(LOG, br); IOUtils.cleanup(LOG, br);
} }
}
// Copy vectors to arrays of values, to avoid autoboxing overhead later // Copy vectors to arrays of values, to avoid autoboxing overhead later
durations = new long[duration.size()]; durations = new long[duration.size()];