yihua commented on code in PR #13746: URL: https://github.com/apache/hudi/pull/13746#discussion_r2299636064
########## hudi-client/hudi-client-common/src/test/java/org/apache/hudi/io/storage/TestFileWriter.java: ########## @@ -0,0 +1,77 @@ +/* + * 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.hudi.io.storage; + +import org.apache.avro.Schema; +import org.apache.hudi.common.model.HoodieKey; +import org.apache.hudi.common.model.HoodieRecord; +import org.apache.hudi.storage.HoodieStorage; +import org.apache.hudi.storage.StoragePath; + +import java.io.IOException; +import java.util.Properties; + +public class TestFileWriter implements HoodieFileWriter { + private boolean closed = false; + private boolean failOnWrite = false; + + public TestFileWriter(StoragePath filePath, HoodieStorage storage, boolean failOnInitialization) throws IOException { + this(filePath, storage, failOnInitialization, false); + } + + public TestFileWriter(StoragePath filePath, HoodieStorage storage, boolean failOnInitialization, boolean failOnWrite) throws IOException { + this.failOnWrite = failOnWrite; + + if (failOnInitialization) { + throw new IOException("Simulated file writer initialization failure"); + } + + storage.create(filePath, false); Review Comment: Let's move file creation before L41 that throws exception, so if init fails, the marker file should still exist even with the empty file created here (the test fails before if the ordering of marker creation and file writer initialization is flipped)? ########## hudi-client/hudi-client-common/src/test/java/org/apache/hudi/io/TestHoodieCreateHandle.java: ########## @@ -312,31 +314,82 @@ public FailingFileWriterCreateHandle(HoodieWriteConfig config, String instantTim @Override protected HoodieFileWriter initializeFileWriter() throws IOException { - throw new IOException("Simulated file writer initialization failure"); - } - - @Override - protected void createMarkerFile(String partitionPath, String dataFileName) { - // Track if marker file creation was attempted - throw new AssertionError("Marker file should not be created when file writer fails"); + return new TestFileWriter(path, hoodieTable.getStorage(), true); } } // Verify that HoodieInsertException is thrown when file writer initialization fails HoodieInsertException exception = assertThrows(HoodieInsertException.class, () -> - new FailingFileWriterCreateHandle(writeConfig, TEST_INSTANT_TIME, hoodieTable, + new CreateHandleWithFileWriterInitFailure(writeConfig, TEST_INSTANT_TIME, hoodieTable, TEST_PARTITION_PATH, TEST_FILE_ID, taskContextSupplier)); assertEquals("Failed to initialize HoodieStorageWriter for path " + String.format("%s/%s/%s", basePath, TEST_PARTITION_PATH, getExpectedBaseFileName()), exception.getMessage()); - FileSystem fs = (FileSystem) metaClient.getStorage().getFileSystem(); + HoodieStorage hoodieStorage = metaClient.getStorage(); // Verify no partition meta path - validatePartitionMetaPathExistence(fs, false); + validatePartitionMetaPathExistence(hoodieStorage, true); // Verify that no marker file exists in the file system String expectedBaseFileName = getExpectedBaseFileName(); - validateMarkerFileExistence(fs, expectedBaseFileName, false); + validateMarkerFileExistence(hoodieStorage, expectedBaseFileName, true); Review Comment: Should comment on L333 be updated? -- 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]
