Skip to content

Conversation

jim0987795064
Copy link
Contributor

@jim0987795064 jim0987795064 commented Aug 19, 2025

This PR ensures that describeTopics correctly propagates its timeoutMs
setting to the underlying describeCluster call. Integration tests were
added to verify that the API now fails with a TimeoutException when
brokers do not respond within the configured timeout.

Reviewers: Ken Huang [email protected], TengYao Chi
[email protected], Chia-Ping Tsai [email protected]

@github-actions github-actions bot added triage PRs from the community clients small Small PRs labels Aug 19, 2025
Copy link
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.

@jim0987795064: LGTM assuming CI pass

Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@jim0987795064 could you please add a integration test for it?

@github-actions github-actions bot removed the triage PRs from the community label Aug 20, 2025
@jim0987795064
Copy link
Contributor Author

@jim0987795064 could you please add a integration test for it?

@chia7712, Thanks for this suggestion, I've added a test which is used to make sure that describeCluster throws an exception when no broker responds.


// Not using prepareResponse is equivalent to "no brokers respond".
long start = System.currentTimeMillis();
ExecutionException exception = assertThrows(ExecutionException.class, () -> env.adminClient().describeCluster(new DescribeClusterOptions().timeoutMs(200)).clusterId().get());
Copy link
Member

Choose a reason for hiding this comment

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

the API which should be tested is describeTopics, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chia7712
Thanks for pointing this out, I've changed tested API to describeTopics.

// Duration should be greater than or equal to 200 ms but less than 30000 ms.
long duration = System.currentTimeMillis() - start;

assertTrue(exception.getCause() instanceof TimeoutException);
Copy link
Member

Choose a reason for hiding this comment

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

assertInstanceOf(TimeoutException.class, exception.getCause());

@@ -11668,4 +11668,26 @@ private static StreamsGroupDescribeResponseData makeFullStreamsGroupDescribeResp
.setAssignmentEpoch(1));
return data;
}

@Test
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add @Timeout(30) to this unit test?

DescribeTopicsResult result = env.adminClient().describeTopics(Collections.singletonList("test-topic"), new DescribeTopicsOptions().timeoutMs(200));
Map<String, KafkaFuture<TopicDescription>> topicDescriptionMap = result.topicNameValues();
KafkaFuture<TopicDescription> topicDescription = topicDescriptionMap.get("test-topic");
ExecutionException exception = assertThrows(ExecutionException.class, () -> topicDescription.get());
Copy link
Member

Choose a reason for hiding this comment

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

assertThrows(ExecutionException.class, topicDescription::get);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for these suggestions, update it.

@@ -11668,4 +11668,26 @@ private static StreamsGroupDescribeResponseData makeFullStreamsGroupDescribeResp
.setAssignmentEpoch(1));
return data;
}

@Test @Timeout(30)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't put these two annotations in the same line.


// Not using prepareResponse is equivalent to "no brokers respond".
long start = System.currentTimeMillis();
DescribeTopicsResult result = env.adminClient().describeTopics(Collections.singletonList("test-topic"), new DescribeTopicsOptions().timeoutMs(200));
Copy link
Contributor

Choose a reason for hiding this comment

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

List.of

long duration = System.currentTimeMillis() - start;

assertInstanceOf(TimeoutException.class, exception.getCause());
assertTrue(duration >= 150L && duration < 2000L);
Copy link
Contributor

Choose a reason for hiding this comment

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

Pardon me, how do you come up with 2000L?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for this comment, update it.

Copy link
Collaborator

@m1a2st m1a2st left a comment

Choose a reason for hiding this comment

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

Thanks for this patch, one comment

// Duration should be greater than or equal to 200 ms but less than 30000 ms.
long duration = System.currentTimeMillis() - start;

assertInstanceOf(TimeoutException.class, exception.getCause());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
assertInstanceOf(TimeoutException.class, exception.getCause());
assertEquals(TimeoutException.class, exception.getCause().getClass());

Copy link
Member

Choose a reason for hiding this comment

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

That's a common debate between assertInstanceOf and assertEquals. The difference is that assertInstanceOf allows subtypes, while assertEquals does not.

In this case, I prefer assertInstanceOf since we may introduce different varieties of TimeoutException in the future. Using assertInstanceOf provides more flexibility than assertEquals, and it also does not violate the documentation

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for explanation!

@chia7712 chia7712 merged commit 71fdab1 into apache:trunk Aug 26, 2025
29 checks passed
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.

4 participants