|
@@ -19,6 +19,7 @@
|
|
|
package org.apache.hadoop.fs.azurebfs;
|
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.EnumSet;
|
|
|
|
|
|
import org.junit.Test;
|
|
@@ -27,8 +28,10 @@ import org.apache.hadoop.fs.CreateFlag;
|
|
|
import org.apache.hadoop.fs.FSDataOutputStream;
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
import org.apache.hadoop.fs.permission.FsPermission;
|
|
|
+import org.apache.hadoop.test.GenericTestUtils;
|
|
|
|
|
|
import static org.apache.hadoop.fs.contract.ContractTestUtils.assertIsFile;
|
|
|
+import static org.apache.hadoop.test.LambdaTestUtils.intercept;
|
|
|
|
|
|
/**
|
|
|
* Test create operation.
|
|
@@ -104,4 +107,52 @@ public class ITestAzureBlobFileSystemCreate extends
|
|
|
.close();
|
|
|
assertIsFile(fs, testFile);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Attempts to use to the ABFS stream after it is closed.
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testWriteAfterClose() throws Throwable {
|
|
|
+ final AzureBlobFileSystem fs = getFileSystem();
|
|
|
+ Path testPath = new Path(TEST_FOLDER_PATH, TEST_CHILD_FILE);
|
|
|
+ FSDataOutputStream out = fs.create(testPath);
|
|
|
+ out.close();
|
|
|
+ intercept(IOException.class, () -> out.write('a'));
|
|
|
+ intercept(IOException.class, () -> out.write(new byte[]{'a'}));
|
|
|
+ // hsync is not ignored on a closed stream
|
|
|
+ // out.hsync();
|
|
|
+ out.flush();
|
|
|
+ out.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Attempts to double close an ABFS output stream from within a
|
|
|
+ * FilterOutputStream.
|
|
|
+ * That class handles a double failure on close badly if the second
|
|
|
+ * exception rethrows the first.
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testTryWithResources() throws Throwable {
|
|
|
+ final AzureBlobFileSystem fs = getFileSystem();
|
|
|
+ Path testPath = new Path(TEST_FOLDER_PATH, TEST_CHILD_FILE);
|
|
|
+ try (FSDataOutputStream out = fs.create(testPath)) {
|
|
|
+ out.write('1');
|
|
|
+ out.hsync();
|
|
|
+ // this will cause the next write to failAll
|
|
|
+ fs.delete(testPath, false);
|
|
|
+ out.write('2');
|
|
|
+ out.hsync();
|
|
|
+ fail("Expected a failure");
|
|
|
+ } catch (FileNotFoundException fnfe) {
|
|
|
+ // the exception raised in close() must be in the caught exception's
|
|
|
+ // suppressed list
|
|
|
+ Throwable[] suppressed = fnfe.getSuppressed();
|
|
|
+ assertEquals("suppressed count", 1, suppressed.length);
|
|
|
+ Throwable inner = suppressed[0];
|
|
|
+ if (!(inner instanceof IOException)) {
|
|
|
+ throw inner;
|
|
|
+ }
|
|
|
+ GenericTestUtils.assertExceptionContains(fnfe.getMessage(), inner);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|