Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2031,9 +2031,12 @@ private Fetch<K, V> collectFetch() {
long timeoutMs = inflightPoll.deadlineMs() - time.milliseconds();
if (timeoutMs > 0) {
try {
wakeupTrigger.setActiveTask(inflightPoll.reconciliationCheckFuture());
ConsumerUtils.getResult(inflightPoll.reconciliationCheckFuture(), timeoutMs);
} catch (TimeoutException e) {
return Fetch.empty();
} finally {
wakeupTrigger.clearTask();
}
} else {
// No time to wait and reconciliation check not complete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,32 @@ public void testWakeupAfterNonEmptyFetch() {
assertThrows(WakeupException.class, () -> consumer.poll(Duration.ZERO));
}

@Test
public void testWakeupWhileWaitingOnReconciliationCheck() {
FetchBuffer fetchBuffer = mock(FetchBuffer.class);
SubscriptionState subscriptions = new SubscriptionState(new LogContext(), AutoOffsetResetStrategy.NONE);
consumer = newConsumer(fetchBuffer, mock(ConsumerInterceptors.class),
mock(ConsumerRebalanceListenerInvoker.class), subscriptions);

final TopicPartition tp = new TopicPartition("topic1", 0);
subscriptions.assignFromUser(singleton(tp));
subscriptions.seek(tp, 0);

// Do not complete the AsyncPollEvent and call wakeup().
// The call to poll should throw WakeupException without blocking for the full timeout.
doAnswer(invocation -> {
consumer.wakeup();
return null;
}).when(applicationEventHandler).add(ArgumentMatchers.isA(AsyncPollEvent.class));
doReturn(Fetch.empty()).when(fetchCollector).collectFetch(any(FetchBuffer.class));

long startTime = System.currentTimeMillis();
assertThrows(WakeupException.class, () -> consumer.poll(Duration.ofMillis(1500)));
long elapsed = System.currentTimeMillis() - startTime;

assertTrue(elapsed < 500, "Wakeup should interrupt promptly, took " + elapsed + "ms");
}

@Test
public void testCommitInRebalanceCallback() {
consumer = newConsumer();
Expand Down
Loading