jack2012aa opened a new pull request, #20381: URL: https://github.com/apache/kafka/pull/20381
# Description `KafkaProducerTest#testTopicExpiryInMetadata`, `KafkaProducerTest#testTopicRefreshInMetadata`, and `KafkaProducerTest#testTopicNotExistingInMetadata` used busy waiting and triggered IllegalStateException in MockClient#pool. During eliminating them, more problems including missing cluster information and idempotence comes up. # Changes ## IllegalStateException When sender calls `MockClient#poll` and metadata needs an update, the client tries to get an update from list or use the original metadata as an update. However, the original test bypasses the client and updates the metadata directly. The client doesn't have the last update information, so it throws the exception. The exception is reasonable, but we should allow developers to choose whether to update the metadata automatically. I add a flag `shouldUpdateWithCurrentMetadata` so developers can control the behavior. ## Busy waiting The tests want to catch the request of updating metadata, but the original code misses this function. A latch in `MockClient` is used to signal the state change now. ## Missing cluster To catch the updating request, tests have to use their clients to update metadata. However, the initial metadata lacks cluster information, so clients won't try updating. Adding a warmup update fixes the bug. ## Idempotence If idempotence is allowed, the sender requests for `InitProducerIdRequestData`. Since the tests do not reply to the request, and `MockTime` won't change automatically, the sender may be blocked when closing because it wants to get a result of inflight request. Here I allow `advanceTimeDuringPoll` in client, so the sender will get a TimeoutException eventually and be closed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org