Data, Spark, Flink: Migrate TestAppenderFactory and subclasses to JUnit5#9862
Data, Spark, Flink: Migrate TestAppenderFactory and subclasses to JUnit5#9862nastra merged 1 commit intoapache:mainfrom
Conversation
| } | ||
|
|
||
| @Before | ||
| public TableTestBase() { |
There was a problem hiding this comment.
because there are so many subclasses of TableTestBase, we decided to introduce TestBase, which is a JUnit5 version of TableTestBase. That way, we don't have to adjust all subclasses in one go and can therefore split up the required changes into smaller chunks.
There was a problem hiding this comment.
As per my understanding, We won't be able to get rid of TableTestBase . TestBase has it's own implementation of ParameterizedTestExtension. Many of the subclass of TableTestBase has different flavour of ParameterizedTestExtension. I will plan to use TestBase wherever it fits. I will also add a javadoc for both class which one should be used when. Meanwhile , Could you please take a highlevel look for the Temp directory or file initialization? Also I will remove all the classes on which @tomtongue was working.
There was a problem hiding this comment.
@nk1506 TestBase is what needs to be used and it uses the ParameterizedTestExtension that is compatible with JUnit5. The ParameterizedTestExtension used by TableTestBase and its subclasses only works with JUnit4. If you look for example at #9790, you'll see how parameterized JUnit4 tests need to be migrated to parameterized JUnit5 tests.
That being said, every subclass of TableTestBase that is migrated to JUnit5 needs to now extend TestBase and use org.apache.iceberg.ParameterizedTestExtension
There was a problem hiding this comment.
@nastra what will you recommend for class like TestAppenderFactory which has different set of parameters.
@Parameterized.Parameters(name = "FileFormat={0}, Partitioned={1}")
public static Object[] parameters() {
return new Object[][] {
new Object[] {"avro", false},
new Object[] {"avro", true},
new Object[] {"orc", false},
new Object[] {"orc", true},
new Object[] {"parquet", false},
new Object[] {"parquet", true}
};
}
If this class will extend TestBase instead of TableTestBase there will be a conflict on parameters definitions.
There was a problem hiding this comment.
this can be handled similar to how it's done for TestFlinkMetaDataTable
| package org.apache.iceberg; | ||
|
|
||
| import static org.apache.iceberg.types.Types.NestedField.required; | ||
| import static org.assertj.core.api.AssertionsForClassTypes.assertThat; |
|
|
||
| import static org.apache.iceberg.PartitionSpec.unpartitioned; | ||
| import static org.apache.iceberg.types.Types.NestedField.required; | ||
| import static org.assertj.core.api.AssertionsForClassTypes.assertThat; |
There was a problem hiding this comment.
| import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | |
| import static org.assertj.core.api.Assertions.assertThat; |
| import static org.apache.iceberg.PartitionSpec.unpartitioned; | ||
| import static org.apache.iceberg.types.Types.NestedField.required; | ||
| import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
| import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; |
There was a problem hiding this comment.
| import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; | |
| import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| import org.junit.jupiter.api.extension.ExtendWith; | ||
|
|
||
| @RunWith(Parameterized.class) | ||
| @ExtendWith(ParameterizedTestExtension.class) |
There was a problem hiding this comment.
this needs to use ParameterizedTestExtension from the iceberg package. Same for Parameter / Parameters
There was a problem hiding this comment.
Yes, I am using the same, It might nor be showing with the import . since it's part of same package
310ccdc to
35a0ddf
Compare
|
@nk1506 can you please split this PR up into smaller and more manageble pieces so that it's easier to review the changes? I would suggest to either focus on a subset of tests in |
|
|
||
| List<FlinkInputSplit> splits = generateSplits(); | ||
| Assert.assertEquals("Should have 10 splits", 10, splits.size()); | ||
| assertThat(10).as("Should have 10 splits").isEqualTo(splits.size()); |
There was a problem hiding this comment.
the actual/expected is the wrong way here. This should be assertThat(splits).hasSize(10).
@nastra , Most of the changes are coming here because of change in |
|
@nk1506 if changes to |
| WriteResult result = writer.complete(); | ||
| Assert.assertEquals(0, result.dataFiles().length); | ||
| Assert.assertEquals(0, result.deleteFiles().length); | ||
| assertThat(result.dataFiles().length).isEqualTo(0); |
There was a problem hiding this comment.
| assertThat(result.dataFiles().length).isEqualTo(0); | |
| assertThat(result.dataFiles()).isEmpty(); |
or assertThat(result.dataFiles()).hasSize(0);
please also update other places in this PR accordingly
|
|
||
| for (Path path : files) { | ||
| Assert.assertFalse(Files.exists(path)); | ||
| assertThat(Files.exists(path)).isFalse(); |
There was a problem hiding this comment.
| assertThat(Files.exists(path)).isFalse(); | |
| assertThat(path).doesNotExist(); |
| new Object[] {"parquet", true} | ||
| }; | ||
| } | ||
| @Parameter protected FileFormat format; |
There was a problem hiding this comment.
this should have index = 1 and partitioned should have index = 2. The formatVersion is a parameterized field in TestBase with ìndex = 0, so it needs to be part of parameters()` (similar to how it's done in https://github.com/apache/iceberg/blob/main/data/src/test/java/org/apache/iceberg/io/TestGenericSortedPosDeleteWriter.java#L65-L70)
| super(FORMAT_V2); | ||
| this.format = FileFormat.fromString(fileFormat); | ||
| this.partitioned = partitioned; | ||
| @Parameters(name = "FileFormat={0}, partitioned={1}") |
There was a problem hiding this comment.
| @Parameters(name = "FileFormat={0}, partitioned={1}") | |
| @Parameters(name = "FormatVersion={0}, FileFormat={1}, partitioned={2}") |
| this.format = FileFormat.fromString(fileFormat); | ||
| this.partitioned = partitioned; | ||
| @Parameters(name = "FileFormat={0}, partitioned={1}") | ||
| public static List<Object> parameters() { |
There was a problem hiding this comment.
| public static List<Object> parameters() { | |
| protected static List<Object> parameters() { |
| this.tableDir = Files.createTempDirectory(temp, "junit").toFile(); | ||
| assertThat(tableDir.delete()).isTrue(); // created by table create | ||
|
|
||
| this.formatVersion = FORMAT_V2; |
There was a problem hiding this comment.
formatVersion is a parameterized field and needs to be set in parameters() instead of here
| this.tableDir = Files.createTempDirectory(temp, "junit").toFile(); | ||
| assertThat(tableDir.delete()).isTrue(); // created by table create | ||
|
|
||
| this.formatVersion = FORMAT_V2; |
There was a problem hiding this comment.
same as I mentioned in the other class. This should be part of parameters()
| super(FORMAT_V2); | ||
| this.format = FileFormat.fromString(fileFormat); | ||
| @Parameters(name = "FileFormat = {0}") | ||
| public static List<Object> parameters() { |
| Assert.assertEquals( | ||
| ImmutableList.of(posRecord.copy("file_path", dataFile.path(), "pos", 0L)), | ||
| readRecordsAsList(posDeleteSchema, posDeleteFile.path())); | ||
| assertThat(FileContent.POSITION_DELETES).isEqualTo(posDeleteFile.content()); |
There was a problem hiding this comment.
actual/expected is the wrong way here
Issue #9085
In this patch I planned to replace TestBase with TableTestBase for following base classes.