Class AsyncKafkaConsumerTest
java.lang.Object
org.apache.kafka.clients.consumer.internals.AsyncKafkaConsumerTest
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidresetAll()voidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidWhen an inflight poll completes with records already in the fetch buffer, the next poll must return those records without submitting a new poll event: a fresh event would re-run the validate-positions stage and starve the buffered records.voidvoidvoidvoidvoidvoidtestCloseLeavesGroup(long timeoutMs) voidtestCloseLeavesGroupDespiteInterrupt(long timeoutMs) voidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidWhen a singleAsyncKafkaConsumer.poll(Duration)call runs multiple internal iterations (because fetches keep coming back empty), the consumer must keep a fetch request pending on the broker: if the poll event from one iteration completes without returning any records, the next iteration must submit a freshAsyncPollEvent(which drives a new fetch) rather than idling.voidvoidvoidvoidtestListenerCallbacksInvoke(List<org.apache.kafka.clients.consumer.internals.ConsumerRebalanceListenerMethodName> methodNames, Optional<RuntimeException> revokedError, Optional<RuntimeException> assignedError, Optional<RuntimeException> lostError, int expectedRevokedCount, int expectedAssignedCount, int expectedLostCount, Optional<RuntimeException> expectedException) Tests that the consumer correctly invokes the callbacks forConsumerRebalanceListenerthat was specified.voidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidTests that when the app thread fails to update the assignment as part of a reconciliation, it sends an event with error to the background thread before throwing on poll.voidThis behaviour is common to the Classic (cooperative) and Consumer protocols: paused partitions remain paused after a rebalance as long as they remain assigned to the same consumer.voidVerifies that at most oneAsyncPollEventis in-flight at a time.voidvoidWhen the inflight poll (its fetch) completes with an error,AsyncKafkaConsumer.poll(Duration)surfaces the error and clears the event, so a subsequent poll submits a fresh event and resumes keeping a fetch request pending on the broker.voidTests that callingThread.interrupt()beforeKafkaConsumer.poll(Duration)causesInterruptExceptionto be thrown.voidTest that poll() does not return records until the reconciliation check is complete.voidVerifies that with manual partition assignment, poll() blocks for the full user-supplied timeout instead of spinning in a busy loop.voidTestsprocessBackgroundEventshandles the case where theFuturedoes not complete within the timeout.voidTestsprocessBackgroundEventshandles the case where theFuturetakes a bit of time to complete, but does within the timeout.voidTestsprocessBackgroundEventshandles the case where theFutureis already complete when invoked, so it doesn't have to wait.voidvoidvoidvoidvoidvoidvoidTests that when the app thread fails to update the assignment as part of a reconciliation, it sends an event with error to the background thread before throwing on poll.voidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidvoidVerify that unsubscribe() does not commit offsets even when auto-commit is enabled.voidvoidvoidtestUnsubscribeWithPendingAssignmentEvent(org.apache.kafka.clients.consumer.internals.events.CompletableBackgroundEvent<?> assignedEvent) Test to ensure that assignment updates are not applied while unsubscribing (it would cause an IllegalArgumentException when calling unsubscribe()).voidvoidvoidvoidvoidvoid
-
Constructor Details
-
AsyncKafkaConsumerTest
public AsyncKafkaConsumerTest()
-
-
Method Details
-
resetAll
@AfterEach public void resetAll() -
testSuccessfulStartupShutdown
@Test public void testSuccessfulStartupShutdown() -
testFailOnClosedConsumer
@Test public void testFailOnClosedConsumer() -
testCommitAsyncWithNullCallback
@Test public void testCommitAsyncWithNullCallback() -
testCommitAsyncUserSuppliedCallbackNoException
@Test public void testCommitAsyncUserSuppliedCallbackNoException() -
testCommitAsyncUserSuppliedCallbackWithException
@ParameterizedTest @MethodSource("commitExceptionSupplier") public void testCommitAsyncUserSuppliedCallbackWithException(Exception exception) -
testCommitAsyncShouldCopyOffsets
@Test public void testCommitAsyncShouldCopyOffsets() -
testCommitted
@Test public void testCommitted() -
testCommittedExceptionThrown
@Test public void testCommittedExceptionThrown() -
testWakeupBeforeCallingPoll
@Test public void testWakeupBeforeCallingPoll() -
testWakeupAfterEmptyFetch
@Test public void testWakeupAfterEmptyFetch() -
testWakeupAfterNonEmptyFetch
@Test public void testWakeupAfterNonEmptyFetch() -
testWakeupWhileWaitingOnReconciliationCheck
@Test public void testWakeupWhileWaitingOnReconciliationCheck() -
testInflightPollResubmittedAfterCompletionWithEmptyBuffer
@Test public void testInflightPollResubmittedAfterCompletionWithEmptyBuffer()When a singleAsyncKafkaConsumer.poll(Duration)call runs multiple internal iterations (because fetches keep coming back empty), the consumer must keep a fetch request pending on the broker: if the poll event from one iteration completes without returning any records, the next iteration must submit a freshAsyncPollEvent(which drives a new fetch) rather than idling. This test drives two such iterations over an empty fetch buffer and verifies a new poll event is submitted on each one. See KAFKA-20780. -
testPollSurfacesInflightPollErrorAndResumes
@Test public void testPollSurfacesInflightPollErrorAndResumes()When the inflight poll (its fetch) completes with an error,AsyncKafkaConsumer.poll(Duration)surfaces the error and clears the event, so a subsequent poll submits a fresh event and resumes keeping a fetch request pending on the broker. -
testBufferedRecordsReturnedWithoutResubmittingPollEvent
@Test public void testBufferedRecordsReturnedWithoutResubmittingPollEvent()When an inflight poll completes with records already in the fetch buffer, the next poll must return those records without submitting a new poll event: a fresh event would re-run the validate-positions stage and starve the buffered records. Guards the buffer-guarded clear in(KAFKA-20780).invalid reference
AsyncKafkaConsumer#checkInflightPoll(Timer, boolean) -
testCommitInRebalanceCallback
@Test public void testCommitInRebalanceCallback() -
testClearWakeupTriggerAfterPoll
@Test public void testClearWakeupTriggerAfterPoll() -
testPollWaitsForReconciliationCheckComplete
@Test public void testPollWaitsForReconciliationCheckComplete()Test that poll() does not return records until the reconciliation check is complete. This prevents a race condition where records could be returned for partitions that are being revoked (see KAFKA-20332). -
testPollDoesNotWaitForReconciliationCheckIfNoPendingReconciliation
@Test public void testPollDoesNotWaitForReconciliationCheckIfNoPendingReconciliation() -
testEnsureCallbackExecutedByApplicationThread
@Test public void testEnsureCallbackExecutedByApplicationThread() -
testEnsureCommitSyncExecutedCommitAsyncCallbacks
@Test public void testEnsureCommitSyncExecutedCommitAsyncCallbacks() -
testCommitSyncAwaitsCommitAsyncCompletionWithEmptyOffsets
@Test public void testCommitSyncAwaitsCommitAsyncCompletionWithEmptyOffsets() -
testCommitSyncAwaitsCommitAsyncCompletionWithNonEmptyOffsets
@Test public void testCommitSyncAwaitsCommitAsyncCompletionWithNonEmptyOffsets() -
testCommitSyncAwaitsCommitAsyncButDoesNotFail
@Test public void testCommitSyncAwaitsCommitAsyncButDoesNotFail() -
testCommitSyncShouldCopyOffsets
@Test public void testCommitSyncShouldCopyOffsets() -
testEnsurePollExecutedCommitAsyncCallbacks
@Test public void testEnsurePollExecutedCommitAsyncCallbacks() -
testEnsureShutdownExecutedCommitAsyncCallbacks
@Test public void testEnsureShutdownExecutedCommitAsyncCallbacks() -
testVerifyApplicationEventOnShutdown
@Test public void testVerifyApplicationEventOnShutdown() -
testCloseLeavesGroup
@ParameterizedTest @ValueSource(longs={0L,30000L}) public void testCloseLeavesGroup(long timeoutMs) -
testCloseLeavesGroupDespiteOnPartitionsLostError
@Test public void testCloseLeavesGroupDespiteOnPartitionsLostError() -
testCloseLeavesGroupDespiteInterrupt
@ParameterizedTest @ValueSource(longs={0L,30000L}) public void testCloseLeavesGroupDespiteInterrupt(long timeoutMs) -
testCloseRunsRevocationCallbackAndSendsLeaveGroupEventOnInterrupt
@Test public void testCloseRunsRevocationCallbackAndSendsLeaveGroupEventOnInterrupt() -
testCommitSyncAllConsumed
@Test public void testCommitSyncAllConsumed() -
testPauseFlagPreservedForRetainedPartitionAcrossRebalance
@Test public void testPauseFlagPreservedForRetainedPartitionAcrossRebalance()This behaviour is common to the Classic (cooperative) and Consumer protocols: paused partitions remain paused after a rebalance as long as they remain assigned to the same consumer. It is tested separately for each consumer because the rebalance-related calls differ. SeeKafkaConsumerTest.testPauseFlagPreservedForRetainedPartitionAcrossRebalance(GroupProtocol). -
testAutoCommitSyncDisabled
@Test public void testAutoCommitSyncDisabled() -
testAssign
@Test public void testAssign() -
testAssignOnNullTopicPartition
@Test public void testAssignOnNullTopicPartition() -
testAssignOnEmptyTopicPartition
@Test public void testAssignOnEmptyTopicPartition() -
testAssignOnNullTopicInPartition
@Test public void testAssignOnNullTopicInPartition() -
testAssignOnEmptyTopicInPartition
@Test public void testAssignOnEmptyTopicInPartition() -
testBeginningOffsetsFailsIfNullPartitions
@Test public void testBeginningOffsetsFailsIfNullPartitions() -
testBeginningOffsets
@Test public void testBeginningOffsets() -
testBeginningOffsetsThrowsKafkaExceptionForUnderlyingExecutionFailure
@Test public void testBeginningOffsetsThrowsKafkaExceptionForUnderlyingExecutionFailure() -
testBeginningOffsetsTimeoutOnEventProcessingTimeout
@Test public void testBeginningOffsetsTimeoutOnEventProcessingTimeout() -
testOffsetsForTimesOnNullPartitions
@Test public void testOffsetsForTimesOnNullPartitions() -
testOffsetsForTimesFailsOnNegativeTargetTimes
@Test public void testOffsetsForTimesFailsOnNegativeTargetTimes() -
testOffsetsForTimes
@Test public void testOffsetsForTimes() -
testOffsetsForTimesTimeoutException
@Test public void testOffsetsForTimesTimeoutException() -
testBeginningOffsetsTimeoutException
@Test public void testBeginningOffsetsTimeoutException() -
testEndOffsetsTimeoutException
@Test public void testEndOffsetsTimeoutException() -
testBeginningOffsetsWithZeroTimeout
@Test public void testBeginningOffsetsWithZeroTimeout() -
testOffsetsForTimesWithZeroTimeout
@Test public void testOffsetsForTimesWithZeroTimeout() -
testWakeupCommitted
@Test public void testWakeupCommitted() -
testNoWakeupInCloseCommit
@Test public void testNoWakeupInCloseCommit() -
testCloseAwaitPendingAsyncCommitIncomplete
@Test public void testCloseAwaitPendingAsyncCommitIncomplete() -
testCloseAwaitPendingAsyncCommitComplete
@Test public void testCloseAwaitPendingAsyncCommitComplete() -
testInterceptorAutoCommitOnClose
@Test public void testInterceptorAutoCommitOnClose() -
testInterceptorCommitSync
@Test public void testInterceptorCommitSync() -
testNoInterceptorCommitSyncFailed
@Test public void testNoInterceptorCommitSyncFailed() -
testInterceptorCommitAsync
@Test public void testInterceptorCommitAsync() -
testNoInterceptorCommitAsyncFailed
@Test public void testNoInterceptorCommitAsyncFailed() -
testSubscribeGeneratesEvent
@Test public void testSubscribeGeneratesEvent() -
testSubscribePatternGeneratesEvent
@Test public void testSubscribePatternGeneratesEvent() -
testUnsubscribeGeneratesUnsubscribeEvent
@Test public void testUnsubscribeGeneratesUnsubscribeEvent() -
testSubscribeToEmptyListActsAsUnsubscribe
@Test public void testSubscribeToEmptyListActsAsUnsubscribe() -
testSubscribeToNullTopicCollection
@Test public void testSubscribeToNullTopicCollection() -
testSubscriptionOnNullTopic
@Test public void testSubscriptionOnNullTopic() -
testSubscriptionOnEmptyTopic
@Test public void testSubscriptionOnEmptyTopic() -
testGroupMetadataAfterCreationWithGroupIdIsNull
@Test public void testGroupMetadataAfterCreationWithGroupIdIsNull() -
testGroupMetadataAfterCreationWithGroupIdIsNotNull
@Test public void testGroupMetadataAfterCreationWithGroupIdIsNotNull() -
testGroupMetadataAfterCreationWithGroupIdIsNotNullAndGroupInstanceIdSet
@Test public void testGroupMetadataAfterCreationWithGroupIdIsNotNullAndGroupInstanceIdSet() -
testGroupMetadataUpdate
@Test public void testGroupMetadataUpdate() -
testGroupMetadataIsResetAfterUnsubscribe
@Test public void testGroupMetadataIsResetAfterUnsubscribe() -
testEmptyStreamRebalanceData
@Test public void testEmptyStreamRebalanceData() -
testStreamRebalanceData
@Test public void testStreamRebalanceData() -
testListenerCallbacksInvoke
@ParameterizedTest @MethodSource("listenerCallbacksInvokeSource") public void testListenerCallbacksInvoke(List<org.apache.kafka.clients.consumer.internals.ConsumerRebalanceListenerMethodName> methodNames, Optional<RuntimeException> revokedError, Optional<RuntimeException> assignedError, Optional<RuntimeException> lostError, int expectedRevokedCount, int expectedAssignedCount, int expectedLostCount, Optional<RuntimeException> expectedException) Tests that the consumer correctly invokes the callbacks forConsumerRebalanceListenerthat was specified. We don't go through the full effort to emulate heartbeats and correct group management here. We're simply exercising the backgroundEventProcessordoes the correct thing whenAsyncKafkaConsumer.poll(Duration)is called. Note that we testConsumerRebalanceListenerthat throws errors in its different callbacks. Failed callback execution does not immediately errors. Instead, those errors are forwarded to the application event thread for theConsumerMembershipManagerto handle. -
testBackgroundError
@Test public void testBackgroundError() -
testMultipleBackgroundErrors
@Test public void testMultipleBackgroundErrors() -
testGroupRemoteAssignorUnusedIfGroupIdUndefined
@Test public void testGroupRemoteAssignorUnusedIfGroupIdUndefined() -
testGroupRemoteAssignorInClassicProtocol
@Test public void testGroupRemoteAssignorInClassicProtocol() -
testGroupRemoteAssignorUsedInConsumerProtocol
@Test public void testGroupRemoteAssignorUsedInConsumerProtocol() -
testGroupIdNull
@Test public void testGroupIdNull() -
testGroupIdNotNullAndValid
@Test public void testGroupIdNotNullAndValid() -
testEnsurePollEventSentOnConsumerPoll
@Test public void testEnsurePollEventSentOnConsumerPoll() -
testLongPollWaitIsLimited
@Test public void testLongPollWaitIsLimited() -
testPollDoesNotAddNewAsyncPollEventWhenOneIsAlreadyInFlight
@Test public void testPollDoesNotAddNewAsyncPollEventWhenOneIsAlreadyInFlight()Verifies that at most oneAsyncPollEventis in-flight at a time. Whenpoll()runs multiple loop iterations (e.g. empty fetches), it must not enqueue a new event while the previous one is still in-flight. This prevents unnecessary queueing. See KAFKA-20315. -
testPollWithManualAssignmentDoesNotBusyLoop
@Test public void testPollWithManualAssignmentDoesNotBusyLoop()Verifies that with manual partition assignment, poll() blocks for the full user-supplied timeout instead of spinning in a busy loop. Before the fix, AbstractHeartbeatRequestManager.maximumTimeToWait() returned 0 while the membership state was UNSUBSCRIBED (the state used for manual assignment), causing pollForFetches() to call fetchBuffer.awaitWakeup() with a 0-timeout timer and re-enter the poll loop immediately. After KAFKA-20426, maximumTimeToWait() returns Long.MAX_VALUE in that state so the application thread can block for the full timeout. -
testProcessBackgroundEventsWithInitialDelay
-
testProcessBackgroundEventsWithoutDelay
@Test public void testProcessBackgroundEventsWithoutDelay()TestsprocessBackgroundEventshandles the case where theFutureis already complete when invoked, so it doesn't have to wait. -
testProcessBackgroundEventsTimesOut
-
testPollThrowsInterruptExceptionIfInterrupted
@Test public void testPollThrowsInterruptExceptionIfInterrupted()Tests that callingThread.interrupt()beforeKafkaConsumer.poll(Duration)causesInterruptExceptionto be thrown. -
testUnsubscribeWithoutGroupId
@Test public void testUnsubscribeWithoutGroupId() -
testUnsubscribeDoesNotCommitOffsetsEvenWithAutoCommitEnabled
@Test public void testUnsubscribeDoesNotCommitOffsetsEvenWithAutoCommitEnabled()Verify that unsubscribe() does not commit offsets even when auto-commit is enabled. This ensures users are aware that they need to explicitly call commitSync() before unsubscribing to avoid duplicate processing upon re-joining the group. -
testUnsubscribeWithPendingAssignmentEvent
@ParameterizedTest @MethodSource("assignmentEventsSource") public void testUnsubscribeWithPendingAssignmentEvent(org.apache.kafka.clients.consumer.internals.events.CompletableBackgroundEvent<?> assignedEvent) Test to ensure that assignment updates are not applied while unsubscribing (it would cause an IllegalArgumentException when calling unsubscribe()). Validates the fix for KAFKA-20428. -
testSeekToBeginning
@Test public void testSeekToBeginning() -
testSeekToBeginningWithException
@Test public void testSeekToBeginningWithException() -
testSeekToEndWithException
@Test public void testSeekToEndWithException() -
testSeekToEnd
@Test public void testSeekToEnd() -
testSubscribeToRe2JPatternValidation
@Test public void testSubscribeToRe2JPatternValidation() -
testSubscribeToRe2JPatternThrowsIfNoGroupId
@Test public void testSubscribeToRe2JPatternThrowsIfNoGroupId() -
testSubscribeToRe2JPatternGeneratesEvent
@Test public void testSubscribeToRe2JPatternGeneratesEvent() -
testSubscribePatternAgainstBrokerNotSupportingRegex
- Throws:
InterruptedException
-
testRecordBackgroundEventQueueSizeAndBackgroundEventQueueTime
@Test public void testRecordBackgroundEventQueueSizeAndBackgroundEventQueueTime() -
testFailConstructor
@Test public void testFailConstructor() -
testCloseInvokesStreamsRebalanceListenerOnTasksRevokedWhenMemberEpochPositive
@Test public void testCloseInvokesStreamsRebalanceListenerOnTasksRevokedWhenMemberEpochPositive() -
testCloseInvokesStreamsRebalanceListenerOnAllTasksLostWhenMemberEpochZeroOrNegative
@Test public void testCloseInvokesStreamsRebalanceListenerOnAllTasksLostWhenMemberEpochZeroOrNegative() -
testCloseWrapsStreamsRebalanceListenerException
@Test public void testCloseWrapsStreamsRebalanceListenerException() -
testPartitionsAssignedEventSendsErrorWhenApplyAssignmentFails
@Test public void testPartitionsAssignedEventSendsErrorWhenApplyAssignmentFails()Tests that when the app thread fails to update the assignment as part of a reconciliation, it sends an event with error to the background thread before throwing on poll. This ensures the background reconciliation is completed exceptionally. -
testStreamsTasksAssignedEventSendsErrorWhenApplyAssignmentFails
@Test public void testStreamsTasksAssignedEventSendsErrorWhenApplyAssignmentFails()Tests that when the app thread fails to update the assignment as part of a reconciliation, it sends an event with error to the background thread before throwing on poll. This ensures the background reconciliation is completed exceptionally.
-