Skip to content

Port CombinePerKeyExamplesTest off DoFnTester - #41728

Open
harshilv17 wants to merge 1 commit into
apache:masterfrom
harshilv17:fix/41727-combineperkey-off-dofntester
Open

harshilv17 wants to merge 1 commit into
apache:masterfrom
harshilv17:fix/41727-combineperkey-off-dofntester

Conversation

@harshilv17

Copy link
Copy Markdown
Contributor

Fixes #41727, a subtask of #18687.

Ports CombinePerKeyExamplesTest off the deprecated DoFnTester: ExtractLargeWordsFn and FormatShakespeareOutputFn now run in a TestPipeline with PAssert, the same way BigQueryTornadoesTest next to it does. The assertions now check the exact output (containsInAnyOrder) rather than hasItem for each expected element, so an extra output, such as a word shorter than MIN_WORD_LENGTH, would now fail the test.

The PTransform style guide still recommended DoFnTester for unit testing DoFns; it now points at TestPipeline and PAssert. CombineFnTester and SourceTestUtils are unchanged.

Ran CombinePerKeyExamplesTest locally with JDK 17 (both pass); spotlessCheck and checkstyleTest are clean. Adding an unexpected element to the expected output makes testExtractLargeWordsFn fail.

  • Small/focused contribution (ICLA not required).
  • Mentions the issue (Fixes #41727).
  • CHANGES.md: not needed, test and doc change only.

Run ExtractLargeWordsFn and FormatShakespeareOutputFn in a TestPipeline
and check their output with PAssert, like BigQueryTornadoesTest. The
assertions now check the exact output instead of only that it contains
each expected element.

The PTransform style guide still recommended DoFnTester for unit testing
DoFns; point it at TestPipeline and PAssert instead.

Fixes apache#41727

@github-actions github-actions Bot 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.

📋 Review Summary

This PR cleanly migrates CombinePerKeyExamplesTest off the deprecated DoFnTester onto TestPipeline and PAssert, while tightening the test assertions to verify exact output elements using containsInAnyOrder. It also updates the PTransform style guide documentation to reflect current Beam testing best practices.

🔍 General Feedback

  • The migration to TestPipeline and PAssert follows standard Apache Beam testing patterns and matches neighboring cookbook tests.
  • Replacing individual hasItem checks with PAssert.that(...).containsInAnyOrder(...) improves test coverage by ensuring filtered elements (such as short words) are not unexpectedly emitted.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @Abacn for label java.
Backup reviewer: ahmedabu98 (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

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.

Port CombinePerKeyExamplesTest off DoFnTester

1 participant