dajac commented on a change in pull request #11571:
URL: https://github.com/apache/kafka/pull/11571#discussion_r783185731



##########
File path: 
clients/src/test/java/org/apache/kafka/clients/admin/KafkaAdminClientTest.java
##########
@@ -3907,6 +3910,79 @@ public void testRemoveMembersFromGroup() throws 
Exception {
         }
     }
 
+    @Test
+    public void testRemoveMembersFromGroupReason() throws Exception {
+        final Cluster cluster = mockCluster(3, 0);
+        final Time time = new MockTime();
+
+        try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(time, 
cluster)) {
+
+            env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
+
+            
env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, 
env.cluster().controller()));
+            env.kafkaClient().prepareResponse(body -> {
+                if (!(body instanceof LeaveGroupRequest)) {
+                    return false;
+                }
+                LeaveGroupRequestData leaveGroupRequest = ((LeaveGroupRequest) 
body).data();
+
+                return leaveGroupRequest.members().stream().allMatch(
+                    member -> member.reason().equals(LEAVE_GROUP_REASON + ": 
testing remove members reason")
+                );
+            }, new LeaveGroupResponse(new 
LeaveGroupResponseData().setErrorCode(Errors.NONE.code()).setMembers(
+                    Arrays.asList(
+                        new MemberResponse().setGroupInstanceId("instance-1"),
+                        new MemberResponse().setGroupInstanceId("instance-2")
+                    ))
+            ));
+
+            Collection<MemberToRemove> membersToRemove = Arrays.asList(new 
MemberToRemove("instance-1"), new MemberToRemove("instance-2"));
+
+            RemoveMembersFromConsumerGroupOptions options = new 
RemoveMembersFromConsumerGroupOptions(membersToRemove);
+            options.reason("testing remove members reason");
+
+            final RemoveMembersFromConsumerGroupResult result = 
env.adminClient().removeMembersFromConsumerGroup(
+                    GROUP_ID, options);
+
+            assertNull(result.all().get());
+        }
+    }
+
+    @Test
+    public void testRemoveMembersFromGroupDefaultReason() throws Exception {

Review comment:
       The code duplication is a bit annoying here, don't you think? I wonder 
if we could define an helper method, say `testRemoveMembersFromGroup(String 
reason, String expectedReason)`. Then we could call it from within the two test 
cases:
   * `testRemoveMembersFromGroup("testing remove members reason", 
LEAVE_GROUP_REASON + ": testing remove members reason")`
   * `testRemoveMembersFromGroup(null, LEAVE_GROUP_REASON)` - passing `null` is 
somewhat equivalent to not setting the reason at all. Otherwise, we could pass 
the `RemoveMembersFromConsumerGroupOptions` to the helper method.
   
   What do you think?
   
   




-- 
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


Reply via email to