dajac commented on code in PR #14124:
URL: https://github.com/apache/kafka/pull/14124#discussion_r1316808298


##########
clients/src/test/java/org/apache/kafka/common/requests/ConsumerGroupDescribeResponseTest.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.common.requests;
+
+import org.apache.kafka.common.message.ConsumerGroupDescribeResponseData;
+import org.apache.kafka.common.protocol.Errors;
+import org.junit.jupiter.api.Test;
+
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ConsumerGroupDescribeResponseTest {
+
+    @Test
+    void testErrorCounts() {
+        // Arrange
+        Errors e = Errors.INVALID_GROUP_ID;
+        int errorCount = 2;
+        ConsumerGroupDescribeResponseData data = new 
ConsumerGroupDescribeResponseData();
+        for (int i = 0; i < errorCount; i++) {
+            data.groups().add(
+                new ConsumerGroupDescribeResponseData.DescribedGroup()
+                    .setErrorCode(e.code())
+            );
+        }
+        ConsumerGroupDescribeResponse response = new 
ConsumerGroupDescribeResponse(data);
+
+        // Act
+        Map<Errors, Integer> counts = response.errorCounts();
+
+        // Assert
+        assertEquals(errorCount, counts.get(e));
+        assertEquals(null, counts.get(Errors.COORDINATOR_NOT_AVAILABLE));

Review Comment:
   nit: You can use `assertNull` here.



##########
clients/src/test/java/org/apache/kafka/common/requests/RequestResponseTest.java:
##########
@@ -1132,10 +1135,35 @@ private AbstractResponse getResponse(ApiKeys apikey, 
short version) {
             case LIST_TRANSACTIONS: return createListTransactionsResponse();
             case ALLOCATE_PRODUCER_IDS: return 
createAllocateProducerIdsResponse();
             case CONSUMER_GROUP_HEARTBEAT: return 
createConsumerGroupHeartbeatResponse();
+            case CONSUMER_GROUP_DESCRIBE: return 
createConsumerGroupDescribeResponse();
             default: throw new IllegalArgumentException("Unknown API key " + 
apikey);
         }
     }
 
+    private ConsumerGroupDescribeRequest 
createConsumerGroupDescribeRequest(short version) {
+        ConsumerGroupDescribeRequestData data = new 
ConsumerGroupDescribeRequestData()
+            .setGroupIds(Arrays.asList("group"))
+            .setIncludeAuthorizedOperations(false);
+        return new ConsumerGroupDescribeRequest.Builder(data).build(version);
+    }
+
+    private ConsumerGroupDescribeResponse 
createConsumerGroupDescribeResponse() {
+        ConsumerGroupDescribeResponseData data = new 
ConsumerGroupDescribeResponseData()
+            .setGroups(Arrays.asList(

Review Comment:
   ditto.



##########
clients/src/test/java/org/apache/kafka/common/requests/RequestResponseTest.java:
##########
@@ -1132,10 +1135,35 @@ private AbstractResponse getResponse(ApiKeys apikey, 
short version) {
             case LIST_TRANSACTIONS: return createListTransactionsResponse();
             case ALLOCATE_PRODUCER_IDS: return 
createAllocateProducerIdsResponse();
             case CONSUMER_GROUP_HEARTBEAT: return 
createConsumerGroupHeartbeatResponse();
+            case CONSUMER_GROUP_DESCRIBE: return 
createConsumerGroupDescribeResponse();
             default: throw new IllegalArgumentException("Unknown API key " + 
apikey);
         }
     }
 
+    private ConsumerGroupDescribeRequest 
createConsumerGroupDescribeRequest(short version) {
+        ConsumerGroupDescribeRequestData data = new 
ConsumerGroupDescribeRequestData()
+            .setGroupIds(Arrays.asList("group"))

Review Comment:
   nit: Could we use `Collections.singletonList` here?



##########
clients/src/test/java/org/apache/kafka/common/requests/ConsumerGroupDescribeRequestTest.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.common.requests;
+
+import org.apache.kafka.common.message.ConsumerGroupDescribeRequestData;
+import org.apache.kafka.common.message.ConsumerGroupDescribeResponseData;
+import org.apache.kafka.common.protocol.Errors;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ConsumerGroupDescribeRequestTest {
+
+    @Test
+    void testGetErrorResponse() {
+        // Arrange
+        String groupId = "group0";
+        ConsumerGroupDescribeRequestData data = new 
ConsumerGroupDescribeRequestData();
+        data.groupIds().add(groupId);
+        ConsumerGroupDescribeRequest request = new 
ConsumerGroupDescribeRequest.Builder(data, true)
+            .build();
+        Throwable e = Errors.GROUP_AUTHORIZATION_FAILED.exception();
+
+        // Act
+        ConsumerGroupDescribeResponse response = 
request.getErrorResponse(1000, e);
+
+        // Assert

Review Comment:
   nit: Could we also assert the throttle time?



##########
clients/src/test/java/org/apache/kafka/common/requests/ConsumerGroupDescribeRequestTest.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.common.requests;
+
+import org.apache.kafka.common.message.ConsumerGroupDescribeRequestData;
+import org.apache.kafka.common.message.ConsumerGroupDescribeResponseData;
+import org.apache.kafka.common.protocol.Errors;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ConsumerGroupDescribeRequestTest {
+
+    @Test
+    void testGetErrorResponse() {
+        // Arrange

Review Comment:
   nit: We don't have `Arrange`, `Act` and `Assert` in other tests so I would 
remove them in order to remain consistent in the code base. Could you please 
remove all of them in the PR?



##########
core/src/test/scala/unit/kafka/server/KafkaApisTest.scala:
##########
@@ -6191,4 +6191,19 @@ class KafkaApisTest {
     val response = 
verifyNoThrottling[ConsumerGroupHeartbeatResponse](requestChannelRequest)
     assertEquals(Errors.GROUP_AUTHORIZATION_FAILED.code, 
response.data.errorCode)
   }
+
+  @Test
+  def testConsumerGroupDescribeReturnsUnsupportedVersion(): Unit = {
+    // Arrange
+    val consumerGroupDescribeRequestData = new 
ConsumerGroupDescribeRequestData()
+    consumerGroupDescribeRequestData.groupIds.add("group0")
+    val requestChannelRequest = buildRequest(new 
ConsumerGroupDescribeRequest.Builder(consumerGroupDescribeRequestData, 
true).build())
+
+    // Act
+    createKafkaApis().handle(requestChannelRequest, RequestLocal.NoCaching)
+    val response = 
verifyNoThrottling[ConsumerGroupDescribeResponse](requestChannelRequest)
+
+    // Assert
+    assertEquals(Errors.UNSUPPORTED_VERSION.code, 
response.data.groups.get(0).errorCode)

Review Comment:
   nit: In this case, we usually prefer to assert the entire response to ensure 
that it only contain what we expect. For instance, we would build the 
ConsumerGroupDescribeResponseData and use assertEquals(expected, response). We 
can keep it as it is now but let's change it when we update this test during 
the implementation of the next part.



##########
clients/src/test/java/org/apache/kafka/common/requests/ConsumerGroupDescribeRequestTest.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.common.requests;
+
+import org.apache.kafka.common.message.ConsumerGroupDescribeRequestData;
+import org.apache.kafka.common.message.ConsumerGroupDescribeResponseData;
+import org.apache.kafka.common.protocol.Errors;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ConsumerGroupDescribeRequestTest {
+
+    @Test
+    void testGetErrorResponse() {
+        // Arrange
+        String groupId = "group0";
+        ConsumerGroupDescribeRequestData data = new 
ConsumerGroupDescribeRequestData();
+        data.groupIds().add(groupId);

Review Comment:
   nit: I would add a second group to ensure that all groups are put in the 
response.



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