You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "Karsten Spang (Jira)" <ji...@apache.org> on 2023/01/30 12:50:00 UTC

[jira] [Commented] (KAFKA-8217) MockConsumer.poll executes pollTasks before checking wakeup flag

    [ https://issues.apache.org/jira/browse/KAFKA-8217?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17682057#comment-17682057 ] 

Karsten Spang commented on KAFKA-8217:
--------------------------------------

I think this is as it should be. I would want to call wakeup() from a poll task, so I knew when it got delivered.

> MockConsumer.poll executes pollTasks before checking wakeup flag
> ----------------------------------------------------------------
>
>                 Key: KAFKA-8217
>                 URL: https://issues.apache.org/jira/browse/KAFKA-8217
>             Project: Kafka
>          Issue Type: Bug
>          Components: unit tests
>    Affects Versions: 2.0.1
>            Reporter: Kevin
>            Priority: Minor
>
> The tasks scheduled in MockConsumer.schedulePollTask seem to be for simulating interactions between the Consumer and the brokers, but MockConsumer.poll runs scheduledPollTasks before it checks the wakeup flag. Given that the KafkaConsumer.poll method checks the wakeup flag before doing any other logic, it seems like the MockConsumer should rather check wakeup before running scheduledPollTasks.
> This makes it difficult to control exactly how many Consumer.poll invocations occur in a unit test when using the wakeup() pattern described in "Multithreaded Processing" in the KafkaConsumer docs, as gating each poll so that it returns only when instructed in the test requires submitting a scheduledPollTask that blocks until the test unblocks it. The trouble occurs when trying to shut down the consumer, as the poll() task needs to be unblocked in order to receive the WakeupException but https://issues.apache.org/jira/browse/KAFKA-8216 means that Consumer.poll() can be called many times in the race condition interval after poll has been unblocked but before the test has called Consumer.wakeup().



--
This message was sent by Atlassian Jira
(v8.20.10#820010)