svn merge -c 1586079 from trunk for HDFS-6209. TestValidateConfigurationSettings should use random ports.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1586080 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
11a6feb8d3
commit
02163d1441
|
@ -105,6 +105,9 @@ Release 2.4.1 - UNRELEASED
|
||||||
HDFS-6204. Fix TestRBWBlockInvalidation: change the last sleep to a loop.
|
HDFS-6204. Fix TestRBWBlockInvalidation: change the last sleep to a loop.
|
||||||
(szetszwo)
|
(szetszwo)
|
||||||
|
|
||||||
|
HDFS-6209. TestValidateConfigurationSettings should use random ports.
|
||||||
|
(Arpit Agarwal via szetszwo)
|
||||||
|
|
||||||
Release 2.4.0 - 2014-04-07
|
Release 2.4.0 - 2014-04-07
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -17,12 +17,10 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hdfs.server.namenode;
|
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.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.BindException;
|
import java.net.BindException;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.FileSystem;
|
import org.apache.hadoop.fs.FileSystem;
|
||||||
|
@ -55,16 +53,26 @@ public class TestValidateConfigurationSettings {
|
||||||
public void testThatMatchingRPCandHttpPortsThrowException()
|
public void testThatMatchingRPCandHttpPortsThrowException()
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|
||||||
|
NameNode nameNode = null;
|
||||||
|
try {
|
||||||
Configuration conf = new HdfsConfiguration();
|
Configuration conf = new HdfsConfiguration();
|
||||||
File nameDir = new File(MiniDFSCluster.getBaseDirectory(), "name");
|
File nameDir = new File(MiniDFSCluster.getBaseDirectory(), "name");
|
||||||
conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY,
|
conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY,
|
||||||
nameDir.getAbsolutePath());
|
nameDir.getAbsolutePath());
|
||||||
|
|
||||||
// set both of these to port 9000, should fail
|
Random rand = new Random();
|
||||||
FileSystem.setDefaultUri(conf, "hdfs://localhost:9000");
|
final int port = 30000 + rand.nextInt(30000);
|
||||||
conf.set(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY, "127.0.0.1:9000");
|
|
||||||
|
// 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);
|
DFSTestUtil.formatNameNode(conf);
|
||||||
new NameNode(conf);
|
nameNode = new NameNode(conf);
|
||||||
|
} finally {
|
||||||
|
if (nameNode != null) {
|
||||||
|
nameNode.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,12 +88,30 @@ public class TestValidateConfigurationSettings {
|
||||||
conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY,
|
conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY,
|
||||||
nameDir.getAbsolutePath());
|
nameDir.getAbsolutePath());
|
||||||
|
|
||||||
FileSystem.setDefaultUri(conf, "hdfs://localhost:8000");
|
Random rand = new Random();
|
||||||
conf.set(DFSConfigKeys.DFS_NAMENODE_HTTP_ADDRESS_KEY, "127.0.0.1:9000");
|
|
||||||
|
// 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);
|
DFSTestUtil.formatNameNode(conf);
|
||||||
NameNode nameNode = new NameNode(conf); // should be OK!
|
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();
|
nameNode.stop();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HDFS-3013: NameNode format command doesn't pick up
|
* HDFS-3013: NameNode format command doesn't pick up
|
||||||
|
|
Loading…
Reference in New Issue