MINOR: Replace try/fail/catch with assertThrows in producer tests - #23277
Open
hjtiun852 wants to merge 1 commit into
Open
MINOR: Replace try/fail/catch with assertThrows in producer tests#23277hjtiun852 wants to merge 1 commit into
hjtiun852 wants to merge 1 commit into
Conversation
Modernize six exception assertions in ProducerRecordTest, RecordSendTest
and MockProducerTest from the old try/call/fail/catch idiom to assertThrows.
assertThrows fails automatically when no exception is thrown, so a missing
fail() can no longer let a test pass silently, and it pins the exact
expected type. Where the original catch block asserted on the wrapped
cause, the assertThrows return value preserves that check:
ExecutionException err = assertThrows(ExecutionException.class, md2::get);
assertEquals(e, err.getCause());
Follows the same cleanup as apache#19975.
Testing: ./gradlew :clients:test for the three test classes plus checkstyle, all green.
m1a2st
reviewed
Aug 27, 2026
m1a2st
left a comment
Contributor
There was a problem hiding this comment.
Could you also take a look at the following tests?
BufferPoolTestProducerBatchTestProducerMetadataTestRecordAccumulatorTest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Modernize six exception assertions in ProducerRecordTest, RecordSendTest and MockProducerTest from the old try/call/fail/catch idiom to assertThrows.
assertThrows fails automatically when no exception is thrown, so a missing fail() can no longer let a test pass silently, and it pins the exact expected type. Where the original catch block asserted on the wrapped cause, the assertThrows return value preserves that check:
Follows the same cleanup as #19975.
Testing: ./gradlew :clients:test for the three test classes plus checkstyle, all green.
Reviewers: Ken Huang s7133700@gmail.com