lianetm commented on code in PR #16200:
URL: https://github.com/apache/kafka/pull/16200#discussion_r1681548025


##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/HeartbeatRequestManagerTest.java:
##########
@@ -898,6 +854,42 @@ private HeartbeatRequestManager 
createHeartbeatRequestManager(
                 heartbeatState,
                 heartbeatRequestState,
                 backgroundEventHandler,
-                metrics);
+                new Metrics());
+    }
+
+    private void mockJoiningMemberData(boolean instanceId) {
+        when(membershipManager.memberId()).thenReturn("");
+        when(membershipManager.memberEpoch()).thenReturn(0);
+        when(membershipManager.groupId()).thenReturn(DEFAULT_GROUP_ID);
+        if (instanceId)
+            
when(membershipManager.groupInstanceId()).thenReturn(Optional.of(DEFAULT_GROUP_INSTANCE_ID));
+        else
+            
when(membershipManager.groupInstanceId()).thenReturn(Optional.empty());

Review Comment:
   what about simplifying this to:
   ```
       
when(membershipManager.groupInstanceId()).thenReturn(Optional.ofNullable(instanceId));
   ```
   Passing a String instanceId as param. I find it's also clearer to have the 
string param with the explicit `instanceId` to use (or null).



##########
clients/src/test/java/org/apache/kafka/clients/consumer/internals/HeartbeatRequestManagerTest.java:
##########
@@ -898,6 +854,42 @@ private HeartbeatRequestManager 
createHeartbeatRequestManager(
                 heartbeatState,
                 heartbeatRequestState,
                 backgroundEventHandler,
-                metrics);
+                new Metrics());
+    }
+
+    private void mockJoiningMemberData(boolean instanceId) {
+        when(membershipManager.memberId()).thenReturn("");
+        when(membershipManager.memberEpoch()).thenReturn(0);
+        when(membershipManager.groupId()).thenReturn(DEFAULT_GROUP_ID);
+        if (instanceId)
+            
when(membershipManager.groupInstanceId()).thenReturn(Optional.of(DEFAULT_GROUP_INSTANCE_ID));
+        else
+            
when(membershipManager.groupInstanceId()).thenReturn(Optional.empty());

Review Comment:
   what about simplifying this to:
   ```
    
when(membershipManager.groupInstanceId()).thenReturn(Optional.ofNullable(instanceId));
   ```
   Passing a String instanceId as param. I find it's also clearer to have the 
string param with the explicit `instanceId` to use (or null).



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to