49
49
import org .apache .commons .lang3 .reflect .FieldUtils ;
50
50
import org .apache .hadoop .conf .Configuration ;
51
51
import org .apache .hadoop .fs .FileStatus ;
52
+ import org .apache .hadoop .fs .LocalDirAllocator ;
52
53
import org .apache .hadoop .fs .Path ;
53
54
import org .apache .hadoop .fs .contract .ContractTestUtils ;
54
55
import org .apache .hadoop .fs .s3a .auth .STSClientFactory ;
63
64
import org .apache .hadoop .util .VersionInfo ;
64
65
import org .apache .http .HttpStatus ;
65
66
67
+ import static java .lang .String .format ;
66
68
import static java .util .Objects .requireNonNull ;
67
69
import static org .apache .hadoop .fs .contract .ContractTestUtils .skip ;
68
70
import static org .apache .hadoop .fs .s3a .Constants .*;
@@ -485,12 +487,29 @@ public void testCloseIdempotent() throws Throwable {
485
487
486
488
@ Test
487
489
public void testDirectoryAllocatorDefval () throws Throwable {
490
+ removeAllocatorContexts ();
488
491
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 );
494
513
}
495
514
496
515
/**
@@ -504,13 +523,21 @@ private File createTemporaryFileForWriting() throws IOException {
504
523
505
524
@ Test
506
525
public void testDirectoryAllocatorRR () throws Throwable {
526
+ removeAllocatorContexts ();
507
527
File dir1 = GenericTestUtils .getRandomizedTestDir ();
508
528
File dir2 = GenericTestUtils .getRandomizedTestDir ();
509
529
dir1 .mkdirs ();
510
530
dir2 .mkdirs ();
511
531
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 );
513
536
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 );
514
541
File tmp1 = createTemporaryFileForWriting ();
515
542
tmp1 .delete ();
516
543
File tmp2 = createTemporaryFileForWriting ();
@@ -552,10 +579,10 @@ public S3AFileSystem run() throws Exception{
552
579
private static <T > T getField (Object target , Class <T > fieldType ,
553
580
String fieldName ) throws IllegalAccessException {
554
581
Object obj = FieldUtils .readField (target , fieldName , true );
555
- assertNotNull (String . format (
582
+ assertNotNull (format (
556
583
"Could not read field named %s in object with class %s." , fieldName ,
557
584
target .getClass ().getName ()), obj );
558
- assertTrue (String . format (
585
+ assertTrue (format (
559
586
"Unexpected type found for field named %s, expected %s, actual %s." ,
560
587
fieldName , fieldType .getName (), obj .getClass ().getName ()),
561
588
fieldType .isAssignableFrom (obj .getClass ()));
0 commit comments