From 6dc40bab4ec589fb17063f07bb2a056e311f6bf2 Mon Sep 17 00:00:00 2001 From: Inigo Goiri Date: Wed, 30 May 2018 10:02:19 -0700 Subject: [PATCH] HDFS-13632. Randomize baseDir for MiniJournalCluster in MiniQJMHACluster for TestDFSAdminWithHA. Contributed by Anbang Hu. (cherry picked from commit e1102865e6e16babaff9346212c824cb1f47c31c) --- .../apache/hadoop/hdfs/qjournal/MiniQJMHACluster.java | 10 ++++++++-- .../apache/hadoop/hdfs/tools/TestDFSAdminWithHA.java | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/MiniQJMHACluster.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/MiniQJMHACluster.java index 1005f7fcc09..f1f74dcb149 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/MiniQJMHACluster.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/MiniQJMHACluster.java @@ -49,6 +49,7 @@ public class MiniQJMHACluster { private int numNNs = 2; private final MiniDFSCluster.Builder dfsBuilder; private boolean forceRemoteEditsOnly = false; + private String baseDir; public Builder(Configuration conf) { this.conf = conf; @@ -69,6 +70,11 @@ public class MiniQJMHACluster { this.startOpt = startOpt; } + public Builder baseDir(String d) { + this.baseDir = d; + return this; + } + public Builder setNumNameNodes(int nns) { this.numNNs = nns; return this; @@ -104,8 +110,8 @@ public class MiniQJMHACluster { basePort = 10000 + RANDOM.nextInt(1000) * 4; LOG.info("Set MiniQJMHACluster basePort to " + basePort); // start 3 journal nodes - journalCluster = new MiniJournalCluster.Builder(conf).format(true) - .build(); + journalCluster = new MiniJournalCluster.Builder(conf) + .baseDir(builder.baseDir).format(true).build(); journalCluster.waitActive(); journalCluster.setNamenodeSharedEditsConf(NAMESERVICE); URI journalURI = journalCluster.getQuorumJournalURI(NAMESERVICE); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdminWithHA.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdminWithHA.java index b21084edf60..aa4d4819155 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdminWithHA.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestDFSAdminWithHA.java @@ -32,6 +32,7 @@ import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.qjournal.MiniQJMHACluster; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants; import org.apache.hadoop.hdfs.server.namenode.ha.BootstrapStandby; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.After; import org.junit.Test; @@ -85,7 +86,8 @@ public class TestDFSAdminWithHA { conf = new Configuration(); conf.setBoolean(CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION, security); - cluster = new MiniQJMHACluster.Builder(conf).build(); + String baseDir = GenericTestUtils.getRandomizedTempPath(); + cluster = new MiniQJMHACluster.Builder(conf).baseDir(baseDir).build(); setHAConf(conf, cluster.getDfsCluster().getNameNode(0).getHostAndPort(), cluster.getDfsCluster().getNameNode(1).getHostAndPort()); cluster.getDfsCluster().getNameNode(0).getHostAndPort();