nizhikov commented on code in PR #15363:
URL: https://github.com/apache/kafka/pull/15363#discussion_r1514832937


##########
tools/src/test/java/org/apache/kafka/tools/consumer/group/DescribeConsumerGroupTest.java:
##########
@@ -0,0 +1,840 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.tools.consumer.group;
+
+import kafka.admin.ConsumerGroupCommand;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.clients.consumer.RangeAssignor;
+import org.apache.kafka.clients.consumer.RoundRobinAssignor;
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.errors.TimeoutException;
+import org.apache.kafka.common.utils.Exit;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.ValueSource;
+import scala.Function0;
+import scala.Function1;
+import scala.Option;
+import scala.collection.Seq;
+import scala.runtime.BoxedUnit;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.apache.kafka.test.TestUtils.RANDOM;
+import static 
org.apache.kafka.tools.ToolsTestUtils.TEST_WITH_PARAMETERIZED_QUORUM_AND_GROUP_PROTOCOL_NAMES;
+import static 
org.apache.kafka.tools.ToolsTestUtils.TEST_WITH_PARAMETERIZED_QUORUM_NAME;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+public class DescribeConsumerGroupTest extends ConsumerGroupCommandTest {
+    private static final String[][] DESCRIBE_TYPE_OFFSETS = new String[][]{new 
String[]{""}, new String[]{"--offsets"}};

Review Comment:
   Yes. Refactored



##########
tools/src/test/java/org/apache/kafka/tools/consumer/group/DescribeConsumerGroupTest.java:
##########
@@ -0,0 +1,840 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.tools.consumer.group;
+
+import kafka.admin.ConsumerGroupCommand;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.clients.consumer.RangeAssignor;
+import org.apache.kafka.clients.consumer.RoundRobinAssignor;
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.errors.TimeoutException;
+import org.apache.kafka.common.utils.Exit;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.ValueSource;
+import scala.Function0;
+import scala.Function1;
+import scala.Option;
+import scala.collection.Seq;
+import scala.runtime.BoxedUnit;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.apache.kafka.test.TestUtils.RANDOM;
+import static 
org.apache.kafka.tools.ToolsTestUtils.TEST_WITH_PARAMETERIZED_QUORUM_AND_GROUP_PROTOCOL_NAMES;
+import static 
org.apache.kafka.tools.ToolsTestUtils.TEST_WITH_PARAMETERIZED_QUORUM_NAME;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+public class DescribeConsumerGroupTest extends ConsumerGroupCommandTest {
+    private static final String[][] DESCRIBE_TYPE_OFFSETS = new String[][]{new 
String[]{""}, new String[]{"--offsets"}};
+    private static final String[][] DESCRIBE_TYPE_MEMBERS = new String[][]{new 
String[]{"--members"}, new String[]{"--members", "--verbose"}};
+    private static final String[][] DESCRIBE_TYPE_STATE = new String[][]{new 
String[]{"--state"}};
+    private static final String[][] DESCRIBE_TYPES;
+
+    static {
+        List<String[]> describeTypes = new ArrayList<>();
+
+        describeTypes.addAll(Arrays.asList(DESCRIBE_TYPE_OFFSETS));
+        describeTypes.addAll(Arrays.asList(DESCRIBE_TYPE_MEMBERS));
+        describeTypes.addAll(Arrays.asList(DESCRIBE_TYPE_STATE));
+
+        DESCRIBE_TYPES = describeTypes.toArray(new String[0][0]);
+    }
+
+    @ParameterizedTest(name = 
TEST_WITH_PARAMETERIZED_QUORUM_AND_GROUP_PROTOCOL_NAMES)
+    @MethodSource({"getTestQuorumAndGroupProtocolParametersAll"})
+    public void testDescribeNonExistingGroup(String quorum, String 
groupProtocol) {
+        createOffsetsTopic(listenerName(), new Properties());
+        String missingGroup = "missing.group";
+
+        for (String[] describeType : DESCRIBE_TYPES) {
+            // note the group to be queried is a different (non-existing) group
+            List<String> cgcArgs = new 
ArrayList<>(Arrays.asList("--bootstrap-server", 
bootstrapServers(listenerName()), "--describe", "--group", missingGroup));
+            cgcArgs.addAll(Arrays.asList(describeType));
+            ConsumerGroupCommand.ConsumerGroupService service = 
getConsumerGroupService(cgcArgs.toArray(new String[0]));
+
+            String output = 
kafka.utils.TestUtils.grabConsoleOutput(describeGroups(service));
+            assertTrue(output.contains("Consumer group '" + missingGroup + "' 
does not exist."),
+                "Expected error was not detected for describe option '" + 
String.join(" ", describeType) + "'");
+        }
+    }
+
+    @ParameterizedTest(name = TEST_WITH_PARAMETERIZED_QUORUM_NAME)
+    @ValueSource(strings = {"zk", "kraft"})
+    public void testDescribeWithMultipleSubActions(String quorum) {
+        AtomicInteger exitStatus = new AtomicInteger(0);
+        AtomicReference<String> exitMessage = new AtomicReference<>("");
+        Exit.setExitProcedure((status, err) -> {
+            exitStatus.set(status);
+            exitMessage.set(err);
+            throw new RuntimeException();
+        });
+        String[] cgcArgs = new String[]{"--bootstrap-server", 
bootstrapServers(listenerName()), "--describe", "--group", GROUP, "--members", 
"--state"};
+        try {
+            ConsumerGroupCommand.main(cgcArgs);
+        } catch (RuntimeException e) {
+            //expected
+        } finally {
+            Exit.resetExitProcedure();
+        }
+        assertEquals(1, exitStatus.get());
+        assertTrue(exitMessage.get().contains("Option [describe] takes at most 
one of these options"));
+    }
+
+    @ParameterizedTest(name = TEST_WITH_PARAMETERIZED_QUORUM_NAME)
+    @ValueSource(strings = {"zk", "kraft"})
+    public void testDescribeWithStateValue(String quorum) {
+        AtomicInteger exitStatus = new AtomicInteger(0);
+        AtomicReference<String> exitMessage = new AtomicReference<>("");
+        Exit.setExitProcedure((status, err) -> {
+            exitStatus.set(status);
+            exitMessage.set(err);
+            throw new RuntimeException();
+        });
+        String[] cgcArgs = new String[]{"--bootstrap-server", 
bootstrapServers(listenerName()), "--describe", "--all-groups", "--state", 
"Stable"};
+        try {

Review Comment:
   Done



##########
tools/src/test/java/org/apache/kafka/tools/consumer/group/DescribeConsumerGroupTest.java:
##########
@@ -0,0 +1,840 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.tools.consumer.group;
+
+import kafka.admin.ConsumerGroupCommand;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.clients.consumer.RangeAssignor;
+import org.apache.kafka.clients.consumer.RoundRobinAssignor;
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.errors.TimeoutException;
+import org.apache.kafka.common.utils.Exit;
+import org.apache.kafka.test.TestUtils;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.ValueSource;
+import scala.Function0;
+import scala.Function1;
+import scala.Option;
+import scala.collection.Seq;
+import scala.runtime.BoxedUnit;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.apache.kafka.test.TestUtils.RANDOM;
+import static 
org.apache.kafka.tools.ToolsTestUtils.TEST_WITH_PARAMETERIZED_QUORUM_AND_GROUP_PROTOCOL_NAMES;
+import static 
org.apache.kafka.tools.ToolsTestUtils.TEST_WITH_PARAMETERIZED_QUORUM_NAME;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+public class DescribeConsumerGroupTest extends ConsumerGroupCommandTest {
+    private static final String[][] DESCRIBE_TYPE_OFFSETS = new String[][]{new 
String[]{""}, new String[]{"--offsets"}};
+    private static final String[][] DESCRIBE_TYPE_MEMBERS = new String[][]{new 
String[]{"--members"}, new String[]{"--members", "--verbose"}};
+    private static final String[][] DESCRIBE_TYPE_STATE = new String[][]{new 
String[]{"--state"}};
+    private static final String[][] DESCRIBE_TYPES;
+
+    static {
+        List<String[]> describeTypes = new ArrayList<>();
+
+        describeTypes.addAll(Arrays.asList(DESCRIBE_TYPE_OFFSETS));
+        describeTypes.addAll(Arrays.asList(DESCRIBE_TYPE_MEMBERS));
+        describeTypes.addAll(Arrays.asList(DESCRIBE_TYPE_STATE));
+
+        DESCRIBE_TYPES = describeTypes.toArray(new String[0][0]);
+    }
+
+    @ParameterizedTest(name = 
TEST_WITH_PARAMETERIZED_QUORUM_AND_GROUP_PROTOCOL_NAMES)
+    @MethodSource({"getTestQuorumAndGroupProtocolParametersAll"})
+    public void testDescribeNonExistingGroup(String quorum, String 
groupProtocol) {
+        createOffsetsTopic(listenerName(), new Properties());
+        String missingGroup = "missing.group";
+
+        for (String[] describeType : DESCRIBE_TYPES) {
+            // note the group to be queried is a different (non-existing) group
+            List<String> cgcArgs = new 
ArrayList<>(Arrays.asList("--bootstrap-server", 
bootstrapServers(listenerName()), "--describe", "--group", missingGroup));
+            cgcArgs.addAll(Arrays.asList(describeType));
+            ConsumerGroupCommand.ConsumerGroupService service = 
getConsumerGroupService(cgcArgs.toArray(new String[0]));
+
+            String output = 
kafka.utils.TestUtils.grabConsoleOutput(describeGroups(service));
+            assertTrue(output.contains("Consumer group '" + missingGroup + "' 
does not exist."),
+                "Expected error was not detected for describe option '" + 
String.join(" ", describeType) + "'");
+        }
+    }
+
+    @ParameterizedTest(name = TEST_WITH_PARAMETERIZED_QUORUM_NAME)
+    @ValueSource(strings = {"zk", "kraft"})
+    public void testDescribeWithMultipleSubActions(String quorum) {
+        AtomicInteger exitStatus = new AtomicInteger(0);
+        AtomicReference<String> exitMessage = new AtomicReference<>("");
+        Exit.setExitProcedure((status, err) -> {
+            exitStatus.set(status);
+            exitMessage.set(err);
+            throw new RuntimeException();
+        });
+        String[] cgcArgs = new String[]{"--bootstrap-server", 
bootstrapServers(listenerName()), "--describe", "--group", GROUP, "--members", 
"--state"};
+        try {

Review Comment:
   Done



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