Browse Source

MAPREDUCE-745. Fixes a testcase problem to do with generation of JobTracker IDs. Contributed by Amar Kamat.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20@806173 13f79535-47bb-0310-9956-ffa450edef68
Devaraj Das 16 years ago
parent
commit
f503b3c084

+ 3 - 0
CHANGES.txt

@@ -218,6 +218,9 @@ Release 0.20.1 - Unreleased
     MAPREDUCE-832. Reduce number of warning messages printed when 
     deprecated memory variables are used. (Rahul Kumar Singh via yhemanth)
  
+    MAPREDUCE-745. Fixes a testcase problem to do with generation of JobTracker
+    IDs. (Amar Kamat via ddas)
+
 Release 0.20.0 - 2009-04-15
 
   INCOMPATIBLE CHANGES

+ 16 - 2
src/mapred/org/apache/hadoop/mapred/JobTracker.java

@@ -169,10 +169,15 @@ public class JobTracker implements MRConstants, InterTrackerProtocol,
   public static JobTracker startTracker(JobConf conf
                                         ) throws IOException,
                                                  InterruptedException {
+    return startTracker(conf, generateNewIdentifier());
+  }
+  
+  public static JobTracker startTracker(JobConf conf, String identifier) 
+  throws IOException, InterruptedException {
     JobTracker result = null;
     while (true) {
       try {
-        result = new JobTracker(conf);
+        result = new JobTracker(conf, identifier);
         result.taskScheduler.setTaskTrackerManager(result);
         break;
       } catch (VersionMismatch e) {
@@ -1522,6 +1527,11 @@ public class JobTracker implements MRConstants, InterTrackerProtocol,
    * Start the JobTracker process, listen on the indicated port
    */
   JobTracker(JobConf conf) throws IOException, InterruptedException {
+    this(conf, generateNewIdentifier());
+  }
+  
+  JobTracker(JobConf conf, String identifier) 
+  throws IOException, InterruptedException {   
     //
     // Grab some static constants
     //
@@ -1610,7 +1620,7 @@ public class JobTracker implements MRConstants, InterTrackerProtocol,
     infoServer.addServlet("reducegraph", "/taskgraph", TaskGraphServlet.class);
     infoServer.start();
     
-    trackerIdentifier = getDateFormat().format(new Date());
+    this.trackerIdentifier = identifier;
 
     // Initialize instrumentation
     JobTrackerInstrumentation tmp;
@@ -1719,6 +1729,10 @@ public class JobTracker implements MRConstants, InterTrackerProtocol,
     return new SimpleDateFormat("yyyyMMddHHmm");
   }
 
+  private static String generateNewIdentifier() {
+    return getDateFormat().format(new Date());
+  }
+  
   static boolean validateIdentifier(String id) {
     try {
       // the jobtracker id should be 'date' parseable

+ 12 - 1
src/test/org/apache/hadoop/mapred/MiniMRCluster.java

@@ -19,7 +19,9 @@ package org.apache.hadoop.mapred;
 
 import java.io.File;
 import java.io.IOException;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 
@@ -99,7 +101,9 @@ public class MiniMRCluster {
         jc.set("mapred.local.dir",f.getAbsolutePath());
         jc.setClass("topology.node.switch.mapping.impl", 
             StaticMapping.class, DNSToSwitchMapping.class);
-        tracker = JobTracker.startTracker(jc);
+        String id = 
+          new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
+        tracker = JobTracker.startTracker(jc, id);
         tracker.offerService();
       } catch (Throwable e) {
         LOG.error("Job tracker crashed", e);
@@ -312,6 +316,13 @@ public class MiniMRCluster {
     if(conf == null) {
       conf = new JobConf();
     }
+    return configureJobConf(conf, namenode, jobTrackerPort, jobTrackerInfoPort, 
+                            ugi);
+  }
+  
+  static JobConf configureJobConf(JobConf conf, String namenode, 
+                                  int jobTrackerPort, int jobTrackerInfoPort, 
+                                  UnixUserGroupInformation ugi) {
     JobConf result = new JobConf(conf);
     FileSystem.setDefaultUri(result, namenode);
     result.set("mapred.job.tracker", "localhost:"+jobTrackerPort);

+ 43 - 0
src/test/org/apache/hadoop/mapred/TestJobTrackerStart.java

@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.mapred;
+
+import junit.framework.TestCase;
+
+/**
+ * Test {@link JobTracker} w.r.t config parameters.
+ */
+public class TestJobTrackerStart extends TestCase {
+  
+  public void testJobTrackerStartConfig() throws Exception {
+    JobConf conf = new JobConf();
+    conf = MiniMRCluster.configureJobConf(conf, "file:///", 0, 0, null);
+    
+    // test with default values
+    JobTracker jt = JobTracker.startTracker(conf);
+    // test identifier
+    assertEquals(12, jt.getTrackerIdentifier().length()); // correct upto mins
+    jt.stopTracker();
+    
+    // test with special identifier
+    String identifier = "test-identifier";
+    jt = JobTracker.startTracker(conf, identifier);
+    assertEquals(identifier, jt.getTrackerIdentifier());
+    jt.stopTracker();
+  }
+}