Explorar o código

HADOOP-5920. Fixes a testcase failure for TestJobHistory. Contributed by Amar Kamat.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@785569 13f79535-47bb-0310-9956-ffa450edef68
Devaraj Das %!s(int64=16) %!d(string=hai) anos
pai
achega
adaa296cc5

+ 3 - 0
CHANGES.txt

@@ -960,6 +960,9 @@ Release 0.20.1 - Unreleased
     (usually HDFS) is started at nearly the same time as the JobTracker. 
     (Amar Kamat via ddas)
 
+    HADOOP-5920. Fixes a testcase failure for TestJobHistory. 
+    (Amar Kamat via ddas)
+
 Release 0.20.0 - 2009-04-15
 
   INCOMPATIBLE CHANGES

+ 7 - 0
src/mapred/org/apache/hadoop/mapred/JobHistory.java

@@ -397,6 +397,13 @@ public class JobHistory {
     JobHistory.disableHistory = disableHistory;
   }
   
+  /**
+   * Get the history location
+   */
+  static Path getJobHistoryLocation() {
+    return new Path(LOG_DIR);
+  } 
+  
   /**
    * Base class contais utility stuff to manage types key value pairs with enums. 
    */

+ 17 - 1
src/test/mapred/org/apache/hadoop/mapred/TestJobHistory.java

@@ -31,6 +31,7 @@ import java.util.regex.Pattern;
 
 import junit.framework.TestCase;
 
+import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.permission.FsPermission;
@@ -813,6 +814,7 @@ public class TestJobHistory extends TestCase {
 
     } finally {
       if (mr != null) {
+        cleanupLocalFiles(mr);
         mr.shutdown();
       }
     }
@@ -855,7 +857,7 @@ public class TestJobHistory extends TestCase {
       assertTrue("User log file " + logFile + " does not exist",
                  fileSys.exists(logFile));
     }
-    else if (conf.get("hadoop.job.history.user.location") == "none") {
+    else if ("none".equals(conf.get("hadoop.job.history.user.location"))) {
       // history file should not exist in the output path
       assertFalse("Unexpected. User log file exists in output dir when " +
                  "hadoop.job.history.user.location is set to \"none\"",
@@ -920,11 +922,24 @@ public class TestJobHistory extends TestCase {
 
     } finally {
       if (mr != null) {
+        cleanupLocalFiles(mr);
         mr.shutdown();
       }
     }
   }
 
+  private void cleanupLocalFiles(MiniMRCluster mr) 
+  throws IOException {
+    Configuration conf = mr.createJobConf();
+    JobTracker jt = mr.getJobTrackerRunner().getJobTracker();
+    Path sysDir = new Path(jt.getSystemDir());
+    FileSystem fs = sysDir.getFileSystem(conf);
+    fs.delete(sysDir, true);
+    Path jobHistoryDir = JobHistory.getJobHistoryLocation();
+    fs = jobHistoryDir.getFileSystem(conf);
+    fs.delete(jobHistoryDir, true);
+  }
+
   /**
    * Checks if the history file has expected job status
    * @param id job id
@@ -1001,6 +1016,7 @@ public class TestJobHistory extends TestCase {
       
     } finally {
       if (mr != null) {
+        cleanupLocalFiles(mr);
         mr.shutdown();
       }
     }