|
@@ -17,6 +17,8 @@
|
|
|
package org.apache.hadoop.streaming;
|
|
|
|
|
|
import java.io.*;
|
|
|
+import java.util.*;
|
|
|
+import org.apache.hadoop.streaming.Environment;
|
|
|
|
|
|
/** A minimal Java implementation of /usr/bin/tr.
|
|
|
Used to test the usage of external applications without adding
|
|
@@ -31,8 +33,68 @@ public class TrApp
|
|
|
this.replace = replace;
|
|
|
}
|
|
|
|
|
|
+ void testParentJobConfToEnvVars() throws IOException
|
|
|
+ {
|
|
|
+ env = new Environment();
|
|
|
+
|
|
|
+ /* To get some ideas of stable env.vars:
|
|
|
+ Enumeration it = env.keys();
|
|
|
+ while(it.hasMoreElements()) {
|
|
|
+ String key = (String)it.nextElement();
|
|
|
+ String val = (String)env.get(key);
|
|
|
+ System.out.println("@@@" + key + "=" + val);
|
|
|
+ }
|
|
|
+ */
|
|
|
+
|
|
|
+ // test that some JobConf properties are exposed as expected
|
|
|
+ // Note the dots translated to underscore:
|
|
|
+ // property names have been escaped in PipeMapRed.safeEnvVarName()
|
|
|
+ expect("mapred_input_format_class", "org.apache.hadoop.streaming.StreamInputFormat");
|
|
|
+ expect("mapred_job_tracker", "local");
|
|
|
+ expect("mapred_input_key_class", "org.apache.hadoop.io.UTF8");
|
|
|
+ expect("mapred_input_value_class", "org.apache.hadoop.io.UTF8");
|
|
|
+ expect("mapred_local_dir", "build/test/mapred/local");
|
|
|
+ expect("mapred_output_format_class", "org.apache.hadoop.streaming.StreamOutputFormat");
|
|
|
+ expect("mapred_output_key_class", "org.apache.hadoop.io.UTF8");
|
|
|
+ expect("mapred_output_value_class", "org.apache.hadoop.io.UTF8");
|
|
|
+
|
|
|
+ expect("mapred_task_is_map", "true");
|
|
|
+ expect("mapred_reduce_tasks", "1");
|
|
|
+ expectDefined("mapred_task_id");
|
|
|
+
|
|
|
+ expectDefined("map_input_file");
|
|
|
+ expect("map_input_start", "0");
|
|
|
+ expectDefined("map_input_length");
|
|
|
+
|
|
|
+ expectDefined("io_sort_factor");
|
|
|
+
|
|
|
+ // the FileSplit context properties are not available in local hadoop..
|
|
|
+ // so can't check them in this test.
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // this runs in a subprocess; won't use JUnit's assertTrue()
|
|
|
+ void expect(String evName, String evVal) throws IOException
|
|
|
+ {
|
|
|
+ String got = env.getProperty(evName);
|
|
|
+ if(! evVal.equals(got)) {
|
|
|
+ String msg = "FAIL evName=" + evName + " got=" + got + " expect=" + evVal;
|
|
|
+ throw new IOException(msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void expectDefined(String evName) throws IOException
|
|
|
+ {
|
|
|
+ String got = env.getProperty(evName);
|
|
|
+ if(got == null) {
|
|
|
+ String msg = "FAIL evName=" + evName + " is undefined. Expect defined.";
|
|
|
+ throw new IOException(msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void go() throws IOException
|
|
|
{
|
|
|
+ testParentJobConfToEnvVars();
|
|
|
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
|
|
String line;
|
|
|
|
|
@@ -60,5 +122,5 @@ public class TrApp
|
|
|
}
|
|
|
char find;
|
|
|
char replace;
|
|
|
-
|
|
|
+ Environment env;
|
|
|
}
|