Migrate Write sub-classes in spark-extensions to JUnit5 and AssertJ style#9670
Migrate Write sub-classes in spark-extensions to JUnit5 and AssertJ style#9670nastra merged 11 commits intoapache:mainfrom
Conversation
8b6abaf to
e069cee
Compare
| } | ||
|
|
||
| @Rule public TemporaryFolder temp = new TemporaryFolder(); | ||
| @TempDir private Path temp; |
There was a problem hiding this comment.
CatalogTestBase already has temp, so this shouldn't be required
There was a problem hiding this comment.
Thanks for the quick review. Will remove this in the next commit.
| this.planningMode = planningMode; | ||
| } | ||
| @Parameter(index = 3) | ||
| protected String fileFormat; |
There was a problem hiding this comment.
| protected String fileFormat; | |
| protected FileFormat fileFormat; |
There was a problem hiding this comment.
Agree. Let me do this.
| @TestTemplate | ||
| public void testDeleteFileThenMetadataDelete() throws Exception { | ||
| Assume.assumeFalse("Avro does not support metadata delete", fileFormat.equals("avro")); | ||
| assumeThat(fileFormat.equalsIgnoreCase("avro")) |
There was a problem hiding this comment.
once fileFormat is of type FileFormat, this check can be changed to assumeThat(fileFormat).as(..).isNotEqualTo(FileFormat.AVRO)
| List<DataFile> dataFilesAfter = TestHelpers.dataFiles(table, branch); | ||
| Assert.assertTrue( | ||
| "Data file should have been removed", dataFilesBefore.size() > dataFilesAfter.size()); | ||
| assertThat(dataFilesBefore.size() > dataFilesAfter.size()) |
There was a problem hiding this comment.
you could use .hasSizeGreaterThan() here
| @TestTemplate | ||
| public void testDeleteFromEmptyTable() { | ||
| Assume.assumeFalse("Custom branch does not exist for empty table", "test".equals(branch)); | ||
| assumeThat("test".equals(branch)).as("Custom branch does not exist for empty table").isFalse(); |
There was a problem hiding this comment.
| assumeThat("test".equals(branch)).as("Custom branch does not exist for empty table").isFalse(); | |
| assumeThat(branch).as("Custom branch does not exist for empty table").isNotEqualTo("test"); |
| @TestTemplate | ||
| public void testDeleteFromNonExistingCustomBranch() { | ||
| Assume.assumeTrue("Test only applicable to custom branch", "test".equals(branch)); | ||
| assumeThat("test".equals(branch)).as("Test only applicable to custom branch").isTrue(); |
| @TestTemplate | ||
| public void testDeleteWithMultipleRowGroupsParquet() throws NoSuchTableException { | ||
| Assume.assumeTrue(fileFormat.equalsIgnoreCase("parquet")); | ||
| assumeThat(fileFormat.equalsIgnoreCase("parquet")).isTrue(); |
There was a problem hiding this comment.
| assumeThat(fileFormat.equalsIgnoreCase("parquet")).isTrue(); | |
| assumeThat(fileFormat).isEqualTo(FileFormat.PARQUET); |
| @TestTemplate | ||
| public void testDeleteOnNonIcebergTableNotSupported() { | ||
| Assume.assumeTrue(catalogName.equalsIgnoreCase("spark_catalog")); | ||
| assumeThat(catalogName.equalsIgnoreCase("spark_catalog")).isTrue(); |
| public synchronized void testDeleteWithSerializableIsolation() throws InterruptedException { | ||
| // cannot run tests with concurrency for Hadoop tables without atomic renames | ||
| Assume.assumeFalse(catalogName.equalsIgnoreCase("testhadoop")); | ||
| assumeThat(catalogName.equalsIgnoreCase("testhadoop")).isFalse(); |
There was a problem hiding this comment.
please also update all the other places in this PR
| @TestTemplate | ||
| public void testDeleteToWapBranch() throws NoSuchTableException { | ||
| Assume.assumeTrue("WAP branch only works for table identifier without branch", branch == null); | ||
| assumeThat(branch == null) |
There was a problem hiding this comment.
| assumeThat(branch == null) | |
| assumeThat(branch).as(..).isNull(); |
| @TestTemplate | ||
| public void testDeleteToWapBranchWithTableBranchIdentifier() throws NoSuchTableException { | ||
| Assume.assumeTrue("Test must have branch name part in table identifier", branch != null); | ||
| assumeThat(branch != null).as("Test must have branch name part in table identifier").isTrue(); |
| @TestTemplate | ||
| public void testUpdateEmptyTable() { | ||
| Assume.assumeFalse("Custom branch does not exist for empty table", "test".equals(branch)); | ||
| assumeThat("test".equals(branch)).as("Custom branch does not exist for empty table").isFalse(); |
There was a problem hiding this comment.
same as previously mentioned. We want to avoid using isFalse / isTrue as much as possible, because it won't print enough context when the assertion/assumption ever fails
cd62c06 to
d3460dc
Compare
|
Working on the fix of errors. |
| for (int numOperations = 0; numOperations < 20; numOperations++) { | ||
| while (shouldAppend.get() && barrier.get() < numOperations * 2) { | ||
| sleep(10); | ||
| sleep(200); |
There was a problem hiding this comment.
is this being flaky and requires a bump in wait time? We might want to update this to use Awaitility in a follow-up PR
There was a problem hiding this comment.
thanks! yes, the test seems to be flaky. After the updates, the test sometimes failed and sometimes succeeded. I was investigating the issue, but let me update the part with Awaitlity.
|
|
||
| appendFiles.commit(); | ||
| sleep(10); | ||
| sleep(1000); |
There was a problem hiding this comment.
we might want to update this to Awaitility in a follow-up PR
|
|
||
| appendFiles.commit(); | ||
| sleep(10); | ||
| sleep(1000); |
There was a problem hiding this comment.
same as previously mentioned about using Awaitility here
nastra
left a comment
There was a problem hiding this comment.
@tomtongue the changes LGTM, I just left a few questions. Did you plan to do anything else because the title still contains WIP?
|
Thanks for the review @nastra . No, there's one thing that just I update snapshotIsolation tests by adding |
|
|
||
| appendFiles.commit(); | ||
| sleep(10); | ||
| Awaitility.await().pollInterval(Duration.ofMillis(10)).until(() -> true); |
There was a problem hiding this comment.
I don't think this makes a lot of sense to replace this sleep with Awaitility. I wonder whether this sleep here is even necessary
There was a problem hiding this comment.
Let me revert this to sleep. Currently the snapshotIsolation tests for TestDelete, TestMerge and TestUpdate are still flaky. From my current investigation, the test failure seems to be related to the appendFiles with other write operations. And the sleep seems to work for waiting for the appendFiles.commit().
There was a problem hiding this comment.
Got the reason of the test failure. The reason seems to be the conflicts of the appended file names. When I tested using a randomized name for each appendFile, all the tests succeeded (the previous version sets the randomized names). And in this case, as you said, sleep is no longer needed. Let me fix the file name configuration.
| protected DataFile writeDataFile(Table table, List<GenericRecord> records) { | ||
| try { | ||
| OutputFile file = Files.localOutput(temp.newFile()); | ||
|
|
There was a problem hiding this comment.
thanks. Will remove it.
| } | ||
| int currentNumOperations = numOperations; | ||
| Awaitility.await() | ||
| .pollInterval(Duration.ofMillis(10)) |
There was a problem hiding this comment.
I think all of these should have .atMost(5, TimeUnit.SECONDS) because we don't want to wait indefinitely for the condition to happen
There was a problem hiding this comment.
Thanks for the suggestion. I will add atMost to all of the tests. Updated.
|
@nastra Reflected on your comments. If there's any part that I should change, please let me know. |
|
Thank you! |
|
thanks for getting this done @tomtongue. Looking forward to other PRs from you for the remaining files in |
|
Of course, I'm working on migrating procedures and other tests. Will create 2 or 3 PRs later👍 |
Migrate the following "Write" sub-classes in spark-extensions to JUnit 5 and AssertJ style along with #9613, and #9086.
Current progress