rdblue commented on a change in pull request #2621: URL: https://github.com/apache/iceberg/pull/2621#discussion_r637607406
########## File path: core/src/test/java/org/apache/iceberg/actions/TestBaseRewriteDataFilesAction.java ########## @@ -0,0 +1,185 @@ +/* + * 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.iceberg.actions; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.stream.Collectors; +import org.apache.iceberg.AssertHelpers; +import org.apache.iceberg.CombinedScanTask; +import org.apache.iceberg.DataFile; +import org.apache.iceberg.DataFiles; +import org.apache.iceberg.FileFormat; +import org.apache.iceberg.FileScanTask; +import org.apache.iceberg.Files; +import org.apache.iceberg.Table; +import org.apache.iceberg.TableTestBase; +import org.apache.iceberg.exceptions.CommitStateUnknownException; +import org.apache.iceberg.io.FileIO; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.mockito.internal.util.collections.Sets; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.spy; + +@RunWith(Parameterized.class) +public class TestBaseRewriteDataFilesAction extends TableTestBase { + @Parameterized.Parameters(name = "formatVersion = {0}") + public static Object[] parameters() { + return new Object[] {1, 2}; + } + + public TestBaseRewriteDataFilesAction(int formatVersion) { + super(formatVersion); + } + + @Test + public void testReplaceCommitSuccess() throws IOException { + TestRewriteDataFileAction testRewriteDataFileAction = new TestRewriteDataFileAction(table); + DataFile dataFile = DataFiles.builder(table.spec()) + .withFormat(FileFormat.PARQUET) + .withPath(Files.localOutput(temp.newFile()).location()) + .withRecordCount(10) + .withFileSizeInBytes(10) + .build(); + + DataFile rewrite = DataFiles.builder(table.spec()) + .withFormat(FileFormat.PARQUET) + .withPath(Files.localOutput(temp.newFile()).location()) + .withRecordCount(10) + .withFileSizeInBytes(10) + .build(); + + table.newFastAppend() + .appendFile(dataFile) + .commit(); + + table.newFastAppend() + .appendFile(rewrite) + .commit(); + + testRewriteDataFileAction.replaceDataFiles(Sets.newSet(dataFile), Sets.newSet(rewrite)); + + Assert.assertTrue(new File(dataFile.path().toString()).exists()); + Assert.assertTrue(new File(rewrite.path().toString()).exists()); + } + + @Test + public void testReplaceCommitStateUnknown() throws IOException { + TestRewriteDataFileAction testRewriteDataFileAction = new TestRewriteDataFileAction(table); + DataFile dataFile = DataFiles.builder(table.spec()) + .withFormat(FileFormat.PARQUET) + .withPath(Files.localOutput(temp.newFile()).location()) + .withFileSizeInBytes(10) + .withRecordCount(10) + .build(); + + DataFile rewrite = DataFiles.builder(table.spec()) + .withFormat(FileFormat.PARQUET) + .withPath(Files.localOutput(temp.newFile()).location()) + .withFileSizeInBytes(10) + .withRecordCount(10) + .build(); + + table.newFastAppend() + .appendFile(dataFile) + .commit(); + table.newFastAppend() + .appendFile(rewrite) + .commit(); + + BaseRewriteDataFilesAction spyRewriteDataFileAction = spy(testRewriteDataFileAction); + doThrow(new CommitStateUnknownException(new Exception("Commit-state is unknown."))) + .when(spyRewriteDataFileAction) + .commit(any()); Review comment: I don't think that this actually tests the case that you're trying to. This throws an exception instead of calling `replaceDataFiles`. In order to test the catch clause you added, you'd need the table's rewrite action to throw the `CommitStateUnknownException`. You could do that with table spy that returns a special rewrite that throws the exception from `commit` after calling `super.commit()` successfully. -- 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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
