HDFS-10367. TestDFSShell.testMoveWithTargetPortEmpty fails with Address bind exception. Contributed by Brahma Reddy Battula.

This commit is contained in:
Masatake Iwasaki 2016-06-02 20:55:04 +09:00
parent 99675e00df
commit aadb77e412
2 changed files with 42 additions and 1 deletions

View File

@ -63,4 +63,43 @@ public class ServerSocketUtil {
} }
} }
/**
* Check whether port is available or not.
*
* @param port given port
* @return
*/
private static boolean isPortAvailable(int port) {
try (ServerSocket s = new ServerSocket(port)) {
return true;
} catch (IOException e) {
return false;
}
}
/**
* Wait till the port available.
*
* @param port given port
* @param retries number of retries for given port
* @return
* @throws InterruptedException
* @throws IOException
*/
public static int waitForPort(int port, int retries)
throws InterruptedException, IOException {
int tries = 0;
while (true) {
if (isPortAvailable(port)) {
return port;
} else {
tries++;
if (tries >= retries) {
throw new IOException(
"Port is already in use; giving up after " + tries + " times.");
}
Thread.sleep(1000);
}
}
}
} }

View File

@ -49,6 +49,7 @@ import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Text; import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.compress.BZip2Codec; import org.apache.hadoop.io.compress.BZip2Codec;
import org.apache.hadoop.io.compress.CompressionCodec; import org.apache.hadoop.io.compress.CompressionCodec;
import org.apache.hadoop.net.ServerSocketUtil;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.test.PathUtils; import org.apache.hadoop.test.PathUtils;
import org.apache.hadoop.util.ReflectionUtils; import org.apache.hadoop.util.ReflectionUtils;
@ -567,7 +568,8 @@ public class TestDFSShell {
cluster = new MiniDFSCluster.Builder(conf) cluster = new MiniDFSCluster.Builder(conf)
.format(true) .format(true)
.numDataNodes(2) .numDataNodes(2)
.nameNodePort(HdfsClientConfigKeys.DFS_NAMENODE_RPC_PORT_DEFAULT) .nameNodePort(ServerSocketUtil.waitForPort(
HdfsClientConfigKeys.DFS_NAMENODE_RPC_PORT_DEFAULT, 10))
.waitSafeMode(true) .waitSafeMode(true)
.build(); .build();
FileSystem srcFs = cluster.getFileSystem(); FileSystem srcFs = cluster.getFileSystem();