Samrat002 commented on code in PR #28268: URL: https://github.com/apache/flink/pull/28268#discussion_r3356310120
########## flink-filesystems/flink-s3-fs-native/src/test/java/org/apache/flink/fs/s3native/writer/InMemoryNativeS3Operations.java: ########## @@ -0,0 +1,165 @@ +/* + * 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 java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * In-memory implementation for {@link NativeS3ObjectOperations}. + * + * <p>Backs every reachable S3 operation with hash maps so writer/committer logic can be exercised + * without an S3 endpoint (no MinIO/Testcontainers required). The parent's {@code S3Client} / {@code + * S3TransferManager} constructor arguments are passed as {@code null} because no overridden method + * dereferences them. + * + * <p><b>State exposure:</b> the storage maps are exposed as public final fields so tests can + * inspect them, corrupt them, or simulate object loss directly: + * + * <ul> + * <li>{@link #storedObjects} — keys written via {@link #putObject(String, File)} (e.g. the + * incomplete-tail side objects persisted by {@link NativeS3RecoverableFsDataOutputStream}). + * <li>{@link #committedObjects} — keys finalized via {@link #commitMultiPartUpload}. + * <li>{@link #openMultipartUploads} — uploadId → partNumber → bytes for in-flight MPUs; entries + * are removed on commit or abort. + * </ul> + * + * <p>{@link #getObject} reads from <em>both</em> {@link #storedObjects} and {@link + * #committedObjects} so tests can fetch a committed object the same way real S3 would serve it. + * + * <p><b>Thread safety:</b> not thread-safe. Use a single thread per instance, matching the + * single-thread invariant of the production {@link NativeS3RecoverableFsDataOutputStream}. + */ +public final class InMemoryNativeS3Operations extends NativeS3ObjectOperations { Review Comment: Agreed. An interface would make the test seam cleaner and keep SDK types off the test classpath. The reason I didn't do it here is scope: NativeS3ObjectOperations returns SDK types directly (CompletedPart, UploadPartResponse, PartETag-like records), so introducing an interface means either (a) extracting Flink-owned DTOs to replace those return types across NativeS3RecoverableFsDataOutputStream / NativeS3Committer / NativeS3RecoverableWriter, or (b) leaving the SDK types in the interface signatures , which doesn't actually remove the dependency. Both options are meaningful refactors that I'd rather not bundle into a data-loss bugfix. For now the test subclass passes null for the SDK ctor args and overrides every method it touches, so no SDK client is constructed at test time (the SDK is only on the compile classpath, which it already is for main code). I'll file a follow-up to do the interface extraction properly — happy to take it on right after this lands. WDYT? Checked https://github.com/localstack/localstack. It is not maintained anymore. -- 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]
