From ac459d3946c1599216c8836fc1fd6fe71d0b8d12 Mon Sep 17 00:00:00 2001 From: Steve Loughran Date: Thu, 16 Jan 2020 14:19:46 +0000 Subject: [PATCH 1/2] HADOOP-16785 abfs close - part 2 Add an extra test to verify FilterOutputStream close in try-with-resources All seems good Change-Id: Iaa9c5f9602d7a4f0b8c9d8bd71f308c87e4d525a --- .../ITestAzureBlobFileSystemCreate.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemCreate.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemCreate.java index d9ac03ecf648f..1eb9b8852d454 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemCreate.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemCreate.java @@ -19,6 +19,7 @@ package org.apache.hadoop.fs.azurebfs; import java.io.FileNotFoundException; +import java.io.FilterOutputStream; import java.io.IOException; import java.util.EnumSet; @@ -155,4 +156,22 @@ public void testTryWithResources() throws Throwable { GenericTestUtils.assertExceptionContains(fnfe.getMessage(), inner); } } + + /** + * Attempts to write to the azure stream after it is closed will raise + * an IOException. + */ + @Test + public void testFilterFSWriteAfterClose() throws Throwable { + final AzureBlobFileSystem fs = getFileSystem(); + Path testPath = new Path(TEST_FOLDER_PATH, TEST_CHILD_FILE); + FSDataOutputStream out = fs.create(testPath); + intercept(FileNotFoundException.class, + () -> { + try (FilterOutputStream fos = new FilterOutputStream(out)) { + fs.delete(testPath, false); + } + }); + } + } From 53fa7ca30377c61330ccc64482e9535258df79c6 Mon Sep 17 00:00:00 2001 From: Steve Loughran Date: Thu, 16 Jan 2020 14:42:48 +0000 Subject: [PATCH 2/2] HADOOP-16785 abfs close - part 2 Add an extra test to verify FilterOutputStream close in try-with-resources All seems good Change-Id: Iaa9c5f9602d7a4f0b8c9d8bd71f308c87e4d525a --- .../fs/azurebfs/ITestAzureBlobFileSystemCreate.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemCreate.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemCreate.java index 1eb9b8852d454..94368a4f36955 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemCreate.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemCreate.java @@ -169,7 +169,17 @@ public void testFilterFSWriteAfterClose() throws Throwable { intercept(FileNotFoundException.class, () -> { try (FilterOutputStream fos = new FilterOutputStream(out)) { + fos.write('a'); + fos.flush(); + out.hsync(); fs.delete(testPath, false); + // trigger the first failure + throw intercept(FileNotFoundException.class, + () -> { + fos.write('b'); + out.hsync(); + return "hsync didn't raise an IOE"; + }); } }); }