Parcourir la source

MAPREDUCE-5070. TestClusterStatus.testClusterMetrics fails on JDK7. (tucu)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-1@1457033 13f79535-47bb-0310-9956-ffa450edef68
Alejandro Abdelnur il y a 12 ans
Parent
commit
eb4b64527c
2 fichiers modifiés avec 41 ajouts et 34 suppressions
  1. 2 0
      CHANGES.txt
  2. 39 34
      src/test/org/apache/hadoop/mapred/TestClusterStatus.java

+ 2 - 0
CHANGES.txt

@@ -13,6 +13,8 @@ Release 1.3.0 - unreleased
     MAPREDUCE-5047. keep.failed.task.files=true causes job failure on 
     MAPREDUCE-5047. keep.failed.task.files=true causes job failure on 
     secure clusters. (sandyr via tucu)
     secure clusters. (sandyr via tucu)
 
 
+    MAPREDUCE-5070. TestClusterStatus.testClusterMetrics fails on JDK7. (tucu)
+
 Release 1.2.0 - unreleased
 Release 1.2.0 - unreleased
 
 
   INCOMPATIBLE CHANGES
   INCOMPATIBLE CHANGES

+ 39 - 34
src/test/org/apache/hadoop/mapred/TestClusterStatus.java

@@ -17,6 +17,8 @@
  */
  */
 package org.apache.hadoop.mapred;
 package org.apache.hadoop.mapred;
 
 
+import static org.junit.Assert.assertEquals;
+
 import java.io.IOException;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashMap;
@@ -24,14 +26,11 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
 import org.apache.hadoop.mapreduce.ClusterMetrics;
 import org.apache.hadoop.mapreduce.ClusterMetrics;
-import org.apache.hadoop.mapreduce.Job;
 import org.apache.hadoop.mapreduce.TaskType;
 import org.apache.hadoop.mapreduce.TaskType;
 import org.apache.hadoop.mapreduce.server.jobtracker.TaskTracker;
 import org.apache.hadoop.mapreduce.server.jobtracker.TaskTracker;
-
-import junit.extensions.TestSetup;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
 
 
 /**
 /**
  * Class to test that ClusterMetrics are being created with the right
  * Class to test that ClusterMetrics are being created with the right
@@ -39,41 +38,44 @@ import junit.framework.TestSuite;
  * 
  * 
  * The tests exercise code paths where the counts of slots are updated.
  * The tests exercise code paths where the counts of slots are updated.
  */
  */
-public class TestClusterStatus extends TestCase {
+public class TestClusterStatus {
 
 
   private static String[] trackers = new String[] { "tracker_tracker1:1000",
   private static String[] trackers = new String[] { "tracker_tracker1:1000",
       "tracker_tracker2:1000", "tracker_tracker3:1000" };
       "tracker_tracker2:1000", "tracker_tracker3:1000" };
-  private static JobTracker jobTracker;
-  private static int mapSlotsPerTracker = 4;
-  private static int reduceSlotsPerTracker = 2;
-  private static MiniMRCluster mr;
-  private static JobClient client;
+  private JobTracker jobTracker;
+  private final static int mapSlotsPerTracker = 4;
+  private final static int reduceSlotsPerTracker = 2;
+  private MiniMRCluster mr;
+  private JobClient client;
   // heartbeat responseId. increment this after sending a heartbeat
   // heartbeat responseId. increment this after sending a heartbeat
-  private static short responseId = 1;
+  private short responseId;
   private static FakeJobInProgress fakeJob;
   private static FakeJobInProgress fakeJob;
   private static FakeTaskScheduler scheduler;
   private static FakeTaskScheduler scheduler;
   
   
-  public static Test suite() {
-    TestSetup setup = new TestSetup(new TestSuite(TestClusterStatus.class)) {
-      protected void setUp() throws Exception {
-        JobConf conf = new JobConf();
-        conf.setClass("mapred.jobtracker.taskScheduler", 
-            TestClusterStatus.FakeTaskScheduler.class,
-                  TaskScheduler.class);
-        mr = new MiniMRCluster(0, 0, 0, "file:///", 1, null, null, null, conf);
-        jobTracker = mr.getJobTrackerRunner().getJobTracker();
-        for (String tracker : trackers) {
-          establishFirstContact(jobTracker, tracker);
-        }
-        client = new JobClient(mr.createJobConf());
-      }
-
-      protected void tearDown() throws Exception {
-        client.close();
-        mr.shutdown();
-      }
-    };
-    return setup;
+  @Before
+  public void setUp() throws Exception {
+    responseId = 1;
+    JobConf conf = new JobConf();
+    conf.setClass("mapred.jobtracker.taskScheduler", 
+        TestClusterStatus.FakeTaskScheduler.class,
+        TaskScheduler.class);
+    mr = new MiniMRCluster(0, 0, 0, "file:///", 1, null, null, null, conf);
+    jobTracker = mr.getJobTrackerRunner().getJobTracker();
+    for (String tracker : trackers) {
+      establishFirstContact(jobTracker, tracker);
+    }
+    client = new JobClient(mr.createJobConf());
+  }
+  
+  @After
+  public void tearDown() throws Exception {
+    client.close();
+    mr.shutdown();
+    fakeJob = null;
+    scheduler = null;
+    client = null;
+    mr = null;
+    jobTracker = null;
   }
   }
 
 
   /**
   /**
@@ -157,6 +159,7 @@ public class TestClusterStatus extends TestCase {
       taskStatuses, 0, 0, mapSlotsPerTracker, reduceSlotsPerTracker);
       taskStatuses, 0, 0, mapSlotsPerTracker, reduceSlotsPerTracker);
   }
   }
   
   
+  @Test
   public void testClusterMetrics() throws IOException, InterruptedException {
   public void testClusterMetrics() throws IOException, InterruptedException {
     assertEquals("tasktracker count doesn't match", trackers.length,
     assertEquals("tasktracker count doesn't match", trackers.length,
       client.getClusterStatus().getTaskTrackers());
       client.getClusterStatus().getTaskTrackers());
@@ -256,6 +259,7 @@ public class TestClusterStatus extends TestCase {
     list.add(ts);
     list.add(ts);
   }
   }
 
 
+  @Test
   public void testReservedSlots() throws IOException {
   public void testReservedSlots() throws IOException {
     JobConf conf = mr.createJobConf();
     JobConf conf = mr.createJobConf();
 
 
@@ -308,6 +312,7 @@ public class TestClusterStatus extends TestCase {
         0, metrics.getReservedReduceSlots());
         0, metrics.getReservedReduceSlots());
   }
   }
   
   
+  @Test
   public void testClusterStatus() throws Exception {
   public void testClusterStatus() throws Exception {
     ClusterStatus clusterStatus = client.getClusterStatus();
     ClusterStatus clusterStatus = client.getClusterStatus();
     assertEquals("JobTracker used-memory is " + clusterStatus.getUsedMemory() + 
     assertEquals("JobTracker used-memory is " + clusterStatus.getUsedMemory() +