[MINOR] Fix BindException when running tests of shared machines. (#2070)
When unit tests are run on shared machines (e.g. jenkins cluster), the unit tests sometimes fail due to BindException in starting HDFS Cluster. This is because the port chosen may have been bound by another process using the same machine. The fix is to retry the port selection a few times.
This commit is contained in:
@@ -31,6 +31,7 @@ import org.apache.log4j.Logger;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.BindException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -72,6 +73,9 @@ public class HdfsTestService {
|
|||||||
FileIOUtils.deleteDirectory(file);
|
FileIOUtils.deleteDirectory(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int loop = 0;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
int namenodeRpcPort = NetworkTestUtils.nextFreePort();
|
int namenodeRpcPort = NetworkTestUtils.nextFreePort();
|
||||||
int datanodePort = NetworkTestUtils.nextFreePort();
|
int datanodePort = NetworkTestUtils.nextFreePort();
|
||||||
int datanodeIpcPort = NetworkTestUtils.nextFreePort();
|
int datanodeIpcPort = NetworkTestUtils.nextFreePort();
|
||||||
@@ -86,6 +90,15 @@ public class HdfsTestService {
|
|||||||
.checkDataNodeHostConfig(true).build();
|
.checkDataNodeHostConfig(true).build();
|
||||||
LOG.info("HDFS Minicluster service started.");
|
LOG.info("HDFS Minicluster service started.");
|
||||||
return miniDfsCluster;
|
return miniDfsCluster;
|
||||||
|
} catch (BindException ex) {
|
||||||
|
++loop;
|
||||||
|
if (loop < 5) {
|
||||||
|
stop();
|
||||||
|
} else {
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
|
|||||||
Reference in New Issue
Block a user