Skip to content

Commit 1c8f552

Browse files
author
Steve Vaughan Jr
committed
Use test-specific data directories
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.
1 parent e2b1133 commit 1c8f552

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestRollingUpgrade.java

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import javax.management.ReflectionException;
3434
import javax.management.openmbean.CompositeDataSupport;
3535

36+
import org.junit.Rule;
37+
import org.junit.rules.TemporaryFolder;
3638
import org.slf4j.Logger;
3739
import org.slf4j.LoggerFactory;
3840
import org.apache.hadoop.conf.Configuration;
@@ -80,13 +82,37 @@ public static void runCmd(DFSAdmin dfsadmin, boolean success,
8082
}
8183
}
8284

85+
@Rule
86+
public TemporaryFolder folder= new TemporaryFolder();
87+
88+
/**
89+
* Create a default HDFS configuration which has test-specific data directories. This is
90+
* intended to protect against interactions between test runs that might corrupt results. Each
91+
* test run's data is automatically cleaned-up by JUnit.
92+
*
93+
* @return a default configuration with test-specific data directories
94+
*/
95+
public Configuration getHdfsConfiguration() throws IOException {
96+
Configuration conf = new HdfsConfiguration();
97+
98+
// Override the file system locations with test-specific temporary folders
99+
conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY,
100+
folder.newFolder("dfs/name").toString());
101+
conf.set(DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_DIR_KEY,
102+
folder.newFolder("dfs/namesecondary").toString());
103+
conf.set(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY,
104+
folder.newFolder("dfs/data").toString());
105+
106+
return conf;
107+
}
108+
83109
/**
84110
* Test DFSAdmin Upgrade Command.
85111
*/
86112
@Test
87113
public void testDFSAdminRollingUpgradeCommands() throws Exception {
88114
// start a cluster
89-
final Configuration conf = new HdfsConfiguration();
115+
final Configuration conf = getHdfsConfiguration();
90116
try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build()) {
91117
cluster.waitActive();
92118

@@ -168,7 +194,7 @@ public void testRollingUpgradeWithQJM() throws Exception {
168194
LOG.info("nn1Dir=" + nn1Dir);
169195
LOG.info("nn2Dir=" + nn2Dir);
170196

171-
final Configuration conf = new HdfsConfiguration();
197+
final Configuration conf = getHdfsConfiguration();
172198
try (MiniJournalCluster mjc = new MiniJournalCluster.Builder(conf).build()) {
173199
mjc.waitActive();
174200
setConf(conf, nn1Dir, mjc);
@@ -306,7 +332,7 @@ private static void checkMxBean() throws Exception {
306332
@Test
307333
public void testRollback() throws Exception {
308334
// start a cluster
309-
final Configuration conf = new HdfsConfiguration();
335+
final Configuration conf = getHdfsConfiguration();
310336
try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build()) {
311337
cluster.waitActive();
312338

@@ -400,7 +426,7 @@ private static void rollbackRollingUpgrade(Path foo, Path bar,
400426
@Test
401427
public void testDFSAdminDatanodeUpgradeControlCommands() throws Exception {
402428
// start a cluster
403-
final Configuration conf = new HdfsConfiguration();
429+
final Configuration conf = getHdfsConfiguration();
404430
try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build()){
405431
cluster.waitActive();
406432
final DFSAdmin dfsadmin = new DFSAdmin(conf);
@@ -451,7 +477,7 @@ private void testFinalize(int nnCount) throws Exception {
451477

452478
private void testFinalize(int nnCount, boolean skipImageDeltaCheck)
453479
throws Exception {
454-
final Configuration conf = new HdfsConfiguration();
480+
final Configuration conf = getHdfsConfiguration();
455481
MiniQJMHACluster cluster = null;
456482
final Path foo = new Path("/foo");
457483
final Path bar = new Path("/bar");
@@ -517,7 +543,7 @@ public void testQueryWithMultipleNN() throws Exception {
517543
}
518544

519545
private void testQuery(int nnCount) throws Exception{
520-
final Configuration conf = new Configuration();
546+
final Configuration conf = getHdfsConfiguration();
521547
try (MiniQJMHACluster cluster = new MiniQJMHACluster.Builder(conf).setNumNameNodes(nnCount).build()) {
522548
MiniDFSCluster dfsCluster = cluster.getDfsCluster();
523549
dfsCluster.waitActive();
@@ -553,7 +579,7 @@ private void testQuery(int nnCount) throws Exception{
553579

554580
@Test (timeout = 300000)
555581
public void testQueryAfterRestart() throws IOException, InterruptedException {
556-
final Configuration conf = new Configuration();
582+
final Configuration conf = getHdfsConfiguration();
557583
try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build()) {
558584
cluster.waitActive();
559585
DistributedFileSystem dfs = cluster.getFileSystem();
@@ -583,7 +609,7 @@ public void testCheckpointWithMultipleNN() throws IOException, InterruptedExcept
583609

584610
@Test(timeout = 60000)
585611
public void testRollBackImage() throws Exception {
586-
final Configuration conf = new Configuration();
612+
final Configuration conf = getHdfsConfiguration();
587613
conf.setInt(DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_TXNS_KEY, 10);
588614
conf.setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1);
589615
conf.setInt(DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_CHECK_PERIOD_KEY, 2);
@@ -628,7 +654,7 @@ public void duringUploadInProgess()
628654
}
629655

630656
public void testCheckpoint(int nnCount) throws IOException, InterruptedException {
631-
final Configuration conf = new Configuration();
657+
final Configuration conf = getHdfsConfiguration();
632658
conf.setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1);
633659
conf.setInt(DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_PERIOD_KEY, 1);
634660

@@ -705,7 +731,7 @@ public void testCheckpointWithSNN() throws Exception {
705731
SecondaryNameNode snn = null;
706732

707733
try {
708-
Configuration conf = new HdfsConfiguration();
734+
Configuration conf = getHdfsConfiguration();
709735
cluster = new MiniDFSCluster.Builder(conf).build();
710736
cluster.waitActive();
711737

0 commit comments

Comments
 (0)