hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ni...@apache.org
Subject svn commit: r610254 - in /lucene/hadoop/trunk: CHANGES.txt src/test/org/apache/hadoop/dfs/TestHDFSServerPorts.java src/test/org/apache/hadoop/mapred/TestMRServerPorts.java
Date Wed, 09 Jan 2008 01:36:25 GMT
Author: nigel
Date: Tue Jan  8 17:36:17 2008
New Revision: 610254

URL: http://svn.apache.org/viewvc?rev=610254&view=rev
Log:
HADOOP-2446. Fixes TestHDFSServerPorts and TestMRServerPorts so they do not rely on statically
configured ports and cleanup better.  Contributed by nigel.

Modified:
    lucene/hadoop/trunk/CHANGES.txt
    lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestHDFSServerPorts.java
    lucene/hadoop/trunk/src/test/org/apache/hadoop/mapred/TestMRServerPorts.java

Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?rev=610254&r1=610253&r2=610254&view=diff
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Tue Jan  8 17:36:17 2008
@@ -372,6 +372,9 @@
     HADOOP-2512. Fix error stream handling in Shell. Use exit code to
     detect shell command errors in RawLocalFileSystem. (Raghu Angadi)
 
+    HADOOP-2446. Fixes TestHDFSServerPorts and TestMRServerPorts so they
+    do not rely on statically configured ports and cleanup better. (nigel)
+
 Release 0.15.2 - 2008-01-02
 
   BUG FIXES

Modified: lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestHDFSServerPorts.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestHDFSServerPorts.java?rev=610254&r1=610253&r2=610254&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestHDFSServerPorts.java (original)
+++ lucene/hadoop/trunk/src/test/org/apache/hadoop/dfs/TestHDFSServerPorts.java Tue Jan  8
17:36:17 2008
@@ -37,13 +37,7 @@
  */
 public class TestHDFSServerPorts extends TestCase {
   public static final String NAME_NODE_HOST = "localhost:";
-  public static final int    NAME_NODE_PORT = 50013;
-  public static final String NAME_NODE_ADDRESS = NAME_NODE_HOST 
-                                               + NAME_NODE_PORT;
   public static final String NAME_NODE_HTTP_HOST = "0.0.0.0:";
-  public static final int    NAME_NODE_HTTP_PORT = 50073;
-  public static final String NAME_NODE_HTTP_ADDRESS = NAME_NODE_HTTP_HOST 
-                                                    + NAME_NODE_HTTP_PORT;
 
   Configuration config;
   File hdfsDir;
@@ -59,16 +53,19 @@
     }
     config = new Configuration();
     config.set("dfs.name.dir", new File(hdfsDir, "name1").getPath());
-    config.set("fs.default.name", NAME_NODE_ADDRESS);
-    config.set("dfs.http.bindAddress", NAME_NODE_HTTP_ADDRESS);
+    config.set("fs.default.name", NAME_NODE_HOST + "0");
+    config.set("dfs.http.bindAddress", NAME_NODE_HTTP_HOST + "0");
     NameNode.format(config);
 
     String[] args = new String[] {};
+    // NameNode will modify config with the ports it bound to
     return NameNode.createNameNode(args, config);
   }
 
   public void stopNameNode(NameNode nn) {
-    nn.stop();
+    if (nn != null) {
+      nn.stop();
+    }
     RPC.stopClient();
   }
 
@@ -128,74 +125,87 @@
    * Verify name-node port usage.
    */
   public void testNameNodePorts() throws Exception {
-    NameNode nn = startNameNode();
-
-    // start another namenode on the same port
-    Configuration conf2 = new Configuration(config);
-    conf2.set("dfs.name.dir", new File(hdfsDir, "name2").getPath());
-    NameNode.format(conf2);
-    boolean started = canStartNameNode(conf2);
-    assertFalse(started); // should fail
-
-    // start on a different main port
-    conf2.set("fs.default.name", NAME_NODE_HOST + 0);
-    started = canStartNameNode(conf2);
-    assertFalse(started); // should fail again
-
-    // different http port
-    conf2.set("dfs.http.bindAddress", NAME_NODE_HTTP_HOST + 0);
-    started = canStartNameNode(conf2);
-    assertTrue(started); // should start now
+    NameNode nn = null;
+    try {
+      nn = startNameNode();
 
-    stopNameNode(nn);
+      // start another namenode on the same port
+      Configuration conf2 = new Configuration(config);
+      conf2.set("dfs.name.dir", new File(hdfsDir, "name2").getPath());
+      NameNode.format(conf2);
+      boolean started = canStartNameNode(conf2);
+      assertFalse(started); // should fail
+
+      // start on a different main port
+      conf2.set("fs.default.name", NAME_NODE_HOST + "0");
+      started = canStartNameNode(conf2);
+      assertFalse(started); // should fail again
+
+      // reset conf2 since NameNode modifies it
+      conf2.set("fs.default.name", NAME_NODE_HOST + "0");
+      // different http port
+      conf2.set("dfs.http.bindAddress", NAME_NODE_HTTP_HOST + "0");
+      started = canStartNameNode(conf2);
+      assertTrue(started); // should start now
+    } finally {
+      stopNameNode(nn);
+    }
   }
 
   /**
    * Verify data-node port usage.
    */
   public void testDataNodePorts() throws Exception {
-    NameNode nn = startNameNode();
+    NameNode nn = null;
+    try {
+      nn = startNameNode();
 
-    // start data-node on the same port as name-node
-    Configuration conf2 = new Configuration(config);
-    conf2.set("dfs.data.dir", new File(hdfsDir, "data").getPath());
-    conf2.set("dfs.datanode.bindAddress", NAME_NODE_ADDRESS);
-    conf2.set("dfs.datanode.http.bindAddress", NAME_NODE_HTTP_HOST + 0);
-    boolean started = canStartDataNode(conf2);
-    assertFalse(started); // should fail
-
-    // bind http server to the same port as name-node
-    conf2.set("dfs.datanode.bindAddress", NAME_NODE_HOST + 0);
-    conf2.set("dfs.datanode.http.bindAddress", NAME_NODE_HTTP_ADDRESS);
-    started = canStartDataNode(conf2);
-    assertFalse(started); // should fail
+      // start data-node on the same port as name-node
+      Configuration conf2 = new Configuration(config);
+      conf2.set("dfs.data.dir", new File(hdfsDir, "data").getPath());
+      conf2.set("dfs.datanode.bindAddress", config.get("fs.default.name"));
+      conf2.set("dfs.datanode.http.bindAddress", NAME_NODE_HTTP_HOST + "0");
+      boolean started = canStartDataNode(conf2);
+      assertFalse(started); // should fail
+
+      // bind http server to the same port as name-node
+      conf2.set("dfs.datanode.bindAddress", NAME_NODE_HOST + "0");
+      conf2.set("dfs.datanode.http.bindAddress", config.get("dfs.http.bindAddress"));
+      started = canStartDataNode(conf2);
+      assertFalse(started); // should fail
     
-    // both ports are different from the name-node ones
-    conf2.set("dfs.datanode.bindAddress", NAME_NODE_HOST + 0);
-    conf2.set("dfs.datanode.http.bindAddress", NAME_NODE_HTTP_HOST + 0);
-    started = canStartDataNode(conf2);
-    assertTrue(started); // should start now
-    stopNameNode(nn);
+      // both ports are different from the name-node ones
+      conf2.set("dfs.datanode.bindAddress", NAME_NODE_HOST + "0");
+      conf2.set("dfs.datanode.http.bindAddress", NAME_NODE_HTTP_HOST + "0");
+      started = canStartDataNode(conf2);
+      assertTrue(started); // should start now
+    } finally {
+      stopNameNode(nn);
+    }
   }
 
   /**
    * Verify secondary name-node port usage.
    */
   public void testSecondaryNodePorts() throws Exception {
-    NameNode nn = startNameNode();
+    NameNode nn = null;
+    try {
+      nn = startNameNode();
 
-    // bind http server to the same port as name-node
-    Configuration conf2 = new Configuration(config);
-    conf2.set("dfs.secondary.http.bindAddress", NAME_NODE_ADDRESS);
-    SecondaryNameNode.LOG.info("= Starting 1 on: " + conf2.get("dfs.secondary.http.bindAddress"));
-    boolean started = canStartSecondaryNode(conf2);
-    assertFalse(started); // should fail
-
-    // bind http server to a different port
-    conf2.set("dfs.secondary.http.bindAddress", NAME_NODE_HTTP_HOST + 0);
-    SecondaryNameNode.LOG.info("= Starting 2 on: " + conf2.get("dfs.secondary.http.bindAddress"));
-    started = canStartSecondaryNode(conf2);
-    assertTrue(started); // should start now
-    stopNameNode(nn);
+      // bind http server to the same port as name-node
+      Configuration conf2 = new Configuration(config);
+      conf2.set("dfs.secondary.http.bindAddress", config.get("dfs.http.bindAddress"));
+      SecondaryNameNode.LOG.info("= Starting 1 on: " + conf2.get("dfs.secondary.http.bindAddress"));
+      boolean started = canStartSecondaryNode(conf2);
+      assertFalse(started); // should fail
+
+      // bind http server to a different port
+      conf2.set("dfs.secondary.http.bindAddress", NAME_NODE_HTTP_HOST + "0");
+      SecondaryNameNode.LOG.info("= Starting 2 on: " + conf2.get("dfs.secondary.http.bindAddress"));
+      started = canStartSecondaryNode(conf2);
+      assertTrue(started); // should start now
+    } finally {
+      stopNameNode(nn);
+    }
   }
 }

Modified: lucene/hadoop/trunk/src/test/org/apache/hadoop/mapred/TestMRServerPorts.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/test/org/apache/hadoop/mapred/TestMRServerPorts.java?rev=610254&r1=610253&r2=610254&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/test/org/apache/hadoop/mapred/TestMRServerPorts.java (original)
+++ lucene/hadoop/trunk/src/test/org/apache/hadoop/mapred/TestMRServerPorts.java Tue Jan 
8 17:36:17 2008
@@ -93,68 +93,78 @@
    * Verify JobTracker port usage.
    */
   public void testJobTrackerPorts() throws Exception {
-    NameNode nn = hdfs.startNameNode();
-
-    // start job tracker on the same port as name-node
-    JobConf conf2 = new JobConf(hdfs.getConfig());
-    conf2.set("mapred.job.tracker", TestHDFSServerPorts.NAME_NODE_ADDRESS);
-    conf2.set("mapred.job.tracker.http.bindAddress",
+    NameNode nn = null;
+    try {
+      nn = hdfs.startNameNode();
+
+      // start job tracker on the same port as name-node
+      JobConf conf2 = new JobConf(hdfs.getConfig());
+      conf2.set("mapred.job.tracker", hdfs.getConfig().get("fs.default.name"));
+      conf2.set("mapred.job.tracker.http.bindAddress",
         TestHDFSServerPorts.NAME_NODE_HTTP_HOST + 0);
-    boolean started = canStartJobTracker(conf2);
-    assertFalse(started); // should fail
+      boolean started = canStartJobTracker(conf2);
+      assertFalse(started); // should fail
 
-    // bind http server to the same port as name-node
-    conf2.set("mapred.job.tracker", TestHDFSServerPorts.NAME_NODE_HOST + 0);
-    conf2.set("mapred.job.tracker.http.bindAddress",
-        TestHDFSServerPorts.NAME_NODE_HTTP_ADDRESS);
-    started = canStartJobTracker(conf2);
-    assertFalse(started); // should fail again
-
-    // both ports are different from the name-node ones
-    conf2.set("mapred.job.tracker", TestHDFSServerPorts.NAME_NODE_HOST + 0);
-    conf2.set("mapred.job.tracker.http.bindAddress",
+      // bind http server to the same port as name-node
+      conf2.set("mapred.job.tracker", TestHDFSServerPorts.NAME_NODE_HOST + 0);
+      conf2.set("mapred.job.tracker.http.bindAddress",
+        hdfs.getConfig().get("dfs.http.bindAddress"));
+      started = canStartJobTracker(conf2);
+      assertFalse(started); // should fail again
+
+      // both ports are different from the name-node ones
+      conf2.set("mapred.job.tracker", TestHDFSServerPorts.NAME_NODE_HOST + 0);
+      conf2.set("mapred.job.tracker.http.bindAddress",
         TestHDFSServerPorts.NAME_NODE_HTTP_HOST + 0);
-    started = canStartJobTracker(conf2);
-    assertTrue(started); // should start now
+      started = canStartJobTracker(conf2);
+      assertTrue(started); // should start now
 
-    hdfs.stopNameNode(nn);
+    } finally {
+      hdfs.stopNameNode(nn);
+    }
   }
 
   /**
    * Verify JobTracker port usage.
    */
   public void testTaskTrackerPorts() throws Exception {
-    NameNode nn = hdfs.startNameNode();
-
-    JobConf conf2 = new JobConf(hdfs.getConfig());
-    JobTracker jt = startJobTracker(conf2);
-
-    // start job tracker on the same port as name-node
-    conf2.set("mapred.task.tracker.report.bindAddress",
-        TestHDFSServerPorts.NAME_NODE_ADDRESS);
-    conf2.set("mapred.task.tracker.http.bindAddress",
+    NameNode nn = null;
+    JobTracker jt = null;
+    try {
+      nn = hdfs.startNameNode();
+
+      JobConf conf2 = new JobConf(hdfs.getConfig());
+      jt = startJobTracker(conf2);
+
+      // start job tracker on the same port as name-node
+      conf2.set("mapred.task.tracker.report.bindAddress",
+        hdfs.getConfig().get("fs.default.name"));
+      conf2.set("mapred.task.tracker.http.bindAddress",
         TestHDFSServerPorts.NAME_NODE_HTTP_HOST + 0);
-    boolean started = canStartTaskTracker(conf2);
-    assertFalse(started); // should fail
+      boolean started = canStartTaskTracker(conf2);
+      assertFalse(started); // should fail
 
-    // bind http server to the same port as name-node
-    conf2.set("mapred.task.tracker.report.bindAddress",
+      // bind http server to the same port as name-node
+      conf2.set("mapred.task.tracker.report.bindAddress",
         TestHDFSServerPorts.NAME_NODE_HOST + 0);
-    conf2.set("mapred.task.tracker.http.bindAddress",
-        TestHDFSServerPorts.NAME_NODE_HTTP_ADDRESS);
-    started = canStartTaskTracker(conf2);
-    assertFalse(started); // should fail again
+      conf2.set("mapred.task.tracker.http.bindAddress",
+        hdfs.getConfig().get("dfs.http.bindAddress"));
+      started = canStartTaskTracker(conf2);
+      assertFalse(started); // should fail again
 
-    // both ports are different from the name-node ones
-    conf2.set("mapred.task.tracker.report.bindAddress",
+      // both ports are different from the name-node ones
+      conf2.set("mapred.task.tracker.report.bindAddress",
         TestHDFSServerPorts.NAME_NODE_HOST + 0);
-    conf2.set("mapred.task.tracker.http.bindAddress",
+      conf2.set("mapred.task.tracker.http.bindAddress",
         TestHDFSServerPorts.NAME_NODE_HTTP_HOST + 0);
-    started = canStartTaskTracker(conf2);
-    assertTrue(started); // should start now
-
-    jt.fs.close();
-    jt.stopTracker();
-    hdfs.stopNameNode(nn);
+      started = canStartTaskTracker(conf2);
+      assertTrue(started); // should start now
+    } finally {
+      if (jt != null) {
+        jt.fs.close();
+        jt.stopTracker();
+      }
+      hdfs.stopNameNode(nn);
+    }
   }
 }



Mime
View raw message