hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r428088 - /lucene/hadoop/trunk/src/contrib/streaming/src/test/org/apache/hadoop/streaming/TrApp.java
Date Wed, 02 Aug 2006 18:44:45 GMT
Author: cutting
Date: Wed Aug  2 11:44:45 2006
New Revision: 428088

URL: http://svn.apache.org/viewvc?rev=428088&view=rev
Log:
HADOOP-418.  Add unit tests for streaming contrib environment variables.

Modified:
    lucene/hadoop/trunk/src/contrib/streaming/src/test/org/apache/hadoop/streaming/TrApp.java

Modified: lucene/hadoop/trunk/src/contrib/streaming/src/test/org/apache/hadoop/streaming/TrApp.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/streaming/src/test/org/apache/hadoop/streaming/TrApp.java?rev=428088&r1=428087&r2=428088&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/contrib/streaming/src/test/org/apache/hadoop/streaming/TrApp.java
(original)
+++ lucene/hadoop/trunk/src/contrib/streaming/src/test/org/apache/hadoop/streaming/TrApp.java
Wed Aug  2 11:44:45 2006
@@ -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 @@
     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 @@
   }
   char find;
   char replace;
-
+  Environment env;
 }



Mime
View raw message