Author: ddas Date: Thu Aug 20 13:50:05 2009 New Revision: 806173 URL: http://svn.apache.org/viewvc?rev=806173&view=rev Log: MAPREDUCE-745. Fixes a testcase problem to do with generation of JobTracker IDs. Contributed by Amar Kamat.
Added: hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/mapred/TestJobTrackerStart.java Modified: hadoop/common/branches/branch-0.20/CHANGES.txt hadoop/common/branches/branch-0.20/src/mapred/org/apache/hadoop/mapred/JobTracker.java hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/mapred/MiniMRCluster.java Modified: hadoop/common/branches/branch-0.20/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20/CHANGES.txt?rev=806173&r1=806172&r2=806173&view=diff ============================================================================== --- hadoop/common/branches/branch-0.20/CHANGES.txt (original) +++ hadoop/common/branches/branch-0.20/CHANGES.txt Thu Aug 20 13:50:05 2009 @@ -218,6 +218,9 @@ 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 Modified: hadoop/common/branches/branch-0.20/src/mapred/org/apache/hadoop/mapred/JobTracker.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20/src/mapred/org/apache/hadoop/mapred/JobTracker.java?rev=806173&r1=806172&r2=806173&view=diff ============================================================================== --- hadoop/common/branches/branch-0.20/src/mapred/org/apache/hadoop/mapred/JobTracker.java (original) +++ hadoop/common/branches/branch-0.20/src/mapred/org/apache/hadoop/mapred/JobTracker.java Thu Aug 20 13:50:05 2009 @@ -169,10 +169,15 @@ 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 @@ * 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 @@ infoServer.addServlet("reducegraph", "/taskgraph", TaskGraphServlet.class); infoServer.start(); - trackerIdentifier = getDateFormat().format(new Date()); + this.trackerIdentifier = identifier; // Initialize instrumentation JobTrackerInstrumentation tmp; @@ -1719,6 +1729,10 @@ 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 Modified: hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/mapred/MiniMRCluster.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/mapred/MiniMRCluster.java?rev=806173&r1=806172&r2=806173&view=diff ============================================================================== --- hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/mapred/MiniMRCluster.java (original) +++ hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/mapred/MiniMRCluster.java Thu Aug 20 13:50:05 2009 @@ -19,7 +19,9 @@ 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 @@ 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 @@ 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); Added: hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/mapred/TestJobTrackerStart.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/mapred/TestJobTrackerStart.java?rev=806173&view=auto ============================================================================== --- hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/mapred/TestJobTrackerStart.java (added) +++ hadoop/common/branches/branch-0.20/src/test/org/apache/hadoop/mapred/TestJobTrackerStart.java Thu Aug 20 13:50:05 2009 @@ -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(); + } +} \ No newline at end of file