You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2022/11/16 04:48:43 UTC

[GitHub] [kafka] jeffkbkim commented on a diff in pull request #12845: KAFKA-14367; Add `JoinGroup` to the new `GroupCoordinator` interface

jeffkbkim commented on code in PR #12845:
URL: https://github.com/apache/kafka/pull/12845#discussion_r1023478149


##########
core/src/main/scala/kafka/coordinator/group/GroupCoordinatorAdapter.scala:
##########
@@ -0,0 +1,81 @@
+/**
+ * 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 kafka.coordinator.group
+
+import kafka.server.RequestLocal
+
+import org.apache.kafka.common.message.{JoinGroupRequestData, JoinGroupResponseData}
+import org.apache.kafka.coordinator.group.GroupCoordinatorRequestContext
+
+import java.util.concurrent.CompletableFuture
+import scala.jdk.CollectionConverters._
+
+class GroupCoordinatorAdapter(

Review Comment:
   can we add a comment that this is a wrapper around the existing group coordinator?



##########
core/src/test/scala/unit/kafka/coordinator/group/GroupCoordinatorAdapterTest.scala:
##########
@@ -0,0 +1,138 @@
+/**
+ * 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 kafka.coordinator.group
+
+import kafka.coordinator.group.GroupCoordinatorConcurrencyTest.JoinGroupCallback
+import kafka.server.RequestLocal
+
+import org.apache.kafka.common.message.{JoinGroupRequestData, JoinGroupResponseData}
+import org.apache.kafka.common.message.JoinGroupRequestData.JoinGroupRequestProtocol
+import org.apache.kafka.common.message.JoinGroupResponseData.JoinGroupResponseMember
+import org.apache.kafka.common.protocol.{ApiKeys, Errors}
+import org.apache.kafka.common.utils.BufferSupplier
+import org.apache.kafka.common.utils.annotation.ApiKeyVersionsSource
+import org.apache.kafka.coordinator.group.GroupCoordinatorRequestContext
+
+import org.junit.jupiter.api.Assertions.{assertEquals, assertFalse, assertTrue}
+import org.junit.jupiter.params.ParameterizedTest
+import org.mockito.{ArgumentCaptor, ArgumentMatchers}
+import org.mockito.Mockito.{mock, verify}
+
+import java.net.InetAddress
+import scala.jdk.CollectionConverters._
+
+class GroupCoordinatorAdapterTest {
+
+  private def makeContext(
+    apiVersion: Short
+  ): GroupCoordinatorRequestContext = {
+    new GroupCoordinatorRequestContext(
+      apiVersion,
+      "client",
+      InetAddress.getLocalHost,
+      BufferSupplier.create()
+    )
+  }
+
+  @ParameterizedTest
+  @ApiKeyVersionsSource(apiKey = ApiKeys.JOIN_GROUP)
+  def testJoinGroup(version: Short): Unit = {
+    val groupCoordinator = mock(classOf[GroupCoordinator])
+    val adapter = new GroupCoordinatorAdapter(groupCoordinator)
+
+    val ctx = makeContext(version)
+    val data = new JoinGroupRequestData()
+      .setGroupId("group")
+      .setMemberId("member")
+      .setProtocolType("consumer")
+      .setRebalanceTimeoutMs(1000)
+      .setSessionTimeoutMs(2000)
+      .setReason("reason")
+      .setProtocols(new JoinGroupRequestData.JoinGroupRequestProtocolCollection(List(
+        new JoinGroupRequestProtocol()
+          .setName("first")
+          .setMetadata("first".getBytes()),
+        new JoinGroupRequestProtocol()
+          .setName("second")
+          .setMetadata("second".getBytes())).iterator.asJava))
+
+    val future = adapter.joinGroup(ctx, data)
+    assertFalse(future.isDone)
+
+    val capturedProtocols: ArgumentCaptor[List[(String, Array[Byte])]] =
+      ArgumentCaptor.forClass(classOf[List[(String, Array[Byte])]])
+    val capturedCallback: ArgumentCaptor[JoinGroupCallback] =
+      ArgumentCaptor.forClass(classOf[JoinGroupCallback])
+
+    verify(groupCoordinator).handleJoinGroup(
+      ArgumentMatchers.eq(data.groupId),
+      ArgumentMatchers.eq(data.memberId),
+      ArgumentMatchers.eq(None),
+      ArgumentMatchers.eq(if (version >= 4) true else false),
+      ArgumentMatchers.eq(if (version >= 9) true else false),
+      ArgumentMatchers.eq(ctx.clientId),
+      ArgumentMatchers.eq(InetAddress.getLocalHost.toString),
+      ArgumentMatchers.eq(data.rebalanceTimeoutMs),
+      ArgumentMatchers.eq(data.sessionTimeoutMs),
+      ArgumentMatchers.eq(data.protocolType),
+      capturedProtocols.capture(),
+      capturedCallback.capture(),
+      ArgumentMatchers.eq(Some("reason")),
+      ArgumentMatchers.eq(RequestLocal(ctx.bufferSupplier))
+    )
+
+    assertEquals(List(
+      ("first", "first"),
+      ("second", "second")
+    ), capturedProtocols.getValue.map { case (name, metadata) =>
+      (name, new String(metadata))
+    }.toList)

Review Comment:
   do we need toList?



##########
core/src/test/scala/unit/kafka/coordinator/group/GroupCoordinatorAdapterTest.scala:
##########
@@ -0,0 +1,138 @@
+/**
+ * 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 kafka.coordinator.group
+
+import kafka.coordinator.group.GroupCoordinatorConcurrencyTest.JoinGroupCallback
+import kafka.server.RequestLocal
+
+import org.apache.kafka.common.message.{JoinGroupRequestData, JoinGroupResponseData}
+import org.apache.kafka.common.message.JoinGroupRequestData.JoinGroupRequestProtocol
+import org.apache.kafka.common.message.JoinGroupResponseData.JoinGroupResponseMember
+import org.apache.kafka.common.protocol.{ApiKeys, Errors}
+import org.apache.kafka.common.utils.BufferSupplier
+import org.apache.kafka.common.utils.annotation.ApiKeyVersionsSource
+import org.apache.kafka.coordinator.group.GroupCoordinatorRequestContext
+
+import org.junit.jupiter.api.Assertions.{assertEquals, assertFalse, assertTrue}
+import org.junit.jupiter.params.ParameterizedTest
+import org.mockito.{ArgumentCaptor, ArgumentMatchers}
+import org.mockito.Mockito.{mock, verify}
+
+import java.net.InetAddress
+import scala.jdk.CollectionConverters._
+
+class GroupCoordinatorAdapterTest {
+
+  private def makeContext(
+    apiVersion: Short
+  ): GroupCoordinatorRequestContext = {
+    new GroupCoordinatorRequestContext(
+      apiVersion,
+      "client",
+      InetAddress.getLocalHost,
+      BufferSupplier.create()
+    )
+  }
+
+  @ParameterizedTest
+  @ApiKeyVersionsSource(apiKey = ApiKeys.JOIN_GROUP)
+  def testJoinGroup(version: Short): Unit = {

Review Comment:
   maybe a more descriptive test name would be useful here



##########
core/src/test/scala/unit/kafka/server/KafkaApisTest.scala:
##########
@@ -2524,196 +2528,166 @@ class KafkaApisTest {
     assertEquals(MemoryRecords.EMPTY, FetchResponse.recordsOrFail(partitionData))
   }
 
-  @Test
-  def testJoinGroupProtocolsOrder(): Unit = {

Review Comment:
   do you mean "now"?



##########
core/src/main/scala/kafka/server/KafkaApis.scala:
##########
@@ -1646,73 +1649,46 @@ class KafkaApis(val requestChannel: RequestChannel,
     }
   }
 
+  private def makeGroupCoordinatorRequestContextFrom(

Review Comment:
   the naming seems slightly off. how's createGroupCoordinatorRequestContext?



##########
core/src/main/scala/kafka/server/KafkaApis.scala:
##########
@@ -94,6 +95,7 @@ class KafkaApis(val requestChannel: RequestChannel,
                 val metadataSupport: MetadataSupport,
                 val replicaManager: ReplicaManager,
                 val groupCoordinator: GroupCoordinator,
+                val newGroupCoordinator: org.apache.kafka.coordinator.group.GroupCoordinator,

Review Comment:
   should we add a comment?



-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org