Skip to content

Commit d491f0b

Browse files
HADOOP-19573. S3A: ITestS3AConfiguration.testDirectoryAllocatorDefval() failing (#7699)
* trim the buffer dir string before the probe (more robust code anyway) * tests to set this, and remove any instantiated context mappers Contributed by Steve Loughran
1 parent 20f4011 commit d491f0b

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/S3AStoreImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import software.amazon.awssdk.transfer.s3.model.FileUpload;
5858
import software.amazon.awssdk.transfer.s3.model.UploadFileRequest;
5959

60+
import org.apache.commons.lang3.StringUtils;
6061
import org.apache.hadoop.conf.Configuration;
6162
import org.apache.hadoop.fs.FileSystem;
6263
import org.apache.hadoop.fs.LocalDirAllocator;
@@ -287,10 +288,11 @@ public boolean inputStreamHasCapability(final String capability) {
287288
* Initialize dir allocator if not already initialized.
288289
*/
289290
private void initLocalDirAllocator() {
290-
String bufferDir = getConfig().get(BUFFER_DIR) != null
291-
? BUFFER_DIR
292-
: HADOOP_TMP_DIR;
293-
directoryAllocator = new LocalDirAllocator(bufferDir);
291+
String key = BUFFER_DIR;
292+
if (StringUtils.isEmpty(getConfig().getTrimmed(key))) {
293+
key = HADOOP_TMP_DIR;
294+
}
295+
directoryAllocator = new LocalDirAllocator(key);
294296
}
295297

296298
/** Acquire write capacity for rate limiting {@inheritDoc}. */

hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3AConfiguration.java

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.apache.commons.lang3.reflect.FieldUtils;
5050
import org.apache.hadoop.conf.Configuration;
5151
import org.apache.hadoop.fs.FileStatus;
52+
import org.apache.hadoop.fs.LocalDirAllocator;
5253
import org.apache.hadoop.fs.Path;
5354
import org.apache.hadoop.fs.contract.ContractTestUtils;
5455
import org.apache.hadoop.fs.s3a.auth.STSClientFactory;
@@ -63,6 +64,7 @@
6364
import org.apache.hadoop.util.VersionInfo;
6465
import org.apache.http.HttpStatus;
6566

67+
import static java.lang.String.format;
6668
import static java.util.Objects.requireNonNull;
6769
import static org.apache.hadoop.fs.contract.ContractTestUtils.skip;
6870
import 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

Comments
 (0)