AndrewJSchofield commented on code in PR #15803: URL: https://github.com/apache/kafka/pull/15803#discussion_r1585852808
########## clients/src/test/java/org/apache/kafka/clients/consumer/internals/AsyncKafkaConsumerTest.java: ########## @@ -1789,6 +1791,33 @@ public void testProcessBackgroundEventsTimesOut() throws Exception { } } + /** + * Tests that calling {@link Thread#interrupt()} before {@link KafkaConsumer#poll(Duration)} + * causes {@link InterruptException} to be thrown. + */ + @Test + public void testPollThrowsInterruptExceptionIfInterrupted() { + consumer = newConsumer(); + final String topicName = "foo"; + final int partition = 3; + final TopicPartition tp = new TopicPartition(topicName, partition); + doReturn(Fetch.empty()).when(fetchCollector).collectFetch(any(FetchBuffer.class)); + Map<TopicPartition, OffsetAndMetadata> offsets = mkMap(mkEntry(tp, new OffsetAndMetadata(1))); + completeFetchedCommittedOffsetApplicationEventSuccessfully(offsets); + doReturn(LeaderAndEpoch.noLeaderOrEpoch()).when(metadata).currentLeader(any()); + consumer.assign(singleton(tp)); + + // interrupt the thread and call poll + try { + Thread.currentThread().interrupt(); + assertThrows(InterruptException.class, () -> consumer.poll(Duration.ZERO)); + } finally { + // clear interrupted state again since this thread may be reused by JUnit Review Comment: By calling `Thread.interrupted()`, the code is ensuring that the test does not exit with the thread still in an interrupted state. I have updated the comment accordingly. -- 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