eskabetxe commented on code in PR #29420:
URL: https://github.com/apache/flink/pull/29420#discussion_r4790300052


##########
flink-filesystems/flink-s3-fs-native/src/test/java/org/apache/flink/fs/s3native/NativeS3FileSystemITCase.java:
##########
@@ -103,6 +107,56 @@ void testListRenameDelete() throws Exception {
         assertThat(fs.exists(renamed)).isFalse();
     }
 
+    @ParameterizedTest
+    @ValueSource(strings = {"", "/"})
+    void testBucketRootExistsAsDirectory(String rootSuffix) throws Exception {
+        final Path root = new Path(bucketUri + rootSuffix);
+
+        assertThat(fs.exists(root)).isTrue();
+        final FileStatus status = fs.getFileStatus(root);
+        assertThat(status.isDir()).isTrue();
+        assertThat(status.getLen()).isZero();
+        assertThat(status.getPath()).isEqualTo(root);
+    }
+
+    @Test
+    void testBucketRootCannotBeOpened() throws Exception {
+        write(path("openroot/" + UUID.randomUUID() + ".txt"), 
"x".getBytes(StandardCharsets.UTF_8));
+
+        assertThatThrownBy(() -> fs.open(new Path(bucketUri)))
+                .isInstanceOf(FileNotFoundException.class)
+                .hasMessageContaining("directory");
+    }
+
+    @ParameterizedTest
+    @ValueSource(booleans = {true, false})
+    void testBucketRootCannotBeDeleted(boolean recursive) throws Exception {
+        final String dir = "deleteroot-" + UUID.randomUUID();
+        write(path(dir + "/" + UUID.randomUUID() + ".txt"), 
"x".getBytes(StandardCharsets.UTF_8));
+
+        assertThatThrownBy(() -> fs.delete(new Path(bucketUri), recursive))
+                .isInstanceOf(IOException.class)
+                .hasMessageContaining("root");
+        assertThat(fs.listStatus(path(dir))).hasSize(1);
+    }
+
+    @Test
+    void testMissingBucketRootIsReportedAsNotFound() throws Exception {
+        final Configuration config = new Configuration();
+        container().setS3ConfigOptions(config);
+
+        final NativeS3FileSystemFactory factory = new 
NativeS3FileSystemFactory();
+        factory.configure(config);
+
+        final String missingBucketUri =
+                "s3://missing-bucket-" + 
UUID.randomUUID().toString().toLowerCase(Locale.ROOT);
+        final FileSystem missingFs = 
factory.create(URI.create(missingBucketUri + "/"));

Review Comment:
   Fixed, missingFs is now closed via closeAsync().get() in a finally block.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to