hadoop-hdfs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szets...@apache.org
Subject svn commit: r1586080 - in /hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs: ./ CHANGES.txt src/test/java/org/apache/hadoop/hdfs/server/namenode/TestValidateConfigurationSettings.java
Date Wed, 09 Apr 2014 18:50:40 GMT
Author: szetszwo
Date: Wed Apr  9 18:50:39 2014
New Revision: 1586080

URL: http://svn.apache.org/r1586080
Log:
svn merge -c 1586079 from trunk for HDFS-6209. TestValidateConfigurationSettings should use
random ports.

Modified:
    hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/   (props changed)
    hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
    hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestValidateConfigurationSettings.java

Propchange: hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/
------------------------------------------------------------------------------
  Merged /hadoop/common/trunk/hadoop-hdfs-project/hadoop-hdfs:r1586079

Modified: hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt?rev=1586080&r1=1586079&r2=1586080&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt (original)
+++ hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt Wed Apr  9
18:50:39 2014
@@ -105,6 +105,9 @@ Release 2.4.1 - UNRELEASED
     HDFS-6204. Fix TestRBWBlockInvalidation: change the last sleep to a loop.
     (szetszwo) 
 
+    HDFS-6209. TestValidateConfigurationSettings should use random ports.
+    (Arpit Agarwal via szetszwo) 
+
 Release 2.4.0 - 2014-04-07 
 
   INCOMPATIBLE CHANGES

Modified: hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestValidateConfigurationSettings.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestValidateConfigurationSettings.java?rev=1586080&r1=1586079&r2=1586080&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestValidateConfigurationSettings.java
(original)
+++ hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestValidateConfigurationSettings.java
Wed Apr  9 18:50:39 2014
@@ -17,12 +17,10 @@
  */
 package org.apache.hadoop.hdfs.server.namenode;
 
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
 import java.io.File;
 import java.io.IOException;
 import java.net.BindException;
+import java.util.Random;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
@@ -55,16 +53,26 @@ public class TestValidateConfigurationSe
   public void testThatMatchingRPCandHttpPortsThrowException() 
       throws IOException {
 
-    Configuration conf = new HdfsConfiguration();
-    File nameDir = new File(MiniDFSCluster.getBaseDirectory(), "name");
-    conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY,
-        nameDir.getAbsolutePath());
-
-    // set both of these to port 9000, should fail
-    FileSystem.setDefaultUri(conf, "hdfs://localhost:9000"); 
-    conf.set(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY, "127.0.0.1:9000");
-    DFSTestUtil.formatNameNode(conf);
-    new NameNode(conf);
+    NameNode nameNode = null;
+    try {
+      Configuration conf = new HdfsConfiguration();
+      File nameDir = new File(MiniDFSCluster.getBaseDirectory(), "name");
+      conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY,
+          nameDir.getAbsolutePath());
+
+      Random rand = new Random();
+      final int port = 30000 + rand.nextInt(30000);
+
+      // set both of these to the same port. It should fail.
+      FileSystem.setDefaultUri(conf, "hdfs://localhost:" + port);
+      conf.set(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY, "127.0.0.1:" + port);
+      DFSTestUtil.formatNameNode(conf);
+      nameNode = new NameNode(conf);
+    } finally {
+      if (nameNode != null) {
+        nameNode.stop();
+      }
+    }
   }
 
   /**
@@ -80,11 +88,29 @@ public class TestValidateConfigurationSe
     conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY,
         nameDir.getAbsolutePath());
 
-    FileSystem.setDefaultUri(conf, "hdfs://localhost:8000");
-    conf.set(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY, "127.0.0.1:9000");
-    DFSTestUtil.formatNameNode(conf);
-    NameNode nameNode = new NameNode(conf); // should be OK!
-    nameNode.stop();
+    Random rand = new Random();
+
+    // A few retries in case the ports we choose are in use.
+    for (int i = 0; i < 5; ++i) {
+      final int port1 = 30000 + rand.nextInt(10000);
+      final int port2 = port1 + 1 + rand.nextInt(10000);
+
+      FileSystem.setDefaultUri(conf, "hdfs://localhost:" + port1);
+      conf.set(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY, "127.0.0.1:" + port2);
+      DFSTestUtil.formatNameNode(conf);
+      NameNode nameNode = null;
+
+      try {
+        nameNode = new NameNode(conf); // should be OK!
+        break;
+      } catch(BindException be) {
+        continue;     // Port in use? Try another.
+      } finally {
+        if (nameNode != null) {
+          nameNode.stop();
+        }
+      }
+    }
   }
 
   /**



Mime
View raw message