Skip to content

Flink v1.16: Switch Flink v1.16 tests to Junit5 (Part 1) - #9565

Closed
ilyasahsan123 wants to merge 15 commits into
apache:mainfrom
ilyasahsan123:switch-junit5-for-flink-v1.16
Closed

ilyasahsan123 wants to merge 15 commits into
apache:mainfrom
ilyasahsan123:switch-junit5-for-flink-v1.16

Conversation

@ilyasahsan123

Copy link
Copy Markdown

Issue: #9087

@nastra

nastra commented Jan 29, 2024

Copy link
Copy Markdown
Contributor

@ilyasahsan123 we typically apply such changes on the latest version first (1.18) and then backport them in a separate PR. Could you apply these changes to Flink 1.18 first please?

@ilyasahsan123

Copy link
Copy Markdown
Author

Sure, I will do it. Thanks

@ilyasahsan123

Copy link
Copy Markdown
Author

hi @nastra , I've addressed your suggestion. Could you please take another look? Thanks

Comment thread flink/v1.18/build.gradle

project(":iceberg-flink:iceberg-flink-${flinkMajorVersion}") {

test {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already set in L127, so it's not needed here

int expectedMilliseconds = (int) ((long) expected / 1000_000);
int actualMilliseconds = (int) ((long) actual / 1000_000);
Assert.assertEquals(message, expectedMilliseconds, actualMilliseconds);
assertThat(expectedMilliseconds).as(message).isEqualTo(actualMilliseconds);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the actual/expected is the wrong way around. It should be assertThat(actualMilliseconds).isEqualTo(expectedMilliseconds)

for (int i = 0; i < numRecords; i++) {
Assert.assertTrue("Should have more records", actual.hasNext());
Assert.assertTrue("Should have more RowData", expected.hasNext());
assertThat(actual.hasNext()).as("Should have more records").isTrue();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assertThat(actual.hasNext()).as("Should have more records").isTrue();
assertThat(actual).as("Should have more records").hasNext();

same for the other places that use a similar pattern. We want to avoid using isTrue/isFalse as much as possible, because we want to get rich context from AssertJ when the assertion ever fails

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class TestStructRowData {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not also include the other files from the data package in this PR?

*/
package org.apache.iceberg.flink.sink;

import static org.junit.jupiter.api.Assertions.assertEquals;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong import. We should be using AssertJ assertions instead of the JUnit ones

@@ -18,10 +18,11 @@
*/
package org.apache.iceberg.flink.sink;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have expected to include other test files from the sink package here is well, but just picking 2 files seems quite random to me. I'd suggest to focus on one or more packages per PR (depending on how big the changes are) instead of just randomly picking files across the codebase


String expectedStr = row.isNullAt(1) ? null : row.getString(1).toString();
Assert.assertEquals(expectedStr, partitionKey.get(0, String.class));
assertThat(expectedStr).isEqualTo(partitionKey.get(0, String.class));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the ordering of actual/expected needs to be fixed here

// recordOffset points to the position after this one
Assert.assertEquals(startingRecordOffset + i + 1, recAndPos.recordOffset());
assertThat(elements[i]).isEqualTo(recAndPos.record());
assertThat(fileOffset).isEqualTo(recAndPos.fileOffset());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think actual/expected are in the wrong order here as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants