|
@@ -19,8 +19,11 @@ package org.apache.hadoop.hdfs.server.namenode.ha;
|
|
|
|
|
|
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.net.URI;
|
|
|
|
|
|
import org.apache.commons.logging.impl.Log4JLogger;
|
|
@@ -37,6 +40,7 @@ import org.apache.hadoop.hdfs.server.namenode.FSImage;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.NNStorage;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.NameNode;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
|
|
|
+import org.apache.hadoop.net.ServerSocketUtil;
|
|
|
import org.apache.hadoop.test.GenericTestUtils;
|
|
|
import org.apache.log4j.Level;
|
|
|
import org.junit.Test;
|
|
@@ -120,17 +124,32 @@ public class TestEditLogTailer {
|
|
|
// Roll every 1s
|
|
|
conf.setInt(DFSConfigKeys.DFS_HA_LOGROLL_PERIOD_KEY, 1);
|
|
|
conf.setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1);
|
|
|
-
|
|
|
- // Have to specify IPC ports so the NNs can talk to each other.
|
|
|
- MiniDFSNNTopology topology = new MiniDFSNNTopology()
|
|
|
- .addNameservice(new MiniDFSNNTopology.NSConf("ns1")
|
|
|
- .addNN(new MiniDFSNNTopology.NNConf("nn1").setIpcPort(10031))
|
|
|
- .addNN(new MiniDFSNNTopology.NNConf("nn2").setIpcPort(10032)));
|
|
|
|
|
|
- MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf)
|
|
|
- .nnTopology(topology)
|
|
|
- .numDataNodes(0)
|
|
|
- .build();
|
|
|
+ MiniDFSCluster cluster = null;
|
|
|
+ for (int i = 0; i < 5; i++) {
|
|
|
+ try {
|
|
|
+ // Have to specify IPC ports so the NNs can talk to each other.
|
|
|
+ int[] ports = ServerSocketUtil.getPorts(2);
|
|
|
+ MiniDFSNNTopology topology = new MiniDFSNNTopology()
|
|
|
+ .addNameservice(new MiniDFSNNTopology.NSConf("ns1")
|
|
|
+ .addNN(new MiniDFSNNTopology.NNConf("nn1")
|
|
|
+ .setIpcPort(ports[0]))
|
|
|
+ .addNN(new MiniDFSNNTopology.NNConf("nn2")
|
|
|
+ .setIpcPort(ports[1])));
|
|
|
+
|
|
|
+ cluster = new MiniDFSCluster.Builder(conf)
|
|
|
+ .nnTopology(topology)
|
|
|
+ .numDataNodes(0)
|
|
|
+ .build();
|
|
|
+ break;
|
|
|
+ } catch (BindException e) {
|
|
|
+ // retry if race on ports given by ServerSocketUtil#getPorts
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (cluster == null) {
|
|
|
+ fail("failed to start mini cluster.");
|
|
|
+ }
|
|
|
try {
|
|
|
cluster.transitionToActive(activeIndex);
|
|
|
waitForLogRollInSharedDir(cluster, 3);
|