This is an automated email from the ASF dual-hosted git repository. stevel pushed a commit to branch branch-3.3 in repository https://gitbox.apache.org/repos/asf/hadoop.git
commit f3eab22a7561465871802d16511e4037f6bd0de5 Author: Steve Loughran <ste...@cloudera.com> AuthorDate: Mon Jan 1 18:30:33 2024 +0000 Revert "HDFS-16740. Mini cluster test flakiness (#4835) (#6325)" This reverts commit 9f34593ea7bd210b4e9ed7e8791a8219beb23cb1. --- .../apache/hadoop/hdfs/AdminStatesBaseTest.java | 12 +-- .../org/apache/hadoop/hdfs/MiniDFSCluster.java | 5 +- .../hadoop/hdfs/TestDFSStripedInputStream.java | 8 +- .../hadoop/hdfs/TestDecommissionWithStriped.java | 27 +++--- .../hadoop/hdfs/TestReconstructStripedFile.java | 8 +- .../org/apache/hadoop/hdfs/TestRollingUpgrade.java | 80 +++++++++------- .../hadoop/hdfs/qjournal/MiniJournalCluster.java | 11 +-- .../hadoop/hdfs/qjournal/MiniQJMHACluster.java | 8 -- .../hdfs/server/datanode/TestBPOfferService.java | 21 ++-- .../datanode/TestDataNodeRollingUpgrade.java | 7 +- .../hadoop/hdfs/server/namenode/TestFsck.java | 106 +++++++++++++-------- .../hdfs/server/namenode/TestNameNodeMXBean.java | 37 ++++--- .../server/namenode/ha/TestRetryCacheWithHA.java | 9 +- 13 files changed, 166 insertions(+), 173 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/AdminStatesBaseTest.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/AdminStatesBaseTest.java index 8f0ec9da25d9..d07da684dbe9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/AdminStatesBaseTest.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/AdminStatesBaseTest.java @@ -18,7 +18,6 @@ package org.apache.hadoop.hdfs; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.io.IOException; @@ -30,8 +29,6 @@ import java.util.Map; import java.util.Random; import org.apache.hadoop.thirdparty.com.google.common.collect.Lists; -import org.junit.Rule; -import org.junit.rules.TemporaryFolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.conf.Configuration; @@ -67,9 +64,6 @@ public class AdminStatesBaseTest { final private Random myrand = new Random(); - @Rule - public TemporaryFolder baseDir = new TemporaryFolder(); - private HostsFileWriter hostsFileWriter; private Configuration conf; private MiniDFSCluster cluster = null; @@ -402,7 +396,7 @@ public class AdminStatesBaseTest { protected void startCluster(int numNameNodes, int numDatanodes, boolean setupHostsFile, long[] nodesCapacity, boolean checkDataNodeHostConfig, boolean federation) throws IOException { - MiniDFSCluster.Builder builder = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + MiniDFSCluster.Builder builder = new MiniDFSCluster.Builder(conf) .numDataNodes(numDatanodes); if (federation) { builder.nnTopology( @@ -437,7 +431,7 @@ public class AdminStatesBaseTest { protected void startSimpleHACluster(int numDatanodes) throws IOException { - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + cluster = new MiniDFSCluster.Builder(conf) .nnTopology(MiniDFSNNTopology.simpleHATopology()).numDataNodes( numDatanodes).build(); cluster.transitionToActive(0); @@ -464,6 +458,6 @@ public class AdminStatesBaseTest { throws IOException { assertTrue(fileSys.exists(name)); fileSys.delete(name, true); - assertFalse(fileSys.exists(name)); + assertTrue(!fileSys.exists(name)); } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java index e0b966008c3e..4dafbbe57418 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java @@ -248,10 +248,7 @@ public class MiniDFSCluster implements AutoCloseable { "MiniDFSCluster base directory cannot be null"); } String cdir = conf.get(HDFS_MINIDFS_BASEDIR); - // There are tests which restart server, and we want to allow them to restart with the same - // configuration. Although it is an error if the base directory is already set, we'll ignore - // cases where the base directory is the same. - if (cdir != null && !cdir.equals(basedir.getAbsolutePath())) { + if (cdir != null) { throw new IllegalArgumentException( "MiniDFSCluster base directory already defined (" + cdir + ")"); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSStripedInputStream.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSStripedInputStream.java index 9d3bdbf4e952..2369d42482a4 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSStripedInputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSStripedInputStream.java @@ -17,7 +17,6 @@ */ package org.apache.hadoop.hdfs; -import org.junit.rules.TemporaryFolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.HadoopIllegalArgumentException; @@ -87,9 +86,6 @@ public class TestDFSStripedInputStream { @Rule public Timeout globalTimeout = new Timeout(300000); - @Rule - public TemporaryFolder baseDir = new TemporaryFolder(); - public ErasureCodingPolicy getEcPolicy() { return StripedFileTestUtil.getDefaultECPolicy(); } @@ -114,12 +110,14 @@ public class TestDFSStripedInputStream { CodecUtil.IO_ERASURECODE_CODEC_RS_RAWCODERS_KEY, NativeRSRawErasureCoderFactory.CODER_NAME); } + conf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, + GenericTestUtils.getRandomizedTempPath()); SimulatedFSDataset.setFactory(conf); startUp(); } private void startUp() throws IOException { - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).numDataNodes( + cluster = new MiniDFSCluster.Builder(conf).numDataNodes( dataBlocks + parityBlocks).build(); cluster.waitActive(); for (DataNode dn : cluster.getDataNodes()) { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDecommissionWithStriped.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDecommissionWithStriped.java index c4457c5b1c3a..c68cb1707c2f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDecommissionWithStriped.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDecommissionWithStriped.java @@ -37,7 +37,6 @@ import org.apache.hadoop.fs.BlockLocation; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileChecksum; import org.apache.hadoop.fs.FileSystem; -import org.apache.hadoop.fs.LocalFileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hdfs.MiniDFSCluster.DataNodeProperties; import org.apache.hadoop.hdfs.client.HdfsDataInputStream; @@ -63,12 +62,11 @@ import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter; import org.apache.hadoop.security.token.Token; import org.apache.hadoop.test.GenericTestUtils; +import org.apache.hadoop.test.PathUtils; import org.junit.After; import org.junit.Assert; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.TemporaryFolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -92,10 +90,7 @@ public class TestDecommissionWithStriped { private Path decommissionDir; private Path hostsFile; private Path excludeFile; - private LocalFileSystem localFileSys; - - @Rule - public TemporaryFolder baseDir = new TemporaryFolder(); + private FileSystem localFileSys; private Configuration conf; private MiniDFSCluster cluster; @@ -123,9 +118,9 @@ public class TestDecommissionWithStriped { conf = createConfiguration(); // Set up the hosts/exclude files. localFileSys = FileSystem.getLocal(conf); - localFileSys.setWorkingDirectory(new Path(baseDir.getRoot().getPath())); Path workingDir = localFileSys.getWorkingDirectory(); - decommissionDir = new Path(workingDir, "work-dir/decommission"); + decommissionDir = new Path(workingDir, + PathUtils.getTestDirName(getClass()) + "/work-dir/decommission"); hostsFile = new Path(decommissionDir, "hosts"); excludeFile = new Path(decommissionDir, "exclude"); writeConfigFile(hostsFile, null); @@ -587,14 +582,16 @@ public class TestDecommissionWithStriped { localFileSys.delete(name, true); } - try (FSDataOutputStream stm = localFileSys.create(name)) { - if (nodes != null) { - for (String node: nodes) { - stm.writeBytes(node); - stm.writeBytes("\n"); - } + FSDataOutputStream stm = localFileSys.create(name); + + if (nodes != null) { + for (Iterator<String> it = nodes.iterator(); it.hasNext();) { + String node = it.next(); + stm.writeBytes(node); + stm.writeBytes("\n"); } } + stm.close(); } private void cleanupFile(FileSystem fileSys, Path name) throws IOException { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestReconstructStripedFile.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestReconstructStripedFile.java index f28b04bded86..3d35511d05d4 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestReconstructStripedFile.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestReconstructStripedFile.java @@ -41,8 +41,6 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.hadoop.hdfs.protocol.LocatedBlock; import org.apache.hadoop.hdfs.server.datanode.erasurecode.ErasureCodingTestHelper; import org.apache.hadoop.io.ElasticByteBufferPool; -import org.junit.Rule; -import org.junit.rules.TemporaryFolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.conf.Configuration; @@ -98,9 +96,6 @@ public class TestReconstructStripedFile { Any } - @Rule - public TemporaryFolder baseDir = new TemporaryFolder(); - private Configuration conf; private MiniDFSCluster cluster; private DistributedFileSystem fs; @@ -155,7 +150,8 @@ public class TestReconstructStripedFile { getPendingTimeout()); conf.setBoolean(DFSConfigKeys.DFS_DN_EC_RECONSTRUCTION_VALIDATION_KEY, isValidationEnabled()); - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).numDataNodes(dnNum) + File basedir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, basedir).numDataNodes(dnNum) .build(); cluster.waitActive(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgrade.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgrade.java index cd05994b5bdc..495195a0c591 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgrade.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgrade.java @@ -86,7 +86,28 @@ public class TestRollingUpgrade { } @Rule - public TemporaryFolder baseDir = new TemporaryFolder(); + public TemporaryFolder folder = new TemporaryFolder(); + + /** + * Create a default HDFS configuration which has test-specific data directories. This is + * intended to protect against interactions between test runs that might corrupt results. Each + * test run's data is automatically cleaned-up by JUnit. + * + * @return a default configuration with test-specific data directories + */ + public Configuration getHdfsConfiguration() throws IOException { + Configuration conf = new HdfsConfiguration(); + + // Override the file system locations with test-specific temporary folders + conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, + folder.newFolder("dfs/name").toString()); + conf.set(DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_DIR_KEY, + folder.newFolder("dfs/namesecondary").toString()); + conf.set(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY, + folder.newFolder("dfs/data").toString()); + + return conf; + } /** * Test DFSAdmin Upgrade Command. @@ -94,10 +115,8 @@ public class TestRollingUpgrade { @Test public void testDFSAdminRollingUpgradeCommands() throws Exception { // start a cluster - final Configuration conf = new HdfsConfiguration(); - try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) - .numDataNodes(0) - .build()) { + final Configuration conf = getHdfsConfiguration(); + try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build()) { cluster.waitActive(); final Path foo = new Path("/foo"); @@ -178,15 +197,14 @@ public class TestRollingUpgrade { LOG.info("nn1Dir=" + nn1Dir); LOG.info("nn2Dir=" + nn2Dir); - final Configuration conf = new HdfsConfiguration(); - try (MiniJournalCluster mjc = new MiniJournalCluster.Builder(conf, baseDir.getRoot()) - .build()) { + final Configuration conf = getHdfsConfiguration(); + try (MiniJournalCluster mjc = new MiniJournalCluster.Builder(conf).build()) { mjc.waitActive(); setConf(conf, nn1Dir, mjc); { // Start the cluster once to generate the dfs dirs - final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf) .numDataNodes(0) .manageNameDfsDirs(false) .checkExitOnShutdown(false) @@ -206,7 +224,7 @@ public class TestRollingUpgrade { new Path(nn2Dir.getAbsolutePath()), false, conf); // Start the cluster again - final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf) .numDataNodes(0) .format(false) .manageNameDfsDirs(false) @@ -317,10 +335,8 @@ public class TestRollingUpgrade { @Test public void testRollback() throws Exception { // start a cluster - final Configuration conf = new HdfsConfiguration(); - try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) - .numDataNodes(1) - .build()) { + final Configuration conf = getHdfsConfiguration(); + try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build()) { cluster.waitActive(); final Path foo = new Path("/foo"); @@ -413,10 +429,8 @@ public class TestRollingUpgrade { @Test public void testDFSAdminDatanodeUpgradeControlCommands() throws Exception { // start a cluster - final Configuration conf = new HdfsConfiguration(); - try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) - .numDataNodes(1) - .build()) { + final Configuration conf = getHdfsConfiguration(); + try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build()) { cluster.waitActive(); final DFSAdmin dfsadmin = new DFSAdmin(conf); DataNode dn = cluster.getDataNodes().get(0); @@ -466,14 +480,13 @@ public class TestRollingUpgrade { private void testFinalize(int nnCount, boolean skipImageDeltaCheck) throws Exception { - final Configuration conf = new HdfsConfiguration(); + final Configuration conf = getHdfsConfiguration(); MiniQJMHACluster cluster = null; final Path foo = new Path("/foo"); final Path bar = new Path("/bar"); try { - cluster = new MiniQJMHACluster.Builder(conf, baseDir.getRoot()) - .setNumNameNodes(nnCount).build(); + cluster = new MiniQJMHACluster.Builder(conf).setNumNameNodes(nnCount).build(); MiniDFSCluster dfsCluster = cluster.getDfsCluster(); dfsCluster.waitActive(); @@ -533,10 +546,8 @@ public class TestRollingUpgrade { } private void testQuery(int nnCount) throws Exception{ - final Configuration conf = new HdfsConfiguration(); - try (MiniQJMHACluster cluster = new MiniQJMHACluster.Builder(conf, baseDir.getRoot()) - .setNumNameNodes(nnCount) - .build()) { + final Configuration conf = getHdfsConfiguration(); + try (MiniQJMHACluster cluster = new MiniQJMHACluster.Builder(conf).setNumNameNodes(nnCount).build()) { MiniDFSCluster dfsCluster = cluster.getDfsCluster(); dfsCluster.waitActive(); @@ -571,10 +582,8 @@ public class TestRollingUpgrade { @Test (timeout = 300000) public void testQueryAfterRestart() throws IOException, InterruptedException { - final Configuration conf = new HdfsConfiguration(); - try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) - .numDataNodes(0) - .build()) { + final Configuration conf = getHdfsConfiguration(); + try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build()) { cluster.waitActive(); DistributedFileSystem dfs = cluster.getFileSystem(); @@ -603,14 +612,14 @@ public class TestRollingUpgrade { @Test(timeout = 60000) public void testRollBackImage() throws Exception { - final Configuration conf = new HdfsConfiguration(); + final Configuration conf = getHdfsConfiguration(); conf.setInt(DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_TXNS_KEY, 10); conf.setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1); conf.setInt(DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_CHECK_PERIOD_KEY, 2); MiniQJMHACluster cluster = null; CheckpointFaultInjector old = CheckpointFaultInjector.getInstance(); try { - cluster = new MiniQJMHACluster.Builder(conf, baseDir.getRoot()).setNumNameNodes(2).build(); + cluster = new MiniQJMHACluster.Builder(conf).setNumNameNodes(2).build(); MiniDFSCluster dfsCluster = cluster.getDfsCluster(); dfsCluster.waitActive(); dfsCluster.transitionToActive(0); @@ -648,14 +657,13 @@ public class TestRollingUpgrade { } public void testCheckpoint(int nnCount) throws IOException, InterruptedException { - final Configuration conf = new HdfsConfiguration(); + final Configuration conf = getHdfsConfiguration(); conf.setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1); conf.setInt(DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_PERIOD_KEY, 1); final Path foo = new Path("/foo"); - try (MiniQJMHACluster cluster = new MiniQJMHACluster.Builder(conf, baseDir.getRoot()) - .setNumNameNodes(nnCount) + try (MiniQJMHACluster cluster = new MiniQJMHACluster.Builder(conf).setNumNameNodes(nnCount) .build()) { MiniDFSCluster dfsCluster = cluster.getDfsCluster(); dfsCluster.waitActive(); @@ -759,8 +767,8 @@ public class TestRollingUpgrade { SecondaryNameNode snn = null; try { - Configuration conf = new HdfsConfiguration(); - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).build(); + Configuration conf = getHdfsConfiguration(); + cluster = new MiniDFSCluster.Builder(conf).build(); cluster.waitActive(); conf.set(DFSConfigKeys.DFS_NAMENODE_SECONDARY_HTTP_ADDRESS_KEY, diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/MiniJournalCluster.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/MiniJournalCluster.java index 89cfe76d20d1..15f8f1164a23 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/MiniJournalCluster.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/MiniJournalCluster.java @@ -18,6 +18,7 @@ package org.apache.hadoop.hdfs.qjournal; import static org.apache.hadoop.hdfs.qjournal.QJMTestUtil.FAKE_NSINFO; +import static org.junit.Assert.fail; import java.io.Closeable; import java.io.File; @@ -62,12 +63,7 @@ public final class MiniJournalCluster implements Closeable { public Builder(Configuration conf) { this.conf = conf; } - - public Builder(Configuration conf, File baseDir) { - this.conf = conf; - baseDir(baseDir.toString()); - } - + public Builder baseDir(String d) { this.baseDir = d; return this; @@ -292,8 +288,7 @@ public final class MiniJournalCluster implements Closeable { } }, 50, 3000); } catch (TimeoutException e) { - throw new AssertionError("Time out while waiting for journal node " + index + - " to start."); + fail("Time out while waiting for journal node " + index + " to start."); } catch (InterruptedException ite) { LOG.warn("Thread interrupted when waiting for node start", ite); } 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 dd0ccd729efb..0791e0ace1c0 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 @@ -28,7 +28,6 @@ import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider; import org.apache.hadoop.hdfs.server.namenode.ha.HATestUtil; -import java.io.File; import java.io.IOException; import java.net.BindException; import java.net.URI; @@ -61,13 +60,6 @@ public class MiniQJMHACluster implements AutoCloseable { this.dfsBuilder = new MiniDFSCluster.Builder(conf).numDataNodes(0); } - public Builder(Configuration conf, File baseDir) { - this.conf = conf; - // most QJMHACluster tests don't need DataNodes, so we'll make - // this the default - this.dfsBuilder = new MiniDFSCluster.Builder(conf, baseDir).numDataNodes(0); - } - public MiniDFSCluster.Builder getDfsBuilder() { return dfsBuilder; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBPOfferService.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBPOfferService.java index 6d9a79fd1cef..d5dbdbcdc541 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBPOfferService.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestBPOfferService.java @@ -88,9 +88,7 @@ import org.apache.hadoop.test.PathUtils; import org.apache.hadoop.util.Time; import org.apache.log4j.Level; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.TemporaryFolder; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; @@ -119,9 +117,6 @@ public class TestBPOfferService { GenericTestUtils.setLogLevel(DataNode.LOG, Level.ALL); } - @Rule - public TemporaryFolder baseDir = new TemporaryFolder(); - private DatanodeProtocolClientSideTranslatorPB mockNN1; private DatanodeProtocolClientSideTranslatorPB mockNN2; private final NNHAStatusHeartbeat[] mockHaStatuses = @@ -1190,7 +1185,8 @@ public class TestBPOfferService { @Test(timeout = 15000) public void testCommandProcessingThread() throws Exception { Configuration conf = new HdfsConfiguration(); - try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).build()) { + MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build(); + try { List<DataNode> datanodes = cluster.getDataNodes(); assertEquals(datanodes.size(), 1); DataNode datanode = datanodes.get(0); @@ -1207,14 +1203,19 @@ public class TestBPOfferService { // Check new metric result about processedCommandsOp. // One command send back to DataNode here is #FinalizeCommand. assertCounter("ProcessedCommandsOpNumOps", 1L, mrb); + } finally { + if (cluster != null) { + cluster.shutdown(); + } } } @Test(timeout = 5000) public void testCommandProcessingThreadExit() throws Exception { Configuration conf = new HdfsConfiguration(); - try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()). - numDataNodes(1).build()) { + MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf). + numDataNodes(1).build(); + try { List<DataNode> datanodes = cluster.getDataNodes(); DataNode dataNode = datanodes.get(0); List<BPOfferService> allBpOs = dataNode.getAllBpOs(); @@ -1224,6 +1225,10 @@ public class TestBPOfferService { // Stop and wait util actor exit. actor.stopCommandProcessingThread(); GenericTestUtils.waitFor(() -> !actor.isAlive(), 100, 3000); + } finally { + if (cluster != null) { + cluster.shutdown(); + } } } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeRollingUpgrade.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeRollingUpgrade.java index 8042f9c37d39..f285ce3cee85 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeRollingUpgrade.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeRollingUpgrade.java @@ -27,8 +27,6 @@ import java.util.Random; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.junit.Rule; -import org.junit.rules.TemporaryFolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.conf.Configuration; @@ -66,9 +64,6 @@ public class TestDataNodeRollingUpgrade { private static final long FILE_SIZE = BLOCK_SIZE; private static final long SEED = 0x1BADF00DL; - @Rule - public TemporaryFolder baseDir = new TemporaryFolder(); - Configuration conf; MiniDFSCluster cluster = null; DistributedFileSystem fs = null; @@ -79,7 +74,7 @@ public class TestDataNodeRollingUpgrade { private void startCluster() throws IOException { conf = new HdfsConfiguration(); conf.setInt("dfs.blocksize", 1024*1024); - cluster = new Builder(conf, baseDir.getRoot()).numDataNodes(REPL_FACTOR).build(); + cluster = new Builder(conf).numDataNodes(REPL_FACTOR).build(); cluster.waitActive(); fs = cluster.getFileSystem(); nn = cluster.getNameNode(0); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java index fda693baf63a..d24db799a249 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java @@ -19,6 +19,7 @@ package org.apache.hadoop.hdfs.server.namenode; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_CORRUPT_BLOCK_DELETE_IMMEDIATELY_ENABLED; +import static org.apache.hadoop.hdfs.MiniDFSCluster.HDFS_MINIDFS_BASEDIR; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -127,12 +128,9 @@ import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.junit.Rule; -import org.junit.rules.TemporaryFolder; import org.apache.hadoop.thirdparty.com.google.common.collect.Sets; - /** * A JUnit test for doing fsck. */ @@ -184,9 +182,6 @@ public class TestFsck { return bStream.toString(); } - @Rule - public TemporaryFolder baseDir = new TemporaryFolder(); - private MiniDFSCluster cluster = null; private Configuration conf = null; @@ -218,7 +213,8 @@ public class TestFsck { conf.setLong(DFSConfigKeys.DFS_NAMENODE_ACCESSTIME_PRECISION_KEY, precision); conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 10000L); - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(4).build(); fs = cluster.getFileSystem(); final String fileName = "/srcdat"; @@ -236,7 +232,7 @@ public class TestFsck { shutdownCluster(); // restart the cluster; bring up namenode but not the data nodes - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + cluster = new MiniDFSCluster.Builder(conf) .numDataNodes(0).format(false).build(); outStr = runFsck(conf, 1, true, "/"); // expect the result is corrupt @@ -308,7 +304,8 @@ public class TestFsck { setNumFiles(20).build(); FileSystem fs = null; conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 10000L); - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(4).build(); fs = cluster.getFileSystem(); util.createFiles(fs, "/srcdat"); @@ -327,7 +324,8 @@ public class TestFsck { conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 10000L); // Create a cluster with the current user, write some files - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(4).build(); final MiniDFSCluster c2 = cluster; final String dir = "/dfsck"; @@ -374,7 +372,8 @@ public class TestFsck { DFSTestUtil util = new DFSTestUtil("TestFsck", 5, 3, (5 * dfsBlockSize) + (dfsBlockSize - 1), 5 * dfsBlockSize); FileSystem fs = null; - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(numDatanodes).build(); String topDir = "/srcdat"; fs = cluster.getFileSystem(); @@ -581,7 +580,8 @@ public class TestFsck { FileSystem fs = null; conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 10000L); conf.setInt(DFSConfigKeys.DFS_DATANODE_DIRECTORYSCAN_INTERVAL_KEY, 1); - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(4).build(); String topDir = "/srcdat"; fs = cluster.getFileSystem(); @@ -646,7 +646,8 @@ public class TestFsck { setNumFiles(4).build(); FileSystem fs = null; conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 10000L); - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(4).build(); String topDir = "/srcdat"; String randomString = "HADOOP "; @@ -700,7 +701,8 @@ public class TestFsck { final int numAllUnits = dataBlocks + ecPolicy.getNumParityUnits(); int blockSize = 2 * cellSize; conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, blockSize); - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).numDataNodes( + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir).numDataNodes( numAllUnits + 1).build(); String topDir = "/myDir"; cluster.waitActive(); @@ -791,7 +793,8 @@ public class TestFsck { String outStr = null; short factor = 1; - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(1).build(); cluster.waitActive(); fs = cluster.getFileSystem(); @@ -863,7 +866,8 @@ public class TestFsck { Random random = new Random(); String outStr = null; short factor = 1; - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(2).build(); cluster.waitActive(); fs = cluster.getFileSystem(); @@ -936,7 +940,8 @@ public class TestFsck { conf.setInt(DFSConfigKeys.DFS_REPLICATION_KEY, 1); DistributedFileSystem dfs; - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(numDn).hosts(hosts).racks(racks).build(); cluster.waitClusterUp(); dfs = cluster.getFileSystem(); @@ -1084,7 +1089,8 @@ public class TestFsck { @Test public void testFsckError() throws Exception { // bring up a one-node cluster - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).build(); + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir).build(); String fileName = "/test.txt"; Path filePath = new Path(fileName); FileSystem fs = cluster.getFileSystem(); @@ -1116,7 +1122,8 @@ public class TestFsck { conf.setInt(DFSConfigKeys.DFS_DATANODE_DIRECTORYSCAN_INTERVAL_KEY, 1); FileSystem fs = null; - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).build(); + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir).build(); cluster.waitActive(); fs = cluster.getFileSystem(); DFSTestUtil util = new DFSTestUtil.Builder(). @@ -1175,7 +1182,8 @@ public class TestFsck { @Test public void testToCheckTheFsckCommandOnIllegalArguments() throws Exception { // bring up a one-node cluster - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).build(); + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir).build(); String fileName = "/test.txt"; Path filePath = new Path(fileName); FileSystem fs = cluster.getFileSystem(); @@ -1219,7 +1227,8 @@ public class TestFsck { DistributedFileSystem dfs = null; // Startup a minicluster - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(numReplicas).build(); assertNotNull("Failed Cluster Creation", cluster); cluster.waitClusterUp(); @@ -1280,7 +1289,8 @@ public class TestFsck { DistributedFileSystem dfs = null; // Startup a minicluster - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(numDn).hosts(hosts).racks(racks).build(); assertNotNull("Failed Cluster Creation", cluster); cluster.waitClusterUp(); @@ -1388,7 +1398,8 @@ public class TestFsck { conf.setLong(DFSConfigKeys.DFS_NAMENODE_ACCESSTIME_PRECISION_KEY, precision); conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 10000L); - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(4).build(); fs = cluster.getFileSystem(); final String fileName = "/srcdat"; @@ -1416,7 +1427,8 @@ public class TestFsck { */ @Test public void testFsckForSnapshotFiles() throws Exception { - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).numDataNodes(1) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir).numDataNodes(1) .build(); String runFsck = runFsck(conf, 0, true, "/", "-includeSnapshots", "-files"); @@ -1451,7 +1463,8 @@ public class TestFsck { conf.setInt(DFSConfigKeys.DFS_REPLICATION_KEY, 2); DistributedFileSystem dfs = null; - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(numDn).hosts(hosts).racks(racks).build(); assertNotNull("Failed Cluster Creation", cluster); @@ -1505,7 +1518,8 @@ public class TestFsck { conf.setInt(DFSConfigKeys.DFS_REPLICATION_KEY, 2); DistributedFileSystem dfs; - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(numDn).hosts(hosts).racks(racks).build(); assertNotNull("Failed Cluster Creation", cluster); @@ -1589,7 +1603,8 @@ public class TestFsck { replFactor); DistributedFileSystem dfs; - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(numDn) .hosts(hosts) .racks(racks) @@ -1710,7 +1725,8 @@ public class TestFsck { conf.setInt(DFSConfigKeys.DFS_REPLICATION_KEY, 1); DistributedFileSystem dfs = null; - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(numDn).hosts(hosts).racks(racks).build(); assertNotNull("Failed Cluster Creation", cluster); @@ -1778,7 +1794,8 @@ public class TestFsck { */ @Test public void testStoragePoliciesCK() throws Exception { - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(3) .storageTypes( new StorageType[] {StorageType.DISK, StorageType.ARCHIVE}) @@ -1821,7 +1838,8 @@ public class TestFsck { conf.setInt(DFSConfigKeys.DFS_REPLICATION_KEY, 1); DistributedFileSystem dfs; - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(numDn).hosts(hosts).racks(racks).build(); assertNotNull("Failed Cluster Creation", cluster); @@ -1902,7 +1920,8 @@ public class TestFsck { replFactor); DistributedFileSystem dfs; - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(numDn) .hosts(hosts) .racks(racks) @@ -2010,7 +2029,8 @@ public class TestFsck { int parityBlocks = StripedFileTestUtil.getDefaultECPolicy().getNumParityUnits(); int totalSize = dataBlocks + parityBlocks; - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(totalSize).build(); fs = cluster.getFileSystem(); fs.enableErasureCodingPolicy( @@ -2046,7 +2066,7 @@ public class TestFsck { shutdownCluster(); // restart the cluster; bring up namenode but not the data nodes - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + cluster = new MiniDFSCluster.Builder(conf) .numDataNodes(0).format(false).build(); outStr = runFsck(conf, 1, true, "/", "-files", "-blocks"); // expect the result is corrupt @@ -2078,7 +2098,8 @@ public class TestFsck { int numFiles = 3; int numSnapshots = 0; - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).build(); + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir).build(); cluster.waitActive(); hdfs = cluster.getFileSystem(); DFSTestUtil util = new DFSTestUtil.Builder(). @@ -2172,7 +2193,8 @@ public class TestFsck { conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 1000L); conf.setInt(DFSConfigKeys.DFS_DATANODE_DIRECTORYSCAN_INTERVAL_KEY, 1); conf.setInt(DFSConfigKeys.DFS_REPLICATION_KEY, replication); - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).build(); + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir).build(); DistributedFileSystem dfs = cluster.getFileSystem(); cluster.waitActive(); @@ -2267,6 +2289,7 @@ public class TestFsck { HostsFileWriter hostsFileWriter = new HostsFileWriter(); conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, blockSize); conf.setInt(DFSConfigKeys.DFS_REPLICATION_KEY, replFactor); + conf.set(HDFS_MINIDFS_BASEDIR, GenericTestUtils.getRandomizedTempPath()); if (defineUpgradeDomain) { conf.setClass(DFSConfigKeys.DFS_NAMENODE_HOSTS_PROVIDER_CLASSNAME_KEY, CombinedHostFileManager.class, HostConfigManager.class); @@ -2274,7 +2297,7 @@ public class TestFsck { } DistributedFileSystem dfs; - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).numDataNodes(numDN). + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(numDN). hosts(hosts).racks(racks).build(); cluster.waitClusterUp(); dfs = cluster.getFileSystem(); @@ -2318,7 +2341,8 @@ public class TestFsck { StripedFileTestUtil.getDefaultECPolicy().getNumParityUnits(); int cellSize = StripedFileTestUtil.getDefaultECPolicy().getCellSize(); int totalSize = dataBlocks + parityBlocks; - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(totalSize).build(); fs = cluster.getFileSystem(); fs.enableErasureCodingPolicy( @@ -2389,7 +2413,8 @@ public class TestFsck { StripedFileTestUtil.getDefaultECPolicy().getNumParityUnits(); int cellSize = StripedFileTestUtil.getDefaultECPolicy().getCellSize(); int totalSize = dataBlocks + parityBlocks; - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + File builderBaseDir = new File(GenericTestUtils.getRandomizedTempPath()); + cluster = new MiniDFSCluster.Builder(conf, builderBaseDir) .numDataNodes(totalSize).build(); fs = cluster.getFileSystem(); fs.enableErasureCodingPolicy( @@ -2450,7 +2475,8 @@ public class TestFsck { @Test(timeout = 300000) public void testFsckCorruptWhenOneReplicaIsCorrupt() throws Exception { - try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf, + new File(GenericTestUtils.getRandomizedTempPath())) .nnTopology(MiniDFSNNTopology.simpleHATopology()).numDataNodes(2) .build()) { cluster.waitActive(); @@ -2479,7 +2505,7 @@ public class TestFsck { @Test public void testFsckNonPrivilegedListCorrupt() throws Exception { - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).numDataNodes(4).build(); + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(4).build(); UserGroupInformation ugi = UserGroupInformation.createUserForTesting("systest", new String[]{""}); ugi.doAs(new PrivilegedExceptionAction<Void>() { @Override diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMXBean.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMXBean.java index bc46c4857a15..d670025bf506 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMXBean.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeMXBean.java @@ -57,10 +57,8 @@ import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.util.Time; import org.apache.hadoop.util.VersionInfo; import org.junit.Assert; -import org.junit.Rule; import org.junit.Test; import org.eclipse.jetty.util.ajax.JSON; -import org.junit.rules.TemporaryFolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -99,9 +97,6 @@ public class TestNameNodeMXBean { */ private static final double DELTA = 0.000001; - @Rule - public TemporaryFolder baseDir = new TemporaryFolder(); - static { NativeIO.POSIX.setCacheManipulator(new NoMlockCacheManipulator()); } @@ -117,7 +112,7 @@ public class TestNameNodeMXBean { MiniDFSCluster cluster = null; try { - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).numDataNodes(4).build(); + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(4).build(); cluster.waitActive(); // Set upgrade domain on the first DN. @@ -144,7 +139,7 @@ public class TestNameNodeMXBean { String clusterId = (String) mbs.getAttribute(mxbeanName, "ClusterId"); assertEquals(fsn.getClusterId(), clusterId); // get attribute "BlockPoolId" - String blockpoolId = (String) mbs.getAttribute(mxbeanName, + String blockpoolId = (String) mbs.getAttribute(mxbeanName, "BlockPoolId"); assertEquals(fsn.getBlockPoolId(), blockpoolId); // get attribute "Version" @@ -275,7 +270,7 @@ public class TestNameNodeMXBean { assertEquals(0, FileUtil.chmod( new File(failedNameDir, "current").getAbsolutePath(), "000")); cluster.getNameNodeRpc().rollEditLog(); - + nameDirStatuses = (String) (mbs.getAttribute(mxbeanName, "NameDirStatuses")); statusMap = (Map<String, Map<String, String>>) JSON.parse(nameDirStatuses); @@ -318,7 +313,7 @@ public class TestNameNodeMXBean { hostsFileWriter.initialize(conf, "temp/TestNameNodeMXBean"); try { - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).numDataNodes(3).build(); + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(3).build(); cluster.waitActive(); FSNamesystem fsn = cluster.getNameNode().namesystem; @@ -371,7 +366,7 @@ public class TestNameNodeMXBean { hostsFileWriter.initialize(conf, "temp/TestNameNodeMXBean"); try { - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).numDataNodes(3).build(); + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(3).build(); cluster.waitActive(); FSNamesystem fsn = cluster.getNameNode().namesystem; @@ -474,7 +469,7 @@ public class TestNameNodeMXBean { hostsFileWriter.initialize(conf, "temp/TestInServiceNodes"); try { - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).numDataNodes(3).build(); + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(3).build(); cluster.waitActive(); final FSNamesystem fsn = cluster.getNameNode().namesystem; @@ -573,7 +568,7 @@ public class TestNameNodeMXBean { hostsFileWriter.initialize(conf, "temp/TestNameNodeMXBean"); try { - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).numDataNodes(3).build(); + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(3).build(); cluster.waitActive(); FSNamesystem fsn = cluster.getNameNode().namesystem; @@ -664,7 +659,7 @@ public class TestNameNodeMXBean { final Configuration conf = new Configuration(); MiniDFSCluster cluster = null; try { - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).numDataNodes(0).build(); + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build(); cluster.waitActive(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName mxbeanNameFsns = new ObjectName( @@ -680,7 +675,7 @@ public class TestNameNodeMXBean { (String) (mbs.getAttribute(mxbeanNameFsns, "TopUserOpCounts")); ObjectMapper mapper = new ObjectMapper(); Map<String, Object> map = mapper.readValue(topUsers, Map.class); - assertTrue("Could not find map key timestamp", + assertTrue("Could not find map key timestamp", map.containsKey("timestamp")); assertTrue("Could not find map key windows", map.containsKey("windows")); List<Map<String, List<Map<String, Object>>>> windows = @@ -720,7 +715,7 @@ public class TestNameNodeMXBean { conf.setBoolean(DFSConfigKeys.NNTOP_ENABLED_KEY, false); MiniDFSCluster cluster = null; try { - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).numDataNodes(0).build(); + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build(); cluster.waitActive(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName mxbeanNameFsns = new ObjectName( @@ -749,7 +744,7 @@ public class TestNameNodeMXBean { conf.set(DFSConfigKeys.NNTOP_WINDOWS_MINUTES_KEY, ""); MiniDFSCluster cluster = null; try { - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).numDataNodes(0).build(); + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build(); cluster.waitActive(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName mxbeanNameFsns = new ObjectName( @@ -776,7 +771,7 @@ public class TestNameNodeMXBean { final Configuration conf = new Configuration(); MiniDFSCluster cluster = null; try { - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()).numDataNodes(0).build(); + cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build(); cluster.waitActive(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName mxbeanNameFs = @@ -806,7 +801,7 @@ public class TestNameNodeMXBean { .addNN( new MiniDFSNNTopology.NNConf("nn2").setIpcPort(ports[1]))); - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + cluster = new MiniDFSCluster.Builder(conf) .nnTopology(topology).numDataNodes(0) .build(); break; @@ -868,7 +863,7 @@ public class TestNameNodeMXBean { int dataBlocks = defaultPolicy.getNumDataUnits(); int parityBlocks = defaultPolicy.getNumParityUnits(); int totalSize = dataBlocks + parityBlocks; - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + cluster = new MiniDFSCluster.Builder(conf) .numDataNodes(totalSize).build(); fs = cluster.getFileSystem(); @@ -908,7 +903,7 @@ public class TestNameNodeMXBean { StripedFileTestUtil.getDefaultECPolicy().getNumParityUnits(); int cellSize = StripedFileTestUtil.getDefaultECPolicy().getCellSize(); int totalSize = dataBlocks + parityBlocks; - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + cluster = new MiniDFSCluster.Builder(conf) .numDataNodes(totalSize).build(); fs = cluster.getFileSystem(); fs.enableErasureCodingPolicy( @@ -1051,7 +1046,7 @@ public class TestNameNodeMXBean { int blockSize = stripesPerBlock * cellSize; conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, blockSize); - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + cluster = new MiniDFSCluster.Builder(conf) .nnTopology(MiniDFSNNTopology.simpleHAFederatedTopology(1)). numDataNodes(totalSize).build(); cluster.waitActive(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestRetryCacheWithHA.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestRetryCacheWithHA.java index 8f8dd59a1fbf..e3e934b5e377 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestRetryCacheWithHA.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/ha/TestRetryCacheWithHA.java @@ -38,8 +38,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; import org.apache.hadoop.test.GenericTestUtils; -import org.junit.Rule; -import org.junit.rules.TemporaryFolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.conf.Configuration; @@ -108,10 +106,7 @@ public class TestRetryCacheWithHA { defaultEcPolicy.getNumParityUnits() + 1); private static final int CHECKTIMES = 10; private static final int ResponseSize = 3; - - @Rule - public TemporaryFolder baseDir = new TemporaryFolder(); - + private MiniDFSCluster cluster; private DistributedFileSystem dfs; private final Configuration conf = new HdfsConfiguration(); @@ -149,7 +144,7 @@ public class TestRetryCacheWithHA { conf.setInt(DFSConfigKeys.DFS_NAMENODE_LIST_CACHE_POOLS_NUM_RESPONSES, ResponseSize); conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_ACLS_ENABLED_KEY, true); conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_XATTRS_ENABLED_KEY, true); - cluster = new MiniDFSCluster.Builder(conf, baseDir.getRoot()) + cluster = new MiniDFSCluster.Builder(conf) .nnTopology(MiniDFSNNTopology.simpleHATopology()) .numDataNodes(DataNodes).build(); cluster.waitActive(); --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org