Class ConsumerHeartbeatRequestManagerTest

java.lang.Object
org.apache.kafka.clients.consumer.internals.ConsumerHeartbeatRequestManagerTest

public class ConsumerHeartbeatRequestManagerTest extends Object
  • Constructor Details

    • ConsumerHeartbeatRequestManagerTest

      public ConsumerHeartbeatRequestManagerTest()
  • Method Details

    • setUp

      @BeforeEach public void setUp()
    • testHeartBeatRequestStateToStringBase

      @Test public void testHeartBeatRequestStateToStringBase()
    • testHeartbeatOnStartup

      @Test public void testHeartbeatOnStartup()
    • testFirstHeartbeatIncludesRequiredInfoToJoinGroupAndGetAssignments

      @ParameterizedTest public void testFirstHeartbeatIncludesRequiredInfoToJoinGroupAndGetAssignments(short version)
    • testSkippingHeartbeat

      @ParameterizedTest @ValueSource(booleans={true,false}) public void testSkippingHeartbeat(boolean shouldSkipHeartbeat)
    • testMaximumTimeToWaitWhenHeartbeatShouldBeSkipped

      @ParameterizedTest @ValueSource(booleans={true,false}) public void testMaximumTimeToWaitWhenHeartbeatShouldBeSkipped(boolean isUnsubscribed)
      When the consumer uses manual partition assignment (assign()) instead of subscribe(), the member stays in UNSUBSCRIBED state indefinitely. Because heartbeats are skipped in that state and heartbeatIntervalMs initialises to 0, maximumTimeToWait used to return 0, causing a busy-loop in pollForFetches. Verify that maximumTimeToWait returns Long.MAX_VALUE whenever the member is in UNSUBSCRIBED state so the application thread can block for the full poll timeout.
    • testMaximumTimeToWaitWhenCoordinatorUnavailableDoesNotSpin

      @Test public void testMaximumTimeToWaitWhenCoordinatorUnavailableDoesNotSpin()
      KAFKA-20253: when the coordinator is unavailable (e.g. after a re-authentication failure), poll() returns EMPTY, so no heartbeat can be sent. maximumTimeToWait() must return a positive value in that case; returning 0 busy-spins the application thread (and, via wakeups, the consumer network thread), which is the AsyncKafkaConsumer high-CPU loop in this ticket.
    • testMaximumTimeToWaitWhenJoiningAndCoordinatorUnknownDoesNotSpin

      @Test public void testMaximumTimeToWaitWhenJoiningAndCoordinatorUnknownDoesNotSpin()
      While bootstrap DNS resolution is still in progress the coordinator is unknown, and a member that wants to join has a zero heartbeat interval, since the interval is only learned from the first heartbeat response. maximumTimeToWait() must wait a retry backoff rather than the (zero) heartbeat interval; returning 0 busy-spins the application and network threads.
    • testMaximumTimeToWaitWhenFatalReturnsMaxValue

      @Test public void testMaximumTimeToWaitWhenFatalReturnsMaxValue()
    • testMaximumTimeToWaitWhenFencedWaitsRetryBackoff

      @Test public void testMaximumTimeToWaitWhenFencedWaitsRetryBackoff()
    • testMaximumTimeToWaitDoesNotSpinDuringRealBootstrapDnsResolution

      @Test public void testMaximumTimeToWaitDoesNotSpinDuringRealBootstrapDnsResolution() throws Exception
      Throws:
      Exception
    • testHeartbeatNotSentIfAnotherOneInFlight

      @Test public void testHeartbeatNotSentIfAnotherOneInFlight()
    • testNetworkTimeout

      @Test public void testNetworkTimeout()
    • testDisconnect

      @Test public void testDisconnect()
    • testFailureOnFatalException

      @Test public void testFailureOnFatalException()
    • testHeartbeatResponseErrorNotifiedToGroupManagerAfterErrorPropagated

      @Test public void testHeartbeatResponseErrorNotifiedToGroupManagerAfterErrorPropagated()
    • testHeartbeatRequestFailureNotifiedToGroupManagerAfterErrorPropagated

      @Test public void testHeartbeatRequestFailureNotifiedToGroupManagerAfterErrorPropagated()
    • testValidateConsumerGroupHeartbeatRequest

      @ParameterizedTest public void testValidateConsumerGroupHeartbeatRequest(short version)
    • testValidateConsumerGroupHeartbeatRequestAssignmentSentWhenLocalEpochChanges

      @ParameterizedTest public void testValidateConsumerGroupHeartbeatRequestAssignmentSentWhenLocalEpochChanges(short version)
    • testUnsupportedVersionFromBroker

      @ParameterizedTest @ValueSource(strings="The cluster does not support the new CONSUMER group protocol. Set group.protocol=classic on the consumer configs to revert to the CLASSIC protocol until the cluster is upgraded.") public void testUnsupportedVersionFromBroker(String errorMsg)
      This validates the UnsupportedApiVersion the client generates while building a HB if: 1. HB API is not supported. 2. Required HB API version is not available.
    • testUnsupportedVersionFromClient

      @ParameterizedTest @MethodSource("unsupportedVersionFromClientCases") public void testUnsupportedVersionFromClient(org.apache.kafka.common.errors.UnsupportedVersionException thrown, String errorMsg)
      This validates the UnsupportedApiVersion the client generates while building a HB if: REGEX_RESOLUTION_NOT_SUPPORTED_MSG only generated on the client side.
    • testHeartbeatState

      @Test public void testHeartbeatState()
    • testPollTimerExpiration

      @Test public void testPollTimerExpiration()
    • testPollOnLeaving

      @ParameterizedTest @MethodSource("pollOnLeavingMatrix") public void testPollOnLeaving(Optional<String> groupInstanceId, org.apache.kafka.clients.consumer.CloseOptions.GroupMembershipOperation operation)
    • testisExpiredByUsedForLogging

      @Test public void testisExpiredByUsedForLogging()
    • testFencedMemberStopHeartbeatUntilItReleasesAssignmentToRejoin

      @Test public void testFencedMemberStopHeartbeatUntilItReleasesAssignmentToRejoin()
    • testSendingLeaveGroupHeartbeatWhenPreviousOneInFlight

      @ParameterizedTest public void testSendingLeaveGroupHeartbeatWhenPreviousOneInFlight(short version)
    • testConsumerAcksReconciledAssignmentAfterAckLost

      @ParameterizedTest public void testConsumerAcksReconciledAssignmentAfterAckLost(short version)
    • testPollOnCloseGeneratesRequestIfNeeded

      @ParameterizedTest @MethodSource("pollOnLeavingMatrix") public void testPollOnCloseGeneratesRequestIfNeeded(Optional<String> groupInstanceId, org.apache.kafka.clients.consumer.CloseOptions.GroupMembershipOperation operation)
    • testRegexInHeartbeatLifecycle

      @Test public void testRegexInHeartbeatLifecycle()
    • testRegexInJoiningHeartbeat

      @Test public void testRegexInJoiningHeartbeat()
    • testRackIdInHeartbeatLifecycle

      @Test public void testRackIdInHeartbeatLifecycle()
    • testTimerNotDue

      @Test public void testTimerNotDue()
    • testHeartbeatOutsideInterval

      @Test public void testHeartbeatOutsideInterval()
    • testNoCoordinator

      @Test public void testNoCoordinator()
    • testPollTimerExpirationShouldNotMarkMemberStaleIfMemberAlreadyLeaving

      @Test public void testPollTimerExpirationShouldNotMarkMemberStaleIfMemberAlreadyLeaving()
      This is expected to be the case where a member is already leaving the group and the poll timer expires. The poll timer expiration should not transition the member to STALE, and the member should continue to send heartbeats while the ongoing leaving operation completes (send heartbeats while waiting for callbacks before leaving, or send last heartbeat to leave).
    • testSuccessfulHeartbeatTiming

      @Test public void testSuccessfulHeartbeatTiming()
    • testLogsHeartbeatIntervalReceivedFromCoordinatorOnlyWhenChanged

      @Test public void testLogsHeartbeatIntervalReceivedFromCoordinatorOnlyWhenChanged()
    • testGroupIdNotFoundExceptionWhileUnsubscribed

      @Test public void testGroupIdNotFoundExceptionWhileUnsubscribed()
      Test that GROUP_ID_NOT_FOUND error while unsubscribed is not treated as fatal. This can happen when the consumer never successfully joined the group (e.g., due to an InvalidTopicException during poll() and close() sends a leave heartbeat for a group that was never created).
    • testGroupIdNotFoundWhileStableIsFatal

      @Test public void testGroupIdNotFoundWhileStableIsFatal()
      Test that GROUP_ID_NOT_FOUND error while stable is treated as fatal. This would indicate the group was unexpectedly deleted while the member was actively participating.
    • testHeartbeatResponseOnErrorHandling

      @ParameterizedTest @MethodSource("errorProvider") public void testHeartbeatResponseOnErrorHandling(org.apache.kafka.common.protocol.Errors error, boolean isFatal)