Skip to content

[FLINK-39772][tests][JUnit5 migration] Module: flink-fs-tests#28497

Open
spuru9 wants to merge 1 commit into
apache:masterfrom
spuru9:feature/junit5-fs-tests
Open

[FLINK-39772][tests][JUnit5 migration] Module: flink-fs-tests#28497
spuru9 wants to merge 1 commit into
apache:masterfrom
spuru9:feature/junit5-fs-tests

Conversation

@spuru9

@spuru9 spuru9 commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

What is the purpose of the change

Migrate the remaining JUnit 4 tests in flink-fs-tests to JUnit 5 (Jupiter). After this PR the module has zero JUnit 4 imports. Part of the umbrella JUnit 4 → 5 migration.

JIRA: FLINK-39772 (sub-task of FLINK-25325)

Brief change log

Five test classes migrated (all under org.apache.flink.hdfstests):

  • HDFSTest@Rule/@ClassRule TemporaryFolder@TempDir, @Before*/@After*@BeforeEach/@AfterEach/@BeforeAll, Assume.assumeTrueAssumptions.assumeTrue (arg order swapped).
  • DistributedCacheDfsTest — dropped extends TestLogger; @ClassRule MiniClusterWithClientResource@RegisterExtension static MiniClusterExtension; @ClassRule TemporaryFolder@TempDir.
  • ContinuousFileProcessingITCaseextends AbstractTestBaseJUnit4extends AbstractTestBase (the JUnit 5 sibling); lifecycle annotations.
  • ContinuousFileProcessingTest — lifecycle annotations, @ClassRule TemporaryFolder@TempDir (+ TempDirUtils).
  • ContinuousFileProcessingMigrationTest (parameterized) — @RunWith(Parameterized.class)@ExtendWith(ParameterizedTestExtension.class) with @Parameter field injection and @TestTemplate; @SnapshotsGenerator methods kept public (the migration framework discovers them via Class#getMethods()).
  • Assertions converted to AssertJ; org.junit.* imports removed; public dropped from test classes/methods per the Flink JUnit 5 Migration Guide.

One assertion in testReaderSnapshotRestore keeps Collection#contains(...) (rather than AssertJ's assertThat(coll).contains(...)) on purpose: FileInputSplit#equals is asymmetric with its TimestampedFileInputSplit subclass, and AssertJ reverses the equals direction. A comment documents this.

No production code is touched.

Verifying this change

This change is a test-only migration covered by the existing tests it migrates:

./mvnw -pl flink-fs-tests test \
  -Dtest='ContinuousFileProcessingTest,ContinuousFileProcessingITCase,ContinuousFileProcessingMigrationTest,DistributedCacheDfsTest,HDFSTest'

Result: 50 tests run, 0 failures, 0 errors, 0 skipped, matching the pre-migration baseline.

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API, i.e., is any changed class annotated with @Public(Evolving): (no)
  • The serializers: (no)
  • The runtime per-record code paths (performance sensitive): (no)
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (no)
  • The S3 file system connector: (no)

Documentation

  • Does this pull request introduce a new feature? (no)
  • If yes, how is the feature documented? (not applicable)

Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code

@flinkbot

flinkbot commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

@spuru9 spuru9 force-pushed the feature/junit5-fs-tests branch from 621df3c to ee5bd24 Compare June 20, 2026 11:26
@spuru9

spuru9 commented Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

Have used TempDir in most cases but in some multiple distinct temp dirs are needed here, so TempDirUtils.newFolder(tmpFolder) is simpler than injecting several @tempdir params. This is acceptable as per the Migration gdoc

@spuru9 spuru9 marked this pull request as ready for review June 20, 2026 11:32
@spuru9 spuru9 force-pushed the feature/junit5-fs-tests branch from ee5bd24 to 8ea2fa1 Compare June 20, 2026 11:37
@spuru9

spuru9 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

cc: @raminqaf @snuyanzin Can you review this PR as well on JUnit5 migration.

monitoringFunction.run(context);

Assert.assertArrayEquals(filesKept.toArray(), context.getSeenFiles().toArray());
assertThat(context.getSeenFiles().toArray()).isEqualTo(filesKept.toArray());

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 do we need conversion to array here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Have done for 1x1 replacement so had it, also the same for isTrue and some others. Will add it my learning for the PR for other submodules.

assertThat(initTestInstance.getOutput().contains(new StreamRecord<>(fsSplit1))).isTrue();
assertThat(initTestInstance.getOutput().contains(new StreamRecord<>(fsSplit2))).isTrue();
assertThat(initTestInstance.getOutput().contains(new StreamRecord<>(fsSplit3))).isTrue();
assertThat(initTestInstance.getOutput().contains(new StreamRecord<>(fsSplit4))).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.

assert has contains method, so no need for isTrue

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the queue holds TimestampedFileInputSplits but we assert against a plain FileInputSplit, and their equals is asymmetric. Collection#contains checks expected.equals(actual) (passes); AssertJ's .contains reverses it (fails).


Assert.assertArrayEquals(
initTestInstance.getOutput().toArray(), restoredTestInstance.getOutput().toArray());
assertThat(restoredTestInstance.getOutput().toArray())

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.

what is the reason to convert to array here?

cntntStr.append(line);
}
Assert.assertEquals(expectedFileContents.get(fileIdx), cntntStr.toString());
assertThat(cntntStr.toString()).isEqualTo(expectedFileContents.get(fileIdx));

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.

assertJ has hasToString()

// of the input stream.

Assert.assertEquals(NO_OF_FILES * LINES_PER_FILE + 1, tester.getOutput().size());
assertThat(tester.getOutput().size()).isEqualTo(NO_OF_FILES * LINES_PER_FILE + 1);

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 hasSize?

Comment on lines +62 to +63
import static org.assertj.core.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

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'm not sure it is a good idea to mix assertj and junit5
let's use assumptions from assertj

private static int getLineNo(String line) {
String[] tkns = line.split("\\s");
Assert.assertEquals(6, tkns.length);
assertThat(tkns.length).isEqualTo(6);

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.

hasSize

t.join();

Assert.assertArrayEquals(filesToBeRead.toArray(), context.getSeenFiles().toArray());
assertThat(context.getSeenFiles().toArray()).isEqualTo(filesToBeRead.toArray());

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 do we need to transform to array?

@spuru9

spuru9 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @snuyanzin. I implemented 1:1 mechanical conversions from the JUnit 4 assertions, so the old shape (.size()+isEqualTo, contains(...).isTrue(), .toArray()) carried over instead of the fluent forms.
Have taken a note to add optimal form of test for the other migrations.

@spuru9 spuru9 force-pushed the feature/junit5-fs-tests branch from 8ea2fa1 to 06f1d46 Compare June 22, 2026 19:14
@spuru9 spuru9 requested a review from snuyanzin June 22, 2026 19:16

@snuyanzin snuyanzin left a comment

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.

Thanks @snuyanzin. I implemented 1:1 mechanical conversions from the JUnit 4 assertions, so the old shape (.size()+isEqualTo, contains(...).isTrue(), .toArray()) carried over instead of the fluent forms.
Have taken a note to add optimal form of test for the other migrations.

thanks for working on this, however we should not just blindly convert it with all the bugs/suboptimal code
we should clean it as well since it is pretty straightforward in order to not just move under the rug

@spuru9 spuru9 force-pushed the feature/junit5-fs-tests branch from 06f1d46 to e07ada4 Compare June 22, 2026 19:37
@spuru9

spuru9 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Got it. Have made the changes, also took a look on the other parts if they could be optimised.

@spuru9 spuru9 requested a review from snuyanzin June 22, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants