From 7f030250b479adabd81113de321c7c777ca7cdbb Mon Sep 17 00:00:00 2001 From: Viraj Jasani Date: Thu, 18 Aug 2022 15:44:43 -0700 Subject: [PATCH] HADOOP-18403. Fix FileSystem leak in ITestS3AAWSCredentialsProvider (#4737) Contributed By: Viraj Jasani --- .../fs/s3a/ITestS3AAWSCredentialsProvider.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3AAWSCredentialsProvider.java b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3AAWSCredentialsProvider.java index 30f1f71eee..f1805b8408 100644 --- a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3AAWSCredentialsProvider.java +++ b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3AAWSCredentialsProvider.java @@ -162,12 +162,15 @@ public void testAnonymousProvider() throws Exception { conf.set(AWS_CREDENTIALS_PROVIDER, AnonymousAWSCredentialsProvider.class.getName()); Path testFile = getCSVTestPath(conf); - FileSystem fs = FileSystem.newInstance(testFile.toUri(), conf); - assertNotNull(fs); - assertTrue(fs instanceof S3AFileSystem); - FileStatus stat = fs.getFileStatus(testFile); - assertNotNull(stat); - assertEquals(testFile, stat.getPath()); + try (FileSystem fs = FileSystem.newInstance(testFile.toUri(), conf)) { + assertNotNull("S3AFileSystem instance must not be null", fs); + assertTrue("FileSystem must be the instance of S3AFileSystem", fs instanceof S3AFileSystem); + FileStatus stat = fs.getFileStatus(testFile); + assertNotNull("FileStatus with qualified path must not be null", stat); + assertEquals( + "The qualified path returned by getFileStatus should be same as the original file", + testFile, stat.getPath()); + } } }