Skip to content

MINOR: Clean up unreachable code in FetcherTest#19376

Merged
chia7712 merged 4 commits intoapache:trunkfrom
Parkerhiphop:MINOR-Clean-up-unreachable-code-in-FetcherTest
Apr 6, 2025
Merged

MINOR: Clean up unreachable code in FetcherTest#19376
chia7712 merged 4 commits intoapache:trunkfrom
Parkerhiphop:MINOR-Clean-up-unreachable-code-in-FetcherTest

Conversation

@Parkerhiphop
Copy link
Copy Markdown
Contributor

@Parkerhiphop Parkerhiphop commented Apr 4, 2025

This is from #16532's
comment
:

The forEach loop in the assertion will never execute because
nonResponseData is empty.

This happens because the above assertion emptyMap() has a size of 0,
so there are no elements to iterate over.

Reviewers: PoAn Yang payang@apache.org, Ken Huang
s7133700@gmail.com, TaiJuWu tjwu1217@gmail.com, TengYao Chi
kitingiao@gmail.com, Chia-Ping Tsai chia7712@gmail.com

@github-actions github-actions bot added triage PRs from the community consumer tests Test fixes (including flaky tests) clients small Small PRs labels Apr 4, 2025
@@ -3664,7 +3664,6 @@ public void testFetcherDontCacheAnyData() {
responseData.forEach((topicPartition, partitionData) -> assertEquals(records, partitionData.records()));
LinkedHashMap<TopicPartition, FetchResponseData.PartitionData> nonResponseData = fetchResponse.responseData(emptyMap(), version);
assertEquals(emptyMap().size(), nonResponseData.size());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please address this comment #16532 (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.

I suggest that we use assertTrue for this case.
IDEA will have a mark the post iteration is unnecessary after assert empty but it won't do the same thing for assert 0.

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.

Thanks, @chia7712 and @frankvicky, for reminding me about the missing comment.

I think the isEmpty approach helps prevent potential future mistakes, so I've adopted it.

@@ -3664,7 +3664,6 @@ public void testFetcherDontCacheAnyData() {
responseData.forEach((topicPartition, partitionData) -> assertEquals(records, partitionData.records()));
LinkedHashMap<TopicPartition, FetchResponseData.PartitionData> nonResponseData = fetchResponse.responseData(emptyMap(), version);
assertEquals(emptyMap().size(), nonResponseData.size());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Thanks for the reminder about the missing comment!

I've replied it on the previous review.

Copy link
Copy Markdown
Contributor

@frankvicky frankvicky left a comment

Choose a reason for hiding this comment

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

@Parkerhiphop : Thanks for the patch. I have a comment.

@@ -3664,7 +3664,6 @@ public void testFetcherDontCacheAnyData() {
responseData.forEach((topicPartition, partitionData) -> assertEquals(records, partitionData.records()));
LinkedHashMap<TopicPartition, FetchResponseData.PartitionData> nonResponseData = fetchResponse.responseData(emptyMap(), version);
assertEquals(emptyMap().size(), nonResponseData.size());
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.

nit: assertTrue(nonResponseData.isEmpty());

@@ -3663,8 +3663,7 @@ public void testFetcherDontCacheAnyData() {
assertEquals(topicNames.size(), responseData.size());
responseData.forEach((topicPartition, partitionData) -> assertEquals(records, partitionData.records()));
LinkedHashMap<TopicPartition, FetchResponseData.PartitionData> nonResponseData = fetchResponse.responseData(emptyMap(), version);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you also refactor this line? We can use Map.of() to replace emptyMap().

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.

Yes. I've replace the emptyMap() with Map.of()

Copy link
Copy Markdown
Collaborator

@TaiJuWu TaiJuWu left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Copy Markdown
Member

@FrankYang0529 FrankYang0529 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the patch.

@github-actions github-actions bot removed the triage PRs from the community label Apr 5, 2025
@chia7712 chia7712 merged commit 9f676dd into apache:trunk Apr 6, 2025
28 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-approved clients consumer small Small PRs tests Test fixes (including flaky tests)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants