FrankYang0529 commented on code in PR #19856: URL: https://github.com/apache/kafka/pull/19856#discussion_r2126840075
########## clients/src/test/java/org/apache/kafka/clients/consumer/internals/ConsumerHeartbeatRequestManagerTest.java: ########## @@ -1009,6 +1009,28 @@ public void testRegexInJoiningHeartbeat() { assertNull(data.subscribedTopicRegex()); } + @Test + public void testRackIdInHeartbeatLifecycle() { + heartbeatState = new HeartbeatState(subscriptions, membershipManager, DEFAULT_MAX_POLL_INTERVAL_MS); + createHeartbeatRequestStateWithZeroHeartbeatInterval(); + + // Initial heartbeat with rackId + mockJoiningMemberData(null); + when(membershipManager.rackId()).thenReturn(Optional.of("rack1")); + ConsumerGroupHeartbeatRequestData data = heartbeatState.buildRequestData(); + assertEquals("rack1", data.rackId()); + + // RackId not included in HB if not updated + when(membershipManager.state()).thenReturn(MemberState.STABLE); + data = heartbeatState.buildRequestData(); + assertNull(data.rackId()); + + // Empty rackId not included in HB + when(membershipManager.rackId()).thenReturn(Optional.empty()); + data = heartbeatState.buildRequestData(); + assertNull(data.rackId()); + } Review Comment: I add a case: if member state changes to JOINING again, it sends `rackId` again. Thanks. -- 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