hadoop-mapreduce-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r806265 [2/2] - in /hadoop/mapreduce/branches/MAPREDUCE-233: ./ conf/ lib/ src/c++/ src/contrib/ src/contrib/capacity-scheduler/ src/contrib/data_join/ src/contrib/dynamic-scheduler/ src/contrib/eclipse-plugin/ src/contrib/fairscheduler/ sr...
Date Thu, 20 Aug 2009 17:17:01 GMT
Added: hadoop/mapreduce/branches/MAPREDUCE-233/src/test/mapred/org/apache/hadoop/mapred/TestTaskTrackerLifecycle.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MAPREDUCE-233/src/test/mapred/org/apache/hadoop/mapred/TestTaskTrackerLifecycle.java?rev=806265&view=auto
==============================================================================
--- hadoop/mapreduce/branches/MAPREDUCE-233/src/test/mapred/org/apache/hadoop/mapred/TestTaskTrackerLifecycle.java
(added)
+++ hadoop/mapreduce/branches/MAPREDUCE-233/src/test/mapred/org/apache/hadoop/mapred/TestTaskTrackerLifecycle.java
Thu Aug 20 17:16:59 2009
@@ -0,0 +1,124 @@
+/**
+ * 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;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.util.Service;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Test that the task tracker follows the service lifecycle
+ */
+
+public class TestTaskTrackerLifecycle extends TestCase {
+  private TaskTracker tracker;
+  private static final Log LOG = LogFactory.getLog(TestTaskTrackerLifecycle.class);
+
+  /**
+   * Tears down the fixture, for example, close a network connection. This method
+   * is called after a test is executed.
+   */
+  protected void tearDown() throws Exception {
+    super.tearDown();
+    Service.close(tracker);
+  }
+
+  /**
+   * Create a job conf suitable for testing
+   * @return a new job conf instance
+   */
+  private JobConf createJobConf() {
+    JobConf config = new JobConf();
+    //extra fast timeout
+    config.set("mapred.task.tracker.connect.timeout","10");
+    String dataDir = System.getProperty("test.build.data");
+    File hdfsDir = new File(dataDir, "dfs");
+    config.set("dfs.name.dir", new File(hdfsDir, "name1").getPath());
+    FileSystem.setDefaultUri(config, "hdfs://localhost:0");
+    config.set("dfs.http.address", "hdfs://localhost:0");
+    config.set("mapred.job.tracker", "localhost:8012");
+    config.set("ipc.client.connect.max.retries", "1");
+    return config;
+  }
+
+  /**
+   * Assert that the throwable is some kind of IOException, 
+   * containing the string "Connection refused"
+   * @param thrown what was thrown
+   * @throws Throwable the exception, rethrown, if it is not what was expected
+   */
+  private void assertConnectionRefused(Throwable thrown) throws Throwable {
+    assertNotNull("Null Exception", thrown);
+    if (!(thrown instanceof IOException)) {
+      throw thrown;
+    }
+    if (!thrown.getMessage().contains("Connection refused")) {
+      throw thrown;
+    }
+  }
+
+  /**
+   * Test that if a tracker isn't started, we can still terminate it cleanly
+   * @throws Throwable on a failure
+   */
+  public void testTerminateUnstartedTracker() throws Throwable {
+    tracker = new TaskTracker(createJobConf(), false);
+    tracker.close();
+  }
+
+  public void testOrphanTrackerFailure() throws Throwable {
+    try {
+      tracker = new TaskTracker(createJobConf());
+      fail("Expected a failure");
+    } catch (IOException e) {
+      assertConnectionRefused(e);
+    }
+  }
+
+  public void testFailingTracker() throws Throwable {
+    tracker = new TaskTracker(createJobConf(), false);
+    try {
+      tracker.start();
+      fail("Expected a failure");
+    } catch (IOException e) {
+      assertConnectionRefused(e);
+      assertEquals(Service.ServiceState.FAILED, tracker.getServiceState());
+    }
+  }
+
+  public void testStartedTracker() throws Throwable {
+    tracker = new TaskTracker(createJobConf(), false);
+    try {
+      Service.startService(tracker);
+      fail("Expected a failure");
+    } catch (IOException e) {
+      assertConnectionRefused(e);
+      assertEquals(Service.ServiceState.CLOSED, tracker.getServiceState());
+    }
+    assertConnectionRefused(tracker.getFailureCause());
+    tracker.close();
+    assertConnectionRefused(tracker.getFailureCause());
+  }
+
+}

Modified: hadoop/mapreduce/branches/MAPREDUCE-233/src/test/mapred/org/apache/hadoop/mapred/UtilsForTests.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MAPREDUCE-233/src/test/mapred/org/apache/hadoop/mapred/UtilsForTests.java?rev=806265&r1=806264&r2=806265&view=diff
==============================================================================
--- hadoop/mapreduce/branches/MAPREDUCE-233/src/test/mapred/org/apache/hadoop/mapred/UtilsForTests.java
(original)
+++ hadoop/mapreduce/branches/MAPREDUCE-233/src/test/mapred/org/apache/hadoop/mapred/UtilsForTests.java
Thu Aug 20 17:16:59 2009
@@ -234,6 +234,18 @@
     } catch (InterruptedException ie) {}
   }
   
+  static void waitForJobHalfDone(RunningJob job)
+          throws IOException {
+    // wait for 50%
+    long timeout = System.currentTimeMillis() + 30000;
+    while (job.mapProgress() < 0.5f) {
+      if(System.currentTimeMillis() > timeout) {
+        throw new IOException("Timeout waiting for job to get to 50% done");
+      }
+      UtilsForTests.waitFor(100);
+    }
+  }
+  
   /**
    * Wait for the jobtracker to be RUNNING.
    */

Modified: hadoop/mapreduce/branches/MAPREDUCE-233/src/test/mapred/org/apache/hadoop/mapreduce/TestMapReduceLocal.java
URL: http://svn.apache.org/viewvc/hadoop/mapreduce/branches/MAPREDUCE-233/src/test/mapred/org/apache/hadoop/mapreduce/TestMapReduceLocal.java?rev=806265&r1=806264&r2=806265&view=diff
==============================================================================
--- hadoop/mapreduce/branches/MAPREDUCE-233/src/test/mapred/org/apache/hadoop/mapreduce/TestMapReduceLocal.java
(original)
+++ hadoop/mapreduce/branches/MAPREDUCE-233/src/test/mapred/org/apache/hadoop/mapreduce/TestMapReduceLocal.java
Thu Aug 20 17:16:59 2009
@@ -100,7 +100,7 @@
       private float last = 0.0f;
       private boolean progressCalled = false;
       @Override
-      public float getProgress() {
+      public float getProgress() throws IOException {
         progressCalled = true;
         final float ret = super.getProgress();
         assertTrue("getProgress decreased", ret >= last);

Propchange: hadoop/mapreduce/branches/MAPREDUCE-233/src/webapps/job/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Aug 20 17:16:59 2009
@@ -1,2 +1,3 @@
 /hadoop/core/branches/branch-0.19/mapred/src/webapps/job:713112
 /hadoop/core/trunk/src/webapps/job:776175-785643
+/hadoop/mapreduce/trunk/src/webapps/job:804974-805826



Mime
View raw message