Re: [PR] KAFKA-14589 [2/4] Tests of ConsoleGroupCommand rewritten in java [kafka]

2024-03-07 Thread via GitHub


nizhikov commented on PR #15363:
URL: https://github.com/apache/kafka/pull/15363#issuecomment-1982991126

   @chia7712 Thanks for the review and merge!


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



Re: [PR] KAFKA-14589 [2/4] Tests of ConsoleGroupCommand rewritten in java [kafka]

2024-03-06 Thread via GitHub


chia7712 commented on PR #15363:
URL: https://github.com/apache/kafka/pull/15363#issuecomment-1982054671

   @nizhikov thanks for this nice patch


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



Re: [PR] KAFKA-14589 [2/4] Tests of ConsoleGroupCommand rewritten in java [kafka]

2024-03-06 Thread via GitHub


chia7712 merged PR #15363:
URL: https://github.com/apache/kafka/pull/15363


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



Re: [PR] KAFKA-14589 [2/4] Tests of ConsoleGroupCommand rewritten in java [kafka]

2024-03-06 Thread via GitHub


chia7712 commented on PR #15363:
URL: https://github.com/apache/kafka/pull/15363#issuecomment-1982051350

   the failed tests pass on my machine.
   ```sh
   ./gradlew cleanTest core:test --tests ReplicaManagerTest --tests 
LogDirFailureTest
   ```
   will merge it


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



Re: [PR] KAFKA-14589 [2/4] Tests of ConsoleGroupCommand rewritten in java [kafka]

2024-03-06 Thread via GitHub


nizhikov commented on PR #15363:
URL: https://github.com/apache/kafka/pull/15363#issuecomment-1981384111

   @nizhikov Thanks for the review.
   All your comments fixed.
   Please, take a look one more time.


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



Re: [PR] KAFKA-14589 [2/4] Tests of ConsoleGroupCommand rewritten in java [kafka]

2024-03-06 Thread via GitHub


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


##
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 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 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 exitMessage = new Atomi

Re: [PR] KAFKA-14589 [2/4] Tests of ConsoleGroupCommand rewritten in java [kafka]

2024-03-06 Thread via GitHub


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.

Re: [PR] KAFKA-14589 [2/4] Tests of ConsoleGroupCommand rewritten in java [kafka]

2024-03-06 Thread via GitHub


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


##
tools/src/test/java/org/apache/kafka/tools/ToolsTestUtils.java:
##
@@ -210,6 +212,29 @@ public static File tempPropertiesFile(Map 
properties) throws IOE
 return org.apache.kafka.test.TestUtils.tempFile(sb.toString());
 }
 
+/**
+ * Invoke `compute` until `predicate` is true or `waitTime` elapses.
+ *
+ * Return the last `compute` result and a boolean indicating whether 
`predicate` succeeded for that value.
+ *
+ * This method is useful in cases where `waitUntilTrue` makes it awkward 
to provide good error messages.
+ */
+public static  Tuple2 computeUntilTrue(Supplier compute, 
long waitTime, long pause, Predicate predicate) {

Review Comment:
   this change can be reverted since it is unused now.



##
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 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 cgcArgs = new 
ArrayList<>(Arrays.asList("--bootstrap-server", 
bootstrapServers(listenerName()), "--describe", "--group", missingGroup));
+cgcArgs.addAl

Re: [PR] KAFKA-14589 [2/4] Tests of ConsoleGroupCommand rewritten in java [kafka]

2024-03-06 Thread via GitHub


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


##
tools/src/test/java/org/apache/kafka/tools/consumer/group/DescribeConsumerGroupTest.java:
##
@@ -0,0 +1,855 @@
+/*
+ * 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.apache.kafka.tools.ToolsTestUtils;
+import org.apache.kafka.tools.Tuple2;
+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.DEFAULT_MAX_WAIT_MS;
+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 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 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));

Review Comment:
   Not for now.
   
   Scala caches `System.out` value inside `Console#outVar` and when we change 
`System.out` value from java code we can't capture scala code output.
   
   But, in big PR (which moves command itself) I use 
`ToolsTestUtils#captureStandartOut` instead of scala version.



-- 
This is an automated message from the Apache Git Servic

Re: [PR] KAFKA-14589 [2/4] Tests of ConsoleGroupCommand rewritten in java [kafka]

2024-03-06 Thread via GitHub


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


##
tools/src/test/java/org/apache/kafka/tools/consumer/group/DescribeConsumerGroupTest.java:
##
@@ -0,0 +1,855 @@
+/*
+ * 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.apache.kafka.tools.ToolsTestUtils;
+import org.apache.kafka.tools.Tuple2;
+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.DEFAULT_MAX_WAIT_MS;
+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 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 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 test

Re: [PR] KAFKA-14589 [2/4] Tests of ConsoleGroupCommand rewritten in java [kafka]

2024-03-06 Thread via GitHub


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


##
tools/src/test/java/org/apache/kafka/tools/consumer/group/DescribeConsumerGroupTest.java:
##
@@ -0,0 +1,855 @@
+/*
+ * 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.apache.kafka.tools.ToolsTestUtils;
+import org.apache.kafka.tools.Tuple2;
+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.DEFAULT_MAX_WAIT_MS;
+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 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 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));

Review Comment:
   Can `kafka.utils.TestUtils.grabConsoleOutput` be replaced by 
`ToolsTestUtils#captureStandardOut`?



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

Re: [PR] KAFKA-14589 [2/4] Tests of ConsoleGroupCommand rewritten in java [kafka]

2024-03-06 Thread via GitHub


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


##
tools/src/test/java/org/apache/kafka/tools/consumer/group/DescribeConsumerGroupTest.java:
##
@@ -0,0 +1,855 @@
+/*
+ * 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.apache.kafka.tools.ToolsTestUtils;
+import org.apache.kafka.tools.Tuple2;
+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.DEFAULT_MAX_WAIT_MS;
+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 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 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 test

Re: [PR] KAFKA-14589 [2/4] Tests of ConsoleGroupCommand rewritten in java [kafka]

2024-03-06 Thread via GitHub


nizhikov commented on PR #15363:
URL: https://github.com/apache/kafka/pull/15363#issuecomment-1980469311

   @chia7712 This PR ready for review.
   
   Please, take a look.


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



Re: [PR] KAFKA-14589 [2/4] Tests of ConsoleGroupCommand rewritten in java [kafka]

2024-03-04 Thread via GitHub


nizhikov commented on PR #15363:
URL: https://github.com/apache/kafka/pull/15363#issuecomment-1976786020

   @chia7712 
   
   Other PR is #15465
   
   Seems, PR's are reviewable now.
   Please, take a look.


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



Re: [PR] KAFKA-14589 [2/4] Tests of ConsoleGroupCommand rewritten in java [kafka]

2024-03-04 Thread via GitHub


nizhikov commented on PR #15363:
URL: https://github.com/apache/kafka/pull/15363#issuecomment-1976763803

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