hadoop-mapreduce-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sha...@apache.org
Subject svn commit: r797362 - in /hadoop/mapreduce/trunk: CHANGES.txt src/test/mapred/org/apache/hadoop/mapred/TestUserDefinedCounters.java
Date Fri, 24 Jul 2009 08:39:33 GMT
Author: sharad
Date: Fri Jul 24 08:39:33 2009
New Revision: 797362

URL: http://svn.apache.org/viewvc?rev=797362&view=rev
Log:
MAPREDUCE-784. Modify TestUserDefinedCounters to use LocalJobRunner instead of MiniMR. Contributed
by Jothi Padmanabhan.

Modified:
    hadoop/mapreduce/trunk/CHANGES.txt
    hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapred/TestUserDefinedCounters.java

Modified: hadoop/mapreduce/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/CHANGES.txt?rev=797362&r1=797361&r2=797362&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/CHANGES.txt (original)
+++ hadoop/mapreduce/trunk/CHANGES.txt Fri Jul 24 08:39:33 2009
@@ -135,6 +135,9 @@
     MAPREDUCE-785. Separate sub-test of TestReduceFetch to be included in
     MR-670. (Jothi Padmanabhan via cdouglas)
 
+    MAPREDUCE-784. Modify TestUserDefinedCounters to use LocalJobRunner 
+    instead of MiniMR. (Jothi Padmanabhan via sharad)
+
   BUG FIXES
     MAPREDUCE-703. Sqoop requires dependency on hsqldb in ivy.
     (Aaron Kimball via matei)

Modified: hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapred/TestUserDefinedCounters.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapred/TestUserDefinedCounters.java?rev=797362&r1=797361&r2=797362&view=diff
==============================================================================
--- hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapred/TestUserDefinedCounters.java
(original)
+++ hadoop/mapreduce/trunk/src/test/mapred/org/apache/hadoop/mapred/TestUserDefinedCounters.java
Fri Jul 24 08:39:33 2009
@@ -18,6 +18,7 @@
 package org.apache.hadoop.mapred;
 
 import java.io.BufferedReader;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -25,6 +26,9 @@
 import java.io.OutputStreamWriter;
 import java.io.Writer;
 
+import junit.framework.TestCase;
+
+import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.FileUtil;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.LongWritable;
@@ -32,8 +36,16 @@
 import org.apache.hadoop.mapred.lib.IdentityMapper;
 import org.apache.hadoop.mapred.lib.IdentityReducer;
 
-public class TestUserDefinedCounters extends ClusterMapReduceTestCase {
+public class TestUserDefinedCounters extends TestCase {
   
+  private static String TEST_ROOT_DIR =
+    new File(System.getProperty("test.build.data", "/tmp")).toURI()
+    .toString().replace(' ', '+');
+
+  private final Path INPUT_DIR = new Path(TEST_ROOT_DIR + "/input");
+  private final Path OUTPUT_DIR = new Path(TEST_ROOT_DIR + "/out");
+  private final Path INPUT_FILE = new Path(INPUT_DIR , "inp");
+
   enum EnumCounter { MAP_RECORDS }
   
   static class CountingMapper<K, V> extends IdentityMapper<K, V> {
@@ -48,17 +60,27 @@
 
   }
   
-  public void testMapReduceJob() throws Exception {
-    OutputStream os = getFileSystem().create(new Path(getInputDir(), "text.txt"));
+  private void cleanAndCreateInput(FileSystem fs) throws IOException {
+    fs.delete(INPUT_FILE, true);
+    fs.delete(OUTPUT_DIR, true);
+
+    OutputStream os = fs.create(INPUT_FILE);
+
     Writer wr = new OutputStreamWriter(os);
     wr.write("hello1\n");
     wr.write("hello2\n");
     wr.write("hello3\n");
     wr.write("hello4\n");
     wr.close();
+  }
+
+  public void testMapReduceJob() throws Exception {
 
-    JobConf conf = createJobConf();
-    conf.setJobName("counters");
+    JobConf conf = new JobConf(TestUserDefinedCounters.class);
+    conf.setJobName("UserDefinedCounters");
+    
+    FileSystem fs = FileSystem.get(conf);
+    cleanAndCreateInput(fs);
     
     conf.setInputFormat(TextInputFormat.class);
 
@@ -72,17 +94,16 @@
     conf.setMapperClass(CountingMapper.class);
     conf.setReducerClass(IdentityReducer.class);
 
-    FileInputFormat.setInputPaths(conf, getInputDir());
+    FileInputFormat.setInputPaths(conf, INPUT_DIR);
 
-    FileOutputFormat.setOutputPath(conf, getOutputDir());
+    FileOutputFormat.setOutputPath(conf, OUTPUT_DIR);
 
     RunningJob runningJob = JobClient.runJob(conf);
 
     Path[] outputFiles = FileUtil.stat2Paths(
-                           getFileSystem().listStatus(getOutputDir(),
-                           new OutputLogFilter()));
+        fs.listStatus(OUTPUT_DIR, new OutputLogFilter()));
     if (outputFiles.length > 0) {
-      InputStream is = getFileSystem().open(outputFiles[0]);
+      InputStream is = fs.open(outputFiles[0]);
       BufferedReader reader = new BufferedReader(new InputStreamReader(is));
       String line = reader.readLine();
       int counter = 0;



Mime
View raw message