hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r781268 - in /hadoop/core/trunk: CHANGES.txt src/test/mapred/org/apache/hadoop/mapred/TestJavaSerialization.java
Date Wed, 03 Jun 2009 05:43:19 GMT
Author: ddas
Date: Wed Jun  3 05:43:19 2009
New Revision: 781268

URL: http://svn.apache.org/viewvc?rev=781268&view=rev
Log:
HADOOP-5948. Changes TestJavaSerialization to use LocalJobRunner instead of MiniMR/DFS cluster.
Contributed by Jothi Padmanabhan.

Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/test/mapred/org/apache/hadoop/mapred/TestJavaSerialization.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=781268&r1=781267&r2=781268&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Wed Jun  3 05:43:19 2009
@@ -420,6 +420,9 @@
     HADOOP-5955. Changes TestFileOuputFormat so that is uses LOCAL_MR
     instead of CLUSTER_MR. (Jothi Padmanabhan via das)
 
+    HADOOP-5948. Changes TestJavaSerialization to use LocalJobRunner 
+    instead of MiniMR/DFS cluster. (Jothi Padmanabhan via das)
+
   OPTIMIZATIONS
 
     HADOOP-5595. NameNode does not need to run a replicator to choose a

Modified: hadoop/core/trunk/src/test/mapred/org/apache/hadoop/mapred/TestJavaSerialization.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/mapred/org/apache/hadoop/mapred/TestJavaSerialization.java?rev=781268&r1=781267&r2=781268&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/mapred/org/apache/hadoop/mapred/TestJavaSerialization.java
(original)
+++ hadoop/core/trunk/src/test/mapred/org/apache/hadoop/mapred/TestJavaSerialization.java
Wed Jun  3 05:43:19 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;
@@ -27,14 +28,25 @@
 import java.util.Iterator;
 import java.util.StringTokenizer;
 
+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;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.io.serializer.JavaSerializationComparator;
 
-public class TestJavaSerialization extends ClusterMapReduceTestCase {
-  
+public class TestJavaSerialization 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");
+
   static class WordCountMapper extends MapReduceBase implements
       Mapper<LongWritable, Text, String, Long> {
 
@@ -64,17 +76,26 @@
     }
     
   }
-  
-  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("b a\n");
     wr.close();
+  }
+  
+  public void testMapReduceJob() throws Exception {
 
-    JobConf conf = createJobConf();
+    JobConf conf = new JobConf(TestJavaSerialization.class);
     conf.setJobName("JavaSerialization");
     
+    FileSystem fs = FileSystem.get(conf);
+    cleanAndCreateInput(fs);
+
     conf.set("io.serializations",
     "org.apache.hadoop.io.serializer.JavaSerialization," +
     "org.apache.hadoop.io.serializer.WritableSerialization");
@@ -88,17 +109,16 @@
     conf.setMapperClass(WordCountMapper.class);
     conf.setReducerClass(SumReducer.class);
 
-    FileInputFormat.setInputPaths(conf, getInputDir());
+    FileInputFormat.setInputPaths(conf, INPUT_DIR);
 
-    FileOutputFormat.setOutputPath(conf, getOutputDir());
+    FileOutputFormat.setOutputPath(conf, OUTPUT_DIR);
 
     JobClient.runJob(conf);
 
     Path[] outputFiles = FileUtil.stat2Paths(
-                           getFileSystem().listStatus(getOutputDir(),
-                           new OutputLogFilter()));
+        fs.listStatus(OUTPUT_DIR, new OutputLogFilter()));
     assertEquals(1, outputFiles.length);
-    InputStream is = getFileSystem().open(outputFiles[0]);
+    InputStream is = fs.open(outputFiles[0]);
     BufferedReader reader = new BufferedReader(new InputStreamReader(is));
     assertEquals("a\t1", reader.readLine());
     assertEquals("b\t1", reader.readLine());
@@ -108,27 +128,25 @@
 
   /**
    * HADOOP-4466:
-   * This test verifies the JavSerialization impl can write to SequenceFiles. by virtue other
-   * SequenceFileOutputFormat is not coupled to Writable types, if so, the job will fail.
+   * This test verifies the JavSerialization impl can write to
+   * SequenceFiles. by virtue other SequenceFileOutputFormat is not 
+   * coupled to Writable types, if so, the job will fail.
    *
    */
   public void testWriteToSequencefile() throws Exception {
-    OutputStream os = getFileSystem().create(new Path(getInputDir(),
-        "text.txt"));
-    Writer wr = new OutputStreamWriter(os);
-    wr.write("b a\n");
-    wr.close();
-
-    JobConf conf = createJobConf();
+    JobConf conf = new JobConf(TestJavaSerialization.class);
     conf.setJobName("JavaSerialization");
 
+    FileSystem fs = FileSystem.get(conf);
+    cleanAndCreateInput(fs);
+
     conf.set("io.serializations",
     "org.apache.hadoop.io.serializer.JavaSerialization," +
     "org.apache.hadoop.io.serializer.WritableSerialization");
 
     conf.setInputFormat(TextInputFormat.class);
-    conf.setOutputFormat(SequenceFileOutputFormat.class); // test we can write to sequence
files
-
+    // test we can write to sequence files
+    conf.setOutputFormat(SequenceFileOutputFormat.class); 
     conf.setOutputKeyClass(String.class);
     conf.setOutputValueClass(Long.class);
     conf.setOutputKeyComparatorClass(JavaSerializationComparator.class);
@@ -136,16 +154,15 @@
     conf.setMapperClass(WordCountMapper.class);
     conf.setReducerClass(SumReducer.class);
 
-    FileInputFormat.setInputPaths(conf, getInputDir());
+    FileInputFormat.setInputPaths(conf, INPUT_DIR);
 
-    FileOutputFormat.setOutputPath(conf, getOutputDir());
+    FileOutputFormat.setOutputPath(conf, OUTPUT_DIR);
 
     JobClient.runJob(conf);
 
     Path[] outputFiles = FileUtil.stat2Paths(
-                           getFileSystem().listStatus(getOutputDir(),
-                           new OutputLogFilter()));
+        fs.listStatus(OUTPUT_DIR, new OutputLogFilter()));
     assertEquals(1, outputFiles.length);
-}
+  }
 
 }



Mime
View raw message