Samrat002 commented on code in PR #28867: URL: https://github.com/apache/flink/pull/28867#discussion_r3806092933
########## flink-filesystems/flink-s3-fs-native/src/test/java/org/apache/flink/fs/s3native/writer/SeaweedFsNativeS3Operations.java: ########## @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.fs.s3native.writer; + +import software.amazon.awssdk.core.sync.RequestBody; +import software.amazon.awssdk.services.s3.S3Client; +import software.amazon.awssdk.services.s3.model.NoSuchKeyException; +import software.amazon.awssdk.services.s3.model.S3Object; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * {@link NativeS3ObjectOperations} backed by a real (SeaweedFS) S3 endpoint, plus byte-level + * helpers so writer/committer tests can inspect and tamper with the objects that actually landed in + * S3. + */ +final class SeaweedFsNativeS3Operations extends NativeS3ObjectOperations { Review Comment: The benefit isn't line count, it's fidelity: a real endpoint reproduces the actual S3 behaviors these tests assert on — the 5 MiB multipart minimum on complete, real `NoSuchKeyException` semantics on `headObject`, and genuine network-level `GetObject`/`PutObject` responses — which is exactly what the missing-side-object and length-mismatch recovery tests depend on and the in-memory fake couldn't faithfully simulate. Added a sentence to the class javadoc making this explicit. Fixed in 9d7f9e0. ########## flink-filesystems/flink-s3-fs-native/src/test/java/org/apache/flink/fs/s3native/HAApplicationRunOnNativeS3FileSystemITCase.java: ########## @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.fs.s3native; + +import org.apache.flink.api.common.ApplicationState; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.core.fs.FileSystem; +import org.apache.flink.core.testutils.AllCallbackWrapper; +import org.apache.flink.core.testutils.TestContainerExtension; +import org.apache.flink.runtime.highavailability.AbstractHAApplicationRunITCase; +import org.apache.flink.runtime.highavailability.ApplicationResultStoreOptions; +import org.apache.flink.runtime.highavailability.FileSystemApplicationResultStore; +import org.apache.flink.runtime.testutils.CommonTestUtils; +import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration; +import org.apache.flink.test.junit5.MiniClusterExtension; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.extension.RegisterExtension; +import software.amazon.awssdk.services.s3.model.S3Object; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Runs {@link AbstractHAApplicationRunITCase} with HA data stored in SeaweedFS via the native S3 + * FS. + */ +class HAApplicationRunOnNativeS3FileSystemITCase extends AbstractHAApplicationRunITCase { + + private static final String CLUSTER_ID = "test-cluster"; + private static final String APPLICATION_RESULT_STORE_FOLDER = "ars"; + + @RegisterExtension + @Order(2) Review Comment: Yes, deliberate: `AbstractHAApplicationRunITCase` already registers its own extension at `@Order(1)`, so this class's SeaweedFS container extension (and the MiniClusterExtension) have to run after it. Added a comment explaining this. Fixed in 9d7f9e0. ########## flink-filesystems/flink-s3-fs-native/src/test/java/org/apache/flink/fs/s3native/HAJobRunOnNativeS3FileSystemITCase.java: ########## @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.fs.s3native; + +import org.apache.flink.configuration.Configuration; +import org.apache.flink.core.fs.FileSystem; +import org.apache.flink.core.testutils.AllCallbackWrapper; +import org.apache.flink.core.testutils.TestContainerExtension; +import org.apache.flink.runtime.clusterframework.ApplicationStatus; +import org.apache.flink.runtime.highavailability.AbstractHAJobRunITCase; +import org.apache.flink.runtime.highavailability.FileSystemJobResultStore; +import org.apache.flink.runtime.highavailability.JobResultStoreOptions; +import org.apache.flink.runtime.testutils.CommonTestUtils; +import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration; +import org.apache.flink.test.junit5.MiniClusterExtension; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.extension.RegisterExtension; +import software.amazon.awssdk.services.s3.model.S3Object; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +/** Runs {@link AbstractHAJobRunITCase} with HA data stored in SeaweedFS via the native S3 FS. */ +class HAJobRunOnNativeS3FileSystemITCase extends AbstractHAJobRunITCase { + + private static final String CLUSTER_ID = "test-cluster"; + private static final String JOB_RESULT_STORE_FOLDER = "jrs"; + + @RegisterExtension + @Order(2) Review Comment: Same reasoning as the HAApplicationRun case — `AbstractHAJobRunITCase` registers its own extension at `@Order(1)`. Added a comment here too. Fixed in 9d7f9e0. ########## flink-filesystems/flink-s3-fs-native/src/test/java/org/apache/flink/fs/s3native/NativeS3FileSystemITCase.java: ########## @@ -0,0 +1,159 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.fs.s3native; + +import org.apache.flink.configuration.Configuration; +import org.apache.flink.core.fs.FSDataInputStream; +import org.apache.flink.core.fs.FSDataOutputStream; +import org.apache.flink.core.fs.FileStatus; +import org.apache.flink.core.fs.FileSystem; +import org.apache.flink.core.fs.Path; +import org.apache.flink.core.fs.RecoverableFsDataOutputStream; +import org.apache.flink.core.fs.RecoverableWriter; +import org.apache.flink.core.testutils.AllCallbackWrapper; +import org.apache.flink.core.testutils.TestContainerExtension; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; + +/** Exercises native S3 filesystem operations directly. */ +class NativeS3FileSystemITCase { + + @RegisterExtension + private static final AllCallbackWrapper<TestContainerExtension<SeaweedFsNativeS3TestContainer>> + SEAWEEDFS_EXTENSION = + new AllCallbackWrapper<>( + new TestContainerExtension<>(SeaweedFsNativeS3TestContainer::new)); + + private static FileSystem fs; + private static String bucketUri; + + private static SeaweedFsNativeS3TestContainer container() { + return SEAWEEDFS_EXTENSION.getCustomExtension().getTestContainer(); + } + + @BeforeAll + static void setUp() throws Exception { + final Configuration config = new Configuration(); + container().setS3ConfigOptions(config); + + final NativeS3FileSystemFactory factory = new NativeS3FileSystemFactory(); + factory.configure(config); + + bucketUri = container().getS3UriForDefaultBucket(); + fs = factory.create(URI.create(bucketUri + "/")); + } + + @Test + void testWriteReadAndStat() throws Exception { + final Path file = path("dir/" + UUID.randomUUID() + ".txt"); + final byte[] data = "hello seaweedfs".getBytes(StandardCharsets.UTF_8); + write(file, data); + + assertThat(fs.exists(file)).isTrue(); + assertThat(fs.getFileStatus(file).getLen()).isEqualTo(data.length); + assertThat(read(file, data.length)).isEqualTo(data); + } + + @Test + void testListRenameDelete() throws Exception { + final String dir = "listdir-" + UUID.randomUUID(); + final Path a = path(dir + "/a.txt"); + final Path b = path(dir + "/b.txt"); + write(a, "a".getBytes(StandardCharsets.UTF_8)); + write(b, "b".getBytes(StandardCharsets.UTF_8)); + + final FileStatus[] listed = fs.listStatus(path(dir)); + assertThat(listed) + .extracting(status -> status.getPath().getName()) + .containsExactlyInAnyOrder("a.txt", "b.txt"); + + final Path renamed = path(dir + "/c.txt"); + assertThat(fs.rename(a, renamed)).isTrue(); + assertThat(fs.exists(a)).isFalse(); + assertThat(fs.exists(renamed)).isTrue(); + + assertThat(fs.delete(path(dir), true)).isTrue(); + assertThat(fs.exists(renamed)).isFalse(); + } + + @Test + void testMkdirsDoesNotThrow() { + assertThatCode(() -> fs.mkdirs(path("mkdir-" + UUID.randomUUID()))) + .doesNotThrowAnyException(); + } + + @Test + void testRecoverableWriterMultipartCommit() throws Exception { + final Path file = path("recoverable-" + UUID.randomUUID() + ".bin"); + // > s3.upload.min.part.size (5 MiB) so the commit exercises a real multipart upload. + final byte[] data = payload(6 * 1024 * 1024); Review Comment: Agreed — replaced the literal `6 * 1024 * 1024` with `NativeS3FileSystemFactory.S3_MULTIPART_MIN_PART_SIZE + (1024 * 1024)` so the intent (bigger than the configured minimum) is explicit and survives that constant changing later. Fixed in 9d7f9e0. ########## flink-filesystems/flink-s3-fs-native/src/test/java/org/apache/flink/fs/s3native/HAJobRunOnNativeS3FileSystemITCase.java: ########## @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.fs.s3native; + +import org.apache.flink.configuration.Configuration; +import org.apache.flink.core.fs.FileSystem; +import org.apache.flink.core.testutils.AllCallbackWrapper; +import org.apache.flink.core.testutils.TestContainerExtension; +import org.apache.flink.runtime.clusterframework.ApplicationStatus; +import org.apache.flink.runtime.highavailability.AbstractHAJobRunITCase; +import org.apache.flink.runtime.highavailability.FileSystemJobResultStore; +import org.apache.flink.runtime.highavailability.JobResultStoreOptions; +import org.apache.flink.runtime.testutils.CommonTestUtils; +import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration; +import org.apache.flink.test.junit5.MiniClusterExtension; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.extension.RegisterExtension; +import software.amazon.awssdk.services.s3.model.S3Object; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +/** Runs {@link AbstractHAJobRunITCase} with HA data stored in SeaweedFS via the native S3 FS. */ +class HAJobRunOnNativeS3FileSystemITCase extends AbstractHAJobRunITCase { Review Comment: Fair point, and I looked into it — but the same duplication already exists pre-PR between the sibling `flink-s3-fs-base` classes (`HAApplicationRunOnSeaweedFsS3StoreITCase` / `HAJobRunOnSeaweedFsS3StoreITCase`), which register near-identical container extensions. Rather than fix it asymmetrically for just the native-s3 pair in this PR, I'd rather leave this as-is here and file a separate follow-up to introduce a shared composition/trait across both modules. Let me know if you'd rather I do it inline in this PR instead. -- 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]
