9191public class TestDirectoryScanner {
9292 private static final Logger LOG =
9393 LoggerFactory .getLogger (TestDirectoryScanner .class );
94- private static final Configuration CONF = new HdfsConfiguration ();
9594 private static final int DEFAULT_GEN_STAMP = 9999 ;
9695
9796 private MiniDFSCluster cluster ;
@@ -103,12 +102,14 @@ public class TestDirectoryScanner {
103102 private final Random r = new Random ();
104103 private static final int BLOCK_LENGTH = 100 ;
105104
106- static {
107- CONF .setLong (DFSConfigKeys .DFS_BLOCK_SIZE_KEY , BLOCK_LENGTH );
108- CONF .setInt (DFSConfigKeys .DFS_BYTES_PER_CHECKSUM_KEY , 1 );
109- CONF .setLong (DFSConfigKeys .DFS_HEARTBEAT_INTERVAL_KEY , 1L );
110- CONF .setLong (DFSConfigKeys .DFS_DATANODE_MAX_LOCKED_MEMORY_KEY ,
105+ public Configuration getConfiguration () {
106+ Configuration configuration = new HdfsConfiguration ();
107+ configuration .setLong (DFSConfigKeys .DFS_BLOCK_SIZE_KEY , BLOCK_LENGTH );
108+ configuration .setInt (DFSConfigKeys .DFS_BYTES_PER_CHECKSUM_KEY , 1 );
109+ configuration .setLong (DFSConfigKeys .DFS_HEARTBEAT_INTERVAL_KEY , 1L );
110+ configuration .setLong (DFSConfigKeys .DFS_DATANODE_MAX_LOCKED_MEMORY_KEY ,
111111 getMemlockLimit (Long .MAX_VALUE ));
112+ return configuration ;
112113 }
113114
114115 @ Before
@@ -361,7 +362,8 @@ private void verifyStats(long totalBlocks, int diffsize, long missingMetaFile,
361362
362363 @ Test (timeout = 300000 )
363364 public void testRetainBlockOnPersistentStorage () throws Exception {
364- cluster = new MiniDFSCluster .Builder (CONF )
365+ Configuration conf = getConfiguration ();
366+ cluster = new MiniDFSCluster .Builder (conf )
365367 .storageTypes (
366368 new StorageType [] { StorageType .RAM_DISK , StorageType .DEFAULT })
367369 .numDataNodes (1 ).build ();
@@ -370,7 +372,7 @@ public void testRetainBlockOnPersistentStorage() throws Exception {
370372 bpid = cluster .getNamesystem ().getBlockPoolId ();
371373 fds = DataNodeTestUtils .getFSDataset (cluster .getDataNodes ().get (0 ));
372374 client = cluster .getFileSystem ().getClient ();
373- scanner = new DirectoryScanner (fds , CONF );
375+ scanner = new DirectoryScanner (fds , conf );
374376 scanner .setRetainDiffs (true );
375377 FsDatasetTestUtil .stopLazyWriter (cluster .getDataNodes ().get (0 ));
376378
@@ -413,8 +415,9 @@ public void testScanDirectoryStructureWarn() throws Exception {
413415 new WriterAppender (new SimpleLayout (), loggerStream );
414416 rootLogger .addAppender (writerAppender );
415417
418+ Configuration conf = getConfiguration ();
416419 cluster = new MiniDFSCluster
417- .Builder (CONF )
420+ .Builder (conf )
418421 .storageTypes (new StorageType [] {
419422 StorageType .RAM_DISK , StorageType .DEFAULT })
420423 .numDataNodes (1 )
@@ -424,7 +427,7 @@ public void testScanDirectoryStructureWarn() throws Exception {
424427 bpid = cluster .getNamesystem ().getBlockPoolId ();
425428 fds = DataNodeTestUtils .getFSDataset (cluster .getDataNodes ().get (0 ));
426429 client = cluster .getFileSystem ().getClient ();
427- scanner = new DirectoryScanner (fds , CONF );
430+ scanner = new DirectoryScanner (fds , conf );
428431 scanner .setRetainDiffs (true );
429432 FsDatasetTestUtil .stopLazyWriter (cluster .getDataNodes ().get (0 ));
430433
@@ -464,7 +467,8 @@ public void testScanDirectoryStructureWarn() throws Exception {
464467
465468 @ Test (timeout = 300000 )
466469 public void testDeleteBlockOnTransientStorage () throws Exception {
467- cluster = new MiniDFSCluster .Builder (CONF )
470+ Configuration conf = getConfiguration ();
471+ cluster = new MiniDFSCluster .Builder (conf )
468472 .storageTypes (
469473 new StorageType [] { StorageType .RAM_DISK , StorageType .DEFAULT })
470474 .numDataNodes (1 ).build ();
@@ -473,7 +477,7 @@ public void testDeleteBlockOnTransientStorage() throws Exception {
473477 bpid = cluster .getNamesystem ().getBlockPoolId ();
474478 fds = DataNodeTestUtils .getFSDataset (cluster .getDataNodes ().get (0 ));
475479 client = cluster .getFileSystem ().getClient ();
476- scanner = new DirectoryScanner (fds , CONF );
480+ scanner = new DirectoryScanner (fds , conf );
477481 scanner .setRetainDiffs (true );
478482 FsDatasetTestUtil .stopLazyWriter (cluster .getDataNodes ().get (0 ));
479483
@@ -512,16 +516,17 @@ public void testDirectoryScanner() throws Exception {
512516 }
513517
514518 public void runTest (int parallelism ) throws Exception {
515- cluster = new MiniDFSCluster .Builder (CONF ).build ();
519+ Configuration conf = getConfiguration ();
520+ cluster = new MiniDFSCluster .Builder (conf ).build ();
516521 try {
517522 cluster .waitActive ();
518523 bpid = cluster .getNamesystem ().getBlockPoolId ();
519524 fds = DataNodeTestUtils .getFSDataset (cluster .getDataNodes ().get (0 ));
520525 client = cluster .getFileSystem ().getClient ();
521- CONF .setInt (DFSConfigKeys .DFS_DATANODE_DIRECTORYSCAN_THREADS_KEY ,
526+ conf .setInt (DFSConfigKeys .DFS_DATANODE_DIRECTORYSCAN_THREADS_KEY ,
522527 parallelism );
523528
524- scanner = new DirectoryScanner (fds , CONF );
529+ scanner = new DirectoryScanner (fds , conf );
525530 scanner .setRetainDiffs (true );
526531
527532 // Add files with 100 blocks
@@ -672,9 +677,9 @@ public void runTest(int parallelism) throws Exception {
672677 *
673678 * @throws Exception thrown on unexpected failure
674679 */
675- @ Test ( timeout = 600000 )
680+ @ Test
676681 public void testThrottling () throws Exception {
677- Configuration conf = new Configuration (CONF );
682+ Configuration conf = new Configuration (getConfiguration () );
678683
679684 // We need lots of blocks so the report compiler threads have enough to
680685 // keep them busy while we watch them.
@@ -714,7 +719,7 @@ public void testThrottling() throws Exception {
714719 // Waiting should be about 9x running.
715720 LOG .info ("RATIO: " + ratio );
716721 assertTrue ("Throttle is too restrictive" , ratio <= 10f );
717- assertTrue ("Throttle is too permissive" , ratio >= 7f );
722+ assertTrue ("Throttle is too permissive" + ratio , ratio >= 7f );
718723
719724 // Test with a different limit
720725 conf .setInt (
@@ -754,7 +759,7 @@ public void testThrottling() throws Exception {
754759 assertTrue ("Throttle is too permissive" , ratio >= 7f );
755760
756761 // Test with no limit
757- scanner = new DirectoryScanner (fds , CONF );
762+ scanner = new DirectoryScanner (fds , getConfiguration () );
758763 scanner .setRetainDiffs (true );
759764 scan (blocks , 0 , 0 , 0 , 0 , 0 );
760765 scanner .shutdown ();
@@ -1095,13 +1100,14 @@ public void TestScanInfo() throws Exception {
10951100 */
10961101 @ Test (timeout = 60000 )
10971102 public void testExceptionHandlingWhileDirectoryScan () throws Exception {
1098- cluster = new MiniDFSCluster .Builder (CONF ).build ();
1103+ Configuration conf = getConfiguration ();
1104+ cluster = new MiniDFSCluster .Builder (conf ).build ();
10991105 try {
11001106 cluster .waitActive ();
11011107 bpid = cluster .getNamesystem ().getBlockPoolId ();
11021108 fds = DataNodeTestUtils .getFSDataset (cluster .getDataNodes ().get (0 ));
11031109 client = cluster .getFileSystem ().getClient ();
1104- CONF .setInt (DFSConfigKeys .DFS_DATANODE_DIRECTORYSCAN_THREADS_KEY , 1 );
1110+ conf .setInt (DFSConfigKeys .DFS_DATANODE_DIRECTORYSCAN_THREADS_KEY , 1 );
11051111
11061112 // Add files with 2 blocks
11071113 createFile (GenericTestUtils .getMethodName (), BLOCK_LENGTH * 2 , false );
@@ -1121,7 +1127,7 @@ public void testExceptionHandlingWhileDirectoryScan() throws Exception {
11211127 FsDatasetSpi <? extends FsVolumeSpi > spyFds = Mockito .spy (fds );
11221128 Mockito .doReturn (volReferences ).when (spyFds ).getFsVolumeReferences ();
11231129
1124- scanner = new DirectoryScanner (spyFds , CONF );
1130+ scanner = new DirectoryScanner (spyFds , conf );
11251131 scanner .setRetainDiffs (true );
11261132 scanner .reconcile ();
11271133 } finally {
@@ -1135,7 +1141,7 @@ public void testExceptionHandlingWhileDirectoryScan() throws Exception {
11351141
11361142 @ Test
11371143 public void testDirectoryScannerInFederatedCluster () throws Exception {
1138- HdfsConfiguration conf = new HdfsConfiguration (CONF );
1144+ HdfsConfiguration conf = new HdfsConfiguration (getConfiguration () );
11391145 // Create Federated cluster with two nameservices and one DN
11401146 try (MiniDFSCluster cluster = new MiniDFSCluster .Builder (conf )
11411147 .nnTopology (MiniDFSNNTopology .simpleHAFederatedTopology (2 ))
0 commit comments