4949import org .apache .commons .lang3 .reflect .FieldUtils ;
5050import org .apache .hadoop .conf .Configuration ;
5151import org .apache .hadoop .fs .FileStatus ;
52+ import org .apache .hadoop .fs .LocalDirAllocator ;
5253import org .apache .hadoop .fs .Path ;
5354import org .apache .hadoop .fs .contract .ContractTestUtils ;
5455import org .apache .hadoop .fs .s3a .auth .STSClientFactory ;
6364import org .apache .hadoop .util .VersionInfo ;
6465import org .apache .http .HttpStatus ;
6566
67+ import static java .lang .String .format ;
6668import static java .util .Objects .requireNonNull ;
6769import static org .apache .hadoop .fs .contract .ContractTestUtils .skip ;
6870import static org .apache .hadoop .fs .s3a .Constants .*;
@@ -485,12 +487,29 @@ public void testCloseIdempotent() throws Throwable {
485487
486488 @ Test
487489 public void testDirectoryAllocatorDefval () throws Throwable {
490+ removeAllocatorContexts ();
488491 conf = new Configuration ();
489- conf .unset (Constants .BUFFER_DIR );
490- fs = S3ATestUtils .createTestFileSystem (conf );
491- File tmp = createTemporaryFileForWriting ();
492- assertTrue ("not found: " + tmp , tmp .exists ());
493- tmp .delete ();
492+ final String bucketName = getTestBucketName (conf );
493+ final String blank = " " ;
494+ conf .set (Constants .BUFFER_DIR , blank );
495+ conf .set (format ("fs.s3a.bucket.%s.buffer.dir" , bucketName ), blank );
496+ try {
497+ fs = S3ATestUtils .createTestFileSystem (conf );
498+ final Configuration fsConf = fs .getConf ();
499+ Assertions .assertThat (fsConf .get (Constants .BUFFER_DIR ))
500+ .describedAs ("Config option %s" , Constants .BUFFER_DIR )
501+ .isEqualTo (blank );
502+ File tmp = createTemporaryFileForWriting ();
503+ assertTrue ("not found: " + tmp , tmp .exists ());
504+ tmp .delete ();
505+ } finally {
506+ removeAllocatorContexts ();
507+ }
508+ }
509+
510+ private static void removeAllocatorContexts () {
511+ LocalDirAllocator .removeContext (BUFFER_DIR );
512+ LocalDirAllocator .removeContext (HADOOP_TMP_DIR );
494513 }
495514
496515 /**
@@ -504,13 +523,21 @@ private File createTemporaryFileForWriting() throws IOException {
504523
505524 @ Test
506525 public void testDirectoryAllocatorRR () throws Throwable {
526+ removeAllocatorContexts ();
507527 File dir1 = GenericTestUtils .getRandomizedTestDir ();
508528 File dir2 = GenericTestUtils .getRandomizedTestDir ();
509529 dir1 .mkdirs ();
510530 dir2 .mkdirs ();
511531 conf = new Configuration ();
512- conf .set (Constants .BUFFER_DIR , dir1 + ", " + dir2 );
532+ final String bucketName = getTestBucketName (conf );
533+ final String dirs = dir1 + ", " + dir2 ;
534+ conf .set (Constants .BUFFER_DIR , dirs );
535+ conf .set (format ("fs.s3a.bucket.%s.buffer.dir" , bucketName ), dirs );
513536 fs = S3ATestUtils .createTestFileSystem (conf );
537+ final Configuration fsConf = fs .getConf ();
538+ Assertions .assertThat (fsConf .get (Constants .BUFFER_DIR ))
539+ .describedAs ("Config option %s" , Constants .BUFFER_DIR )
540+ .isEqualTo (dirs );
514541 File tmp1 = createTemporaryFileForWriting ();
515542 tmp1 .delete ();
516543 File tmp2 = createTemporaryFileForWriting ();
@@ -552,10 +579,10 @@ public S3AFileSystem run() throws Exception{
552579 private static <T > T getField (Object target , Class <T > fieldType ,
553580 String fieldName ) throws IllegalAccessException {
554581 Object obj = FieldUtils .readField (target , fieldName , true );
555- assertNotNull (String . format (
582+ assertNotNull (format (
556583 "Could not read field named %s in object with class %s." , fieldName ,
557584 target .getClass ().getName ()), obj );
558- assertTrue (String . format (
585+ assertTrue (format (
559586 "Unexpected type found for field named %s, expected %s, actual %s." ,
560587 fieldName , fieldType .getName (), obj .getClass ().getName ()),
561588 fieldType .isAssignableFrom (obj .getClass ()));
0 commit comments