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..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 @@ -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,32 @@ 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)) { + 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"; + }); + } + }); + } + }