|
33 | 33 | import javax.management.ReflectionException; |
34 | 34 | import javax.management.openmbean.CompositeDataSupport; |
35 | 35 |
|
| 36 | +import org.junit.Rule; |
| 37 | +import org.junit.rules.TemporaryFolder; |
36 | 38 | import org.slf4j.Logger; |
37 | 39 | import org.slf4j.LoggerFactory; |
38 | 40 | import org.apache.hadoop.conf.Configuration; |
@@ -80,13 +82,37 @@ public static void runCmd(DFSAdmin dfsadmin, boolean success, |
80 | 82 | } |
81 | 83 | } |
82 | 84 |
|
| 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 | + |
83 | 109 | /** |
84 | 110 | * Test DFSAdmin Upgrade Command. |
85 | 111 | */ |
86 | 112 | @Test |
87 | 113 | public void testDFSAdminRollingUpgradeCommands() throws Exception { |
88 | 114 | // start a cluster |
89 | | - final Configuration conf = new HdfsConfiguration(); |
| 115 | + final Configuration conf = getHdfsConfiguration(); |
90 | 116 | try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build()) { |
91 | 117 | cluster.waitActive(); |
92 | 118 |
|
@@ -168,7 +194,7 @@ public void testRollingUpgradeWithQJM() throws Exception { |
168 | 194 | LOG.info("nn1Dir=" + nn1Dir); |
169 | 195 | LOG.info("nn2Dir=" + nn2Dir); |
170 | 196 |
|
171 | | - final Configuration conf = new HdfsConfiguration(); |
| 197 | + final Configuration conf = getHdfsConfiguration(); |
172 | 198 | try (MiniJournalCluster mjc = new MiniJournalCluster.Builder(conf).build()) { |
173 | 199 | mjc.waitActive(); |
174 | 200 | setConf(conf, nn1Dir, mjc); |
@@ -306,7 +332,7 @@ private static void checkMxBean() throws Exception { |
306 | 332 | @Test |
307 | 333 | public void testRollback() throws Exception { |
308 | 334 | // start a cluster |
309 | | - final Configuration conf = new HdfsConfiguration(); |
| 335 | + final Configuration conf = getHdfsConfiguration(); |
310 | 336 | try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build()) { |
311 | 337 | cluster.waitActive(); |
312 | 338 |
|
@@ -400,7 +426,7 @@ private static void rollbackRollingUpgrade(Path foo, Path bar, |
400 | 426 | @Test |
401 | 427 | public void testDFSAdminDatanodeUpgradeControlCommands() throws Exception { |
402 | 428 | // start a cluster |
403 | | - final Configuration conf = new HdfsConfiguration(); |
| 429 | + final Configuration conf = getHdfsConfiguration(); |
404 | 430 | try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build()){ |
405 | 431 | cluster.waitActive(); |
406 | 432 | final DFSAdmin dfsadmin = new DFSAdmin(conf); |
@@ -451,7 +477,7 @@ private void testFinalize(int nnCount) throws Exception { |
451 | 477 |
|
452 | 478 | private void testFinalize(int nnCount, boolean skipImageDeltaCheck) |
453 | 479 | throws Exception { |
454 | | - final Configuration conf = new HdfsConfiguration(); |
| 480 | + final Configuration conf = getHdfsConfiguration(); |
455 | 481 | MiniQJMHACluster cluster = null; |
456 | 482 | final Path foo = new Path("/foo"); |
457 | 483 | final Path bar = new Path("/bar"); |
@@ -517,7 +543,7 @@ public void testQueryWithMultipleNN() throws Exception { |
517 | 543 | } |
518 | 544 |
|
519 | 545 | private void testQuery(int nnCount) throws Exception{ |
520 | | - final Configuration conf = new Configuration(); |
| 546 | + final Configuration conf = getHdfsConfiguration(); |
521 | 547 | try (MiniQJMHACluster cluster = new MiniQJMHACluster.Builder(conf).setNumNameNodes(nnCount).build()) { |
522 | 548 | MiniDFSCluster dfsCluster = cluster.getDfsCluster(); |
523 | 549 | dfsCluster.waitActive(); |
@@ -553,7 +579,7 @@ private void testQuery(int nnCount) throws Exception{ |
553 | 579 |
|
554 | 580 | @Test (timeout = 300000) |
555 | 581 | public void testQueryAfterRestart() throws IOException, InterruptedException { |
556 | | - final Configuration conf = new Configuration(); |
| 582 | + final Configuration conf = getHdfsConfiguration(); |
557 | 583 | try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(0).build()) { |
558 | 584 | cluster.waitActive(); |
559 | 585 | DistributedFileSystem dfs = cluster.getFileSystem(); |
@@ -583,7 +609,7 @@ public void testCheckpointWithMultipleNN() throws IOException, InterruptedExcept |
583 | 609 |
|
584 | 610 | @Test(timeout = 60000) |
585 | 611 | public void testRollBackImage() throws Exception { |
586 | | - final Configuration conf = new Configuration(); |
| 612 | + final Configuration conf = getHdfsConfiguration(); |
587 | 613 | conf.setInt(DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_TXNS_KEY, 10); |
588 | 614 | conf.setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1); |
589 | 615 | conf.setInt(DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_CHECK_PERIOD_KEY, 2); |
@@ -628,7 +654,7 @@ public void duringUploadInProgess() |
628 | 654 | } |
629 | 655 |
|
630 | 656 | public void testCheckpoint(int nnCount) throws IOException, InterruptedException { |
631 | | - final Configuration conf = new Configuration(); |
| 657 | + final Configuration conf = getHdfsConfiguration(); |
632 | 658 | conf.setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1); |
633 | 659 | conf.setInt(DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_PERIOD_KEY, 1); |
634 | 660 |
|
@@ -705,7 +731,7 @@ public void testCheckpointWithSNN() throws Exception { |
705 | 731 | SecondaryNameNode snn = null; |
706 | 732 |
|
707 | 733 | try { |
708 | | - Configuration conf = new HdfsConfiguration(); |
| 734 | + Configuration conf = getHdfsConfiguration(); |
709 | 735 | cluster = new MiniDFSCluster.Builder(conf).build(); |
710 | 736 | cluster.waitActive(); |
711 | 737 |
|
|
0 commit comments