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


##########
core/src/test/scala/unit/kafka/server/ConsumerProtocolMigrationTest.scala:
##########
@@ -0,0 +1,177 @@
+/**
+ * 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.server
+
+import kafka.test.ClusterInstance
+import kafka.test.annotation.{ClusterConfigProperty, ClusterTest, 
ClusterTestDefaults, Type}
+import kafka.test.junit.ClusterTestExtensions
+import org.apache.kafka.common.message.ListGroupsResponseData
+import org.apache.kafka.common.protocol.{ApiKeys, Errors}
+import org.apache.kafka.coordinator.group.Group
+import org.apache.kafka.coordinator.group.classic.ClassicGroupState
+import 
org.apache.kafka.coordinator.group.consumer.ConsumerGroup.ConsumerGroupState
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Tag
+import org.junit.jupiter.api.Timeout
+import org.junit.jupiter.api.extension.ExtendWith
+
+@Timeout(120)
+@ExtendWith(value = Array(classOf[ClusterTestExtensions]))
+@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1)
+@Tag("integration")
+class ConsumerProtocolMigrationTest(cluster: ClusterInstance) extends 
GroupCoordinatorBaseRequestTest(cluster) {
+  @ClusterTest(serverProperties = Array(
+    new ClusterConfigProperty(key = "group.coordinator.new.enable", value = 
"true"),

Review Comment:
   nit: It may be better to use `new ClusterConfigProperty(key = 
"group.coordinator.rebalance.protocols", value = "classic,consumer")` now.



##########
core/src/test/scala/unit/kafka/server/ConsumerProtocolMigrationTest.scala:
##########
@@ -0,0 +1,177 @@
+/**
+ * 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.server
+
+import kafka.test.ClusterInstance
+import kafka.test.annotation.{ClusterConfigProperty, ClusterTest, 
ClusterTestDefaults, Type}
+import kafka.test.junit.ClusterTestExtensions
+import org.apache.kafka.common.message.ListGroupsResponseData
+import org.apache.kafka.common.protocol.{ApiKeys, Errors}
+import org.apache.kafka.coordinator.group.Group
+import org.apache.kafka.coordinator.group.classic.ClassicGroupState
+import 
org.apache.kafka.coordinator.group.consumer.ConsumerGroup.ConsumerGroupState
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Tag
+import org.junit.jupiter.api.Timeout
+import org.junit.jupiter.api.extension.ExtendWith
+
+@Timeout(120)
+@ExtendWith(value = Array(classOf[ClusterTestExtensions]))
+@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1)
+@Tag("integration")
+class ConsumerProtocolMigrationTest(cluster: ClusterInstance) extends 
GroupCoordinatorBaseRequestTest(cluster) {
+  @ClusterTest(serverProperties = Array(
+    new ClusterConfigProperty(key = "group.coordinator.new.enable", value = 
"true"),
+    new ClusterConfigProperty(key = "offsets.topic.num.partitions", value = 
"1"),
+    new ClusterConfigProperty(key = "offsets.topic.replication.factor", value 
= "1")
+  ))
+  def testOfflineUpgrade(): Unit = {
+    // Creates the __consumer_offsets topics because it won't be created 
automatically
+    // in this test because it does not use FindCoordinator API.
+    createOffsetsTopic()
+
+    // Create the topic.
+    createTopic(
+      topic = "foo",
+      numPartitions = 3
+    )
+
+    // Create a classic group by joining a member.
+    val groupId = "grp"
+    val (memberId, _) = joinDynamicConsumerGroupWithOldProtocol(groupId)
+
+    // The joining request from a consumer group member is rejected.
+    val responseData = consumerGroupHeartbeat(
+      groupId = groupId,
+      rebalanceTimeoutMs = 5 * 60 * 1000,
+      subscribedTopicNames = List("foo"),
+      topicPartitions = List.empty,
+      expectedError = Errors.GROUP_ID_NOT_FOUND
+    )
+    assertEquals("Group grp is not a consumer group.", 
responseData.errorMessage)
+
+    // The member leaves the group.
+    leaveGroup(
+      groupId = groupId,
+      memberId = memberId,
+      useNewProtocol = false,
+      version = ApiKeys.LEAVE_GROUP.latestVersion(isUnstableApiEnabled)
+    )
+
+    // Verify that the group is empty.
+    val listGroupsResponseData1 = listGroups(
+      statesFilter = List.empty,
+      typesFilter = List(Group.GroupType.CLASSIC.toString)
+    )
+
+    val expectedListResponse1 = List(new ListGroupsResponseData.ListedGroup()
+      .setGroupId(groupId)
+      .setProtocolType("consumer")
+      .setGroupState(ClassicGroupState.EMPTY.toString)
+      .setGroupType(Group.GroupType.CLASSIC.toString))
+
+    assertEquals(expectedListResponse1, listGroupsResponseData1)
+
+    // The joining request with a consumer group member is accepted.
+    consumerGroupHeartbeat(
+      groupId = groupId,
+      memberId = memberId,
+      rebalanceTimeoutMs = 5 * 60 * 1000,
+      subscribedTopicNames = List("foo"),
+      topicPartitions = List.empty,
+      expectedError = Errors.NONE
+    )
+
+    // The group has become a consumer group.
+    val listGroupsResponseData2 = listGroups(
+      statesFilter = List.empty,
+      typesFilter = List(Group.GroupType.CONSUMER.toString)
+    )
+
+    val expectedListResponse2 = List(new ListGroupsResponseData.ListedGroup()
+      .setGroupId(groupId)
+      .setProtocolType("consumer")
+      .setGroupState(ConsumerGroupState.STABLE.toString)
+      .setGroupType(Group.GroupType.CONSUMER.toString))
+
+    assertEquals(expectedListResponse2, listGroupsResponseData2)
+  }
+
+  @ClusterTest(serverProperties = Array(
+    new ClusterConfigProperty(key = "group.coordinator.new.enable", value = 
"true"),
+    new ClusterConfigProperty(key = "offsets.topic.num.partitions", value = 
"1"),
+    new ClusterConfigProperty(key = "offsets.topic.replication.factor", value 
= "1")
+  ))
+  def testOfflineDowngrade(): Unit = {
+    // Creates the __consumer_offsets topics because it won't be created 
automatically
+    // in this test because it does not use FindCoordinator API.
+    createOffsetsTopic()
+
+    // Create the topic.
+    createTopic(
+      topic = "foo",
+      numPartitions = 3
+    )
+
+    // Create a consumer group by joining a member.
+    val groupId = "grp"
+    val (memberId, _) = joinConsumerGroupWithNewProtocol(groupId)
+
+    // The joining request from a classic group member is rejected.
+    val joinGroupResponseData = sendJoinRequest(groupId = groupId)
+    assertEquals(Errors.GROUP_ID_NOT_FOUND.code, 
joinGroupResponseData.errorCode)
+
+    // The member leaves the group.
+    leaveGroup(
+      groupId = groupId,
+      memberId = memberId,
+      useNewProtocol = true,
+      version = 
ApiKeys.CONSUMER_GROUP_HEARTBEAT.latestVersion(isUnstableApiEnabled)
+    )
+
+    // Verify that the group is empty.
+    val listGroupsResponseData1 = listGroups(
+      statesFilter = List.empty,
+      typesFilter = List(Group.GroupType.CONSUMER.toString)
+    )
+
+    val expectedListResponse1 = List(new ListGroupsResponseData.ListedGroup()
+      .setGroupId(groupId)
+      .setProtocolType("consumer")
+      .setGroupState(ClassicGroupState.EMPTY.toString)
+      .setGroupType(Group.GroupType.CONSUMER.toString))
+
+    assertEquals(expectedListResponse1, listGroupsResponseData1)

Review Comment:
   Same comment about inlining.



##########
core/src/test/scala/unit/kafka/server/ConsumerProtocolMigrationTest.scala:
##########
@@ -0,0 +1,177 @@
+/**
+ * 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.server
+
+import kafka.test.ClusterInstance
+import kafka.test.annotation.{ClusterConfigProperty, ClusterTest, 
ClusterTestDefaults, Type}
+import kafka.test.junit.ClusterTestExtensions
+import org.apache.kafka.common.message.ListGroupsResponseData
+import org.apache.kafka.common.protocol.{ApiKeys, Errors}
+import org.apache.kafka.coordinator.group.Group
+import org.apache.kafka.coordinator.group.classic.ClassicGroupState
+import 
org.apache.kafka.coordinator.group.consumer.ConsumerGroup.ConsumerGroupState
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Tag
+import org.junit.jupiter.api.Timeout
+import org.junit.jupiter.api.extension.ExtendWith
+
+@Timeout(120)
+@ExtendWith(value = Array(classOf[ClusterTestExtensions]))
+@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1)
+@Tag("integration")
+class ConsumerProtocolMigrationTest(cluster: ClusterInstance) extends 
GroupCoordinatorBaseRequestTest(cluster) {
+  @ClusterTest(serverProperties = Array(
+    new ClusterConfigProperty(key = "group.coordinator.new.enable", value = 
"true"),
+    new ClusterConfigProperty(key = "offsets.topic.num.partitions", value = 
"1"),
+    new ClusterConfigProperty(key = "offsets.topic.replication.factor", value 
= "1")
+  ))
+  def testOfflineUpgrade(): Unit = {

Review Comment:
   nit: Could we say something like 
`testUpgradeFromEmptyClassicToConsumerGroup`?



##########
core/src/test/scala/unit/kafka/server/ConsumerProtocolMigrationTest.scala:
##########
@@ -0,0 +1,177 @@
+/**
+ * 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.server
+
+import kafka.test.ClusterInstance
+import kafka.test.annotation.{ClusterConfigProperty, ClusterTest, 
ClusterTestDefaults, Type}
+import kafka.test.junit.ClusterTestExtensions
+import org.apache.kafka.common.message.ListGroupsResponseData
+import org.apache.kafka.common.protocol.{ApiKeys, Errors}
+import org.apache.kafka.coordinator.group.Group
+import org.apache.kafka.coordinator.group.classic.ClassicGroupState
+import 
org.apache.kafka.coordinator.group.consumer.ConsumerGroup.ConsumerGroupState
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Tag
+import org.junit.jupiter.api.Timeout
+import org.junit.jupiter.api.extension.ExtendWith
+
+@Timeout(120)
+@ExtendWith(value = Array(classOf[ClusterTestExtensions]))
+@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1)
+@Tag("integration")
+class ConsumerProtocolMigrationTest(cluster: ClusterInstance) extends 
GroupCoordinatorBaseRequestTest(cluster) {
+  @ClusterTest(serverProperties = Array(
+    new ClusterConfigProperty(key = "group.coordinator.new.enable", value = 
"true"),
+    new ClusterConfigProperty(key = "offsets.topic.num.partitions", value = 
"1"),
+    new ClusterConfigProperty(key = "offsets.topic.replication.factor", value 
= "1")
+  ))
+  def testOfflineUpgrade(): Unit = {
+    // Creates the __consumer_offsets topics because it won't be created 
automatically
+    // in this test because it does not use FindCoordinator API.
+    createOffsetsTopic()
+
+    // Create the topic.
+    createTopic(
+      topic = "foo",
+      numPartitions = 3
+    )
+
+    // Create a classic group by joining a member.
+    val groupId = "grp"
+    val (memberId, _) = joinDynamicConsumerGroupWithOldProtocol(groupId)
+
+    // The joining request from a consumer group member is rejected.
+    val responseData = consumerGroupHeartbeat(
+      groupId = groupId,
+      rebalanceTimeoutMs = 5 * 60 * 1000,
+      subscribedTopicNames = List("foo"),
+      topicPartitions = List.empty,
+      expectedError = Errors.GROUP_ID_NOT_FOUND
+    )
+    assertEquals("Group grp is not a consumer group.", 
responseData.errorMessage)
+
+    // The member leaves the group.
+    leaveGroup(
+      groupId = groupId,
+      memberId = memberId,
+      useNewProtocol = false,
+      version = ApiKeys.LEAVE_GROUP.latestVersion(isUnstableApiEnabled)
+    )
+
+    // Verify that the group is empty.
+    val listGroupsResponseData1 = listGroups(
+      statesFilter = List.empty,
+      typesFilter = List(Group.GroupType.CLASSIC.toString)
+    )
+
+    val expectedListResponse1 = List(new ListGroupsResponseData.ListedGroup()
+      .setGroupId(groupId)
+      .setProtocolType("consumer")
+      .setGroupState(ClassicGroupState.EMPTY.toString)
+      .setGroupType(Group.GroupType.CLASSIC.toString))
+
+    assertEquals(expectedListResponse1, listGroupsResponseData1)
+
+    // The joining request with a consumer group member is accepted.
+    consumerGroupHeartbeat(
+      groupId = groupId,
+      memberId = memberId,
+      rebalanceTimeoutMs = 5 * 60 * 1000,
+      subscribedTopicNames = List("foo"),
+      topicPartitions = List.empty,
+      expectedError = Errors.NONE
+    )
+
+    // The group has become a consumer group.
+    val listGroupsResponseData2 = listGroups(
+      statesFilter = List.empty,
+      typesFilter = List(Group.GroupType.CONSUMER.toString)
+    )
+
+    val expectedListResponse2 = List(new ListGroupsResponseData.ListedGroup()
+      .setGroupId(groupId)
+      .setProtocolType("consumer")
+      .setGroupState(ConsumerGroupState.STABLE.toString)
+      .setGroupType(Group.GroupType.CONSUMER.toString))
+
+    assertEquals(expectedListResponse2, listGroupsResponseData2)
+  }
+
+  @ClusterTest(serverProperties = Array(
+    new ClusterConfigProperty(key = "group.coordinator.new.enable", value = 
"true"),

Review Comment:
   nit: Let's use the other configuration here too.



##########
core/src/test/scala/unit/kafka/server/ConsumerProtocolMigrationTest.scala:
##########
@@ -0,0 +1,177 @@
+/**
+ * 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.server
+
+import kafka.test.ClusterInstance
+import kafka.test.annotation.{ClusterConfigProperty, ClusterTest, 
ClusterTestDefaults, Type}
+import kafka.test.junit.ClusterTestExtensions
+import org.apache.kafka.common.message.ListGroupsResponseData
+import org.apache.kafka.common.protocol.{ApiKeys, Errors}
+import org.apache.kafka.coordinator.group.Group
+import org.apache.kafka.coordinator.group.classic.ClassicGroupState
+import 
org.apache.kafka.coordinator.group.consumer.ConsumerGroup.ConsumerGroupState
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Tag
+import org.junit.jupiter.api.Timeout
+import org.junit.jupiter.api.extension.ExtendWith
+
+@Timeout(120)
+@ExtendWith(value = Array(classOf[ClusterTestExtensions]))
+@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1)
+@Tag("integration")
+class ConsumerProtocolMigrationTest(cluster: ClusterInstance) extends 
GroupCoordinatorBaseRequestTest(cluster) {
+  @ClusterTest(serverProperties = Array(
+    new ClusterConfigProperty(key = "group.coordinator.new.enable", value = 
"true"),
+    new ClusterConfigProperty(key = "offsets.topic.num.partitions", value = 
"1"),
+    new ClusterConfigProperty(key = "offsets.topic.replication.factor", value 
= "1")
+  ))
+  def testOfflineUpgrade(): Unit = {
+    // Creates the __consumer_offsets topics because it won't be created 
automatically
+    // in this test because it does not use FindCoordinator API.
+    createOffsetsTopic()
+
+    // Create the topic.
+    createTopic(
+      topic = "foo",
+      numPartitions = 3
+    )
+
+    // Create a classic group by joining a member.
+    val groupId = "grp"
+    val (memberId, _) = joinDynamicConsumerGroupWithOldProtocol(groupId)
+
+    // The joining request from a consumer group member is rejected.
+    val responseData = consumerGroupHeartbeat(
+      groupId = groupId,
+      rebalanceTimeoutMs = 5 * 60 * 1000,
+      subscribedTopicNames = List("foo"),
+      topicPartitions = List.empty,
+      expectedError = Errors.GROUP_ID_NOT_FOUND
+    )
+    assertEquals("Group grp is not a consumer group.", 
responseData.errorMessage)
+
+    // The member leaves the group.
+    leaveGroup(
+      groupId = groupId,
+      memberId = memberId,
+      useNewProtocol = false,
+      version = ApiKeys.LEAVE_GROUP.latestVersion(isUnstableApiEnabled)
+    )
+
+    // Verify that the group is empty.
+    val listGroupsResponseData1 = listGroups(
+      statesFilter = List.empty,
+      typesFilter = List(Group.GroupType.CLASSIC.toString)
+    )
+
+    val expectedListResponse1 = List(new ListGroupsResponseData.ListedGroup()
+      .setGroupId(groupId)
+      .setProtocolType("consumer")
+      .setGroupState(ClassicGroupState.EMPTY.toString)
+      .setGroupType(Group.GroupType.CLASSIC.toString))
+
+    assertEquals(expectedListResponse1, listGroupsResponseData1)
+
+    // The joining request with a consumer group member is accepted.
+    consumerGroupHeartbeat(
+      groupId = groupId,
+      memberId = memberId,
+      rebalanceTimeoutMs = 5 * 60 * 1000,
+      subscribedTopicNames = List("foo"),
+      topicPartitions = List.empty,
+      expectedError = Errors.NONE
+    )
+
+    // The group has become a consumer group.
+    val listGroupsResponseData2 = listGroups(
+      statesFilter = List.empty,
+      typesFilter = List(Group.GroupType.CONSUMER.toString)
+    )
+
+    val expectedListResponse2 = List(new ListGroupsResponseData.ListedGroup()
+      .setGroupId(groupId)
+      .setProtocolType("consumer")
+      .setGroupState(ConsumerGroupState.STABLE.toString)
+      .setGroupType(Group.GroupType.CONSUMER.toString))
+
+    assertEquals(expectedListResponse2, listGroupsResponseData2)
+  }
+
+  @ClusterTest(serverProperties = Array(
+    new ClusterConfigProperty(key = "group.coordinator.new.enable", value = 
"true"),
+    new ClusterConfigProperty(key = "offsets.topic.num.partitions", value = 
"1"),
+    new ClusterConfigProperty(key = "offsets.topic.replication.factor", value 
= "1")
+  ))
+  def testOfflineDowngrade(): Unit = {

Review Comment:
   nit: Let's change the name here too if you agree with my earlier comment.



##########
core/src/test/scala/unit/kafka/server/ConsumerProtocolMigrationTest.scala:
##########
@@ -0,0 +1,177 @@
+/**
+ * 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.server
+
+import kafka.test.ClusterInstance
+import kafka.test.annotation.{ClusterConfigProperty, ClusterTest, 
ClusterTestDefaults, Type}
+import kafka.test.junit.ClusterTestExtensions
+import org.apache.kafka.common.message.ListGroupsResponseData
+import org.apache.kafka.common.protocol.{ApiKeys, Errors}
+import org.apache.kafka.coordinator.group.Group
+import org.apache.kafka.coordinator.group.classic.ClassicGroupState
+import 
org.apache.kafka.coordinator.group.consumer.ConsumerGroup.ConsumerGroupState
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Tag
+import org.junit.jupiter.api.Timeout
+import org.junit.jupiter.api.extension.ExtendWith
+
+@Timeout(120)
+@ExtendWith(value = Array(classOf[ClusterTestExtensions]))
+@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1)
+@Tag("integration")
+class ConsumerProtocolMigrationTest(cluster: ClusterInstance) extends 
GroupCoordinatorBaseRequestTest(cluster) {
+  @ClusterTest(serverProperties = Array(
+    new ClusterConfigProperty(key = "group.coordinator.new.enable", value = 
"true"),
+    new ClusterConfigProperty(key = "offsets.topic.num.partitions", value = 
"1"),
+    new ClusterConfigProperty(key = "offsets.topic.replication.factor", value 
= "1")
+  ))
+  def testOfflineUpgrade(): Unit = {
+    // Creates the __consumer_offsets topics because it won't be created 
automatically
+    // in this test because it does not use FindCoordinator API.
+    createOffsetsTopic()
+
+    // Create the topic.
+    createTopic(
+      topic = "foo",
+      numPartitions = 3
+    )
+
+    // Create a classic group by joining a member.
+    val groupId = "grp"
+    val (memberId, _) = joinDynamicConsumerGroupWithOldProtocol(groupId)
+
+    // The joining request from a consumer group member is rejected.
+    val responseData = consumerGroupHeartbeat(
+      groupId = groupId,
+      rebalanceTimeoutMs = 5 * 60 * 1000,
+      subscribedTopicNames = List("foo"),
+      topicPartitions = List.empty,
+      expectedError = Errors.GROUP_ID_NOT_FOUND
+    )
+    assertEquals("Group grp is not a consumer group.", 
responseData.errorMessage)
+
+    // The member leaves the group.
+    leaveGroup(
+      groupId = groupId,
+      memberId = memberId,
+      useNewProtocol = false,
+      version = ApiKeys.LEAVE_GROUP.latestVersion(isUnstableApiEnabled)
+    )
+
+    // Verify that the group is empty.
+    val listGroupsResponseData1 = listGroups(
+      statesFilter = List.empty,
+      typesFilter = List(Group.GroupType.CLASSIC.toString)
+    )
+
+    val expectedListResponse1 = List(new ListGroupsResponseData.ListedGroup()
+      .setGroupId(groupId)
+      .setProtocolType("consumer")
+      .setGroupState(ClassicGroupState.EMPTY.toString)
+      .setGroupType(Group.GroupType.CLASSIC.toString))
+
+    assertEquals(expectedListResponse1, listGroupsResponseData1)
+
+    // The joining request with a consumer group member is accepted.
+    consumerGroupHeartbeat(
+      groupId = groupId,
+      memberId = memberId,
+      rebalanceTimeoutMs = 5 * 60 * 1000,
+      subscribedTopicNames = List("foo"),
+      topicPartitions = List.empty,
+      expectedError = Errors.NONE
+    )
+
+    // The group has become a consumer group.
+    val listGroupsResponseData2 = listGroups(
+      statesFilter = List.empty,
+      typesFilter = List(Group.GroupType.CONSUMER.toString)
+    )
+
+    val expectedListResponse2 = List(new ListGroupsResponseData.ListedGroup()
+      .setGroupId(groupId)
+      .setProtocolType("consumer")
+      .setGroupState(ConsumerGroupState.STABLE.toString)
+      .setGroupType(Group.GroupType.CONSUMER.toString))
+
+    assertEquals(expectedListResponse2, listGroupsResponseData2)

Review Comment:
   ditto.



##########
core/src/test/scala/unit/kafka/server/ConsumerProtocolMigrationTest.scala:
##########
@@ -0,0 +1,177 @@
+/**
+ * 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.server
+
+import kafka.test.ClusterInstance
+import kafka.test.annotation.{ClusterConfigProperty, ClusterTest, 
ClusterTestDefaults, Type}
+import kafka.test.junit.ClusterTestExtensions
+import org.apache.kafka.common.message.ListGroupsResponseData
+import org.apache.kafka.common.protocol.{ApiKeys, Errors}
+import org.apache.kafka.coordinator.group.Group
+import org.apache.kafka.coordinator.group.classic.ClassicGroupState
+import 
org.apache.kafka.coordinator.group.consumer.ConsumerGroup.ConsumerGroupState
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Tag
+import org.junit.jupiter.api.Timeout
+import org.junit.jupiter.api.extension.ExtendWith
+
+@Timeout(120)
+@ExtendWith(value = Array(classOf[ClusterTestExtensions]))
+@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1)
+@Tag("integration")
+class ConsumerProtocolMigrationTest(cluster: ClusterInstance) extends 
GroupCoordinatorBaseRequestTest(cluster) {
+  @ClusterTest(serverProperties = Array(
+    new ClusterConfigProperty(key = "group.coordinator.new.enable", value = 
"true"),
+    new ClusterConfigProperty(key = "offsets.topic.num.partitions", value = 
"1"),
+    new ClusterConfigProperty(key = "offsets.topic.replication.factor", value 
= "1")
+  ))
+  def testOfflineUpgrade(): Unit = {
+    // Creates the __consumer_offsets topics because it won't be created 
automatically
+    // in this test because it does not use FindCoordinator API.
+    createOffsetsTopic()
+
+    // Create the topic.
+    createTopic(
+      topic = "foo",
+      numPartitions = 3
+    )
+
+    // Create a classic group by joining a member.
+    val groupId = "grp"
+    val (memberId, _) = joinDynamicConsumerGroupWithOldProtocol(groupId)
+
+    // The joining request from a consumer group member is rejected.
+    val responseData = consumerGroupHeartbeat(
+      groupId = groupId,
+      rebalanceTimeoutMs = 5 * 60 * 1000,
+      subscribedTopicNames = List("foo"),
+      topicPartitions = List.empty,
+      expectedError = Errors.GROUP_ID_NOT_FOUND
+    )
+    assertEquals("Group grp is not a consumer group.", 
responseData.errorMessage)
+
+    // The member leaves the group.
+    leaveGroup(
+      groupId = groupId,
+      memberId = memberId,
+      useNewProtocol = false,
+      version = ApiKeys.LEAVE_GROUP.latestVersion(isUnstableApiEnabled)
+    )
+
+    // Verify that the group is empty.
+    val listGroupsResponseData1 = listGroups(
+      statesFilter = List.empty,
+      typesFilter = List(Group.GroupType.CLASSIC.toString)
+    )
+
+    val expectedListResponse1 = List(new ListGroupsResponseData.ListedGroup()
+      .setGroupId(groupId)
+      .setProtocolType("consumer")
+      .setGroupState(ClassicGroupState.EMPTY.toString)
+      .setGroupType(Group.GroupType.CLASSIC.toString))
+
+    assertEquals(expectedListResponse1, listGroupsResponseData1)
+
+    // The joining request with a consumer group member is accepted.
+    consumerGroupHeartbeat(
+      groupId = groupId,
+      memberId = memberId,
+      rebalanceTimeoutMs = 5 * 60 * 1000,
+      subscribedTopicNames = List("foo"),
+      topicPartitions = List.empty,
+      expectedError = Errors.NONE
+    )
+
+    // The group has become a consumer group.
+    val listGroupsResponseData2 = listGroups(
+      statesFilter = List.empty,
+      typesFilter = List(Group.GroupType.CONSUMER.toString)
+    )
+
+    val expectedListResponse2 = List(new ListGroupsResponseData.ListedGroup()
+      .setGroupId(groupId)
+      .setProtocolType("consumer")
+      .setGroupState(ConsumerGroupState.STABLE.toString)
+      .setGroupType(Group.GroupType.CONSUMER.toString))
+
+    assertEquals(expectedListResponse2, listGroupsResponseData2)
+  }
+
+  @ClusterTest(serverProperties = Array(
+    new ClusterConfigProperty(key = "group.coordinator.new.enable", value = 
"true"),
+    new ClusterConfigProperty(key = "offsets.topic.num.partitions", value = 
"1"),
+    new ClusterConfigProperty(key = "offsets.topic.replication.factor", value 
= "1")
+  ))
+  def testOfflineDowngrade(): Unit = {
+    // Creates the __consumer_offsets topics because it won't be created 
automatically
+    // in this test because it does not use FindCoordinator API.
+    createOffsetsTopic()
+
+    // Create the topic.
+    createTopic(
+      topic = "foo",
+      numPartitions = 3
+    )
+
+    // Create a consumer group by joining a member.
+    val groupId = "grp"
+    val (memberId, _) = joinConsumerGroupWithNewProtocol(groupId)
+
+    // The joining request from a classic group member is rejected.
+    val joinGroupResponseData = sendJoinRequest(groupId = groupId)
+    assertEquals(Errors.GROUP_ID_NOT_FOUND.code, 
joinGroupResponseData.errorCode)
+
+    // The member leaves the group.
+    leaveGroup(
+      groupId = groupId,
+      memberId = memberId,
+      useNewProtocol = true,
+      version = 
ApiKeys.CONSUMER_GROUP_HEARTBEAT.latestVersion(isUnstableApiEnabled)
+    )
+
+    // Verify that the group is empty.
+    val listGroupsResponseData1 = listGroups(
+      statesFilter = List.empty,
+      typesFilter = List(Group.GroupType.CONSUMER.toString)
+    )
+
+    val expectedListResponse1 = List(new ListGroupsResponseData.ListedGroup()
+      .setGroupId(groupId)
+      .setProtocolType("consumer")
+      .setGroupState(ClassicGroupState.EMPTY.toString)
+      .setGroupType(Group.GroupType.CONSUMER.toString))
+
+    assertEquals(expectedListResponse1, listGroupsResponseData1)
+
+    // The joining request with a classic group member is accepted.
+    joinDynamicConsumerGroupWithOldProtocol(groupId = groupId)
+
+    // The group has become a classic group.
+    val listGroupsResponseData2 = listGroups(
+      statesFilter = List.empty,
+      typesFilter = List(Group.GroupType.CLASSIC.toString)
+    )
+
+    val expectedListResponse2 = List(new ListGroupsResponseData.ListedGroup()
+      .setGroupId(groupId)
+      .setProtocolType("consumer")
+      .setGroupState(ClassicGroupState.STABLE.toString)
+      .setGroupType(Group.GroupType.CLASSIC.toString))
+
+    assertEquals(expectedListResponse2, listGroupsResponseData2)
+  }
+}

Review Comment:
   Should we add a case which starts from a simple consumer group?



##########
core/src/test/scala/unit/kafka/server/ConsumerProtocolMigrationTest.scala:
##########
@@ -0,0 +1,177 @@
+/**
+ * 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.server
+
+import kafka.test.ClusterInstance
+import kafka.test.annotation.{ClusterConfigProperty, ClusterTest, 
ClusterTestDefaults, Type}
+import kafka.test.junit.ClusterTestExtensions
+import org.apache.kafka.common.message.ListGroupsResponseData
+import org.apache.kafka.common.protocol.{ApiKeys, Errors}
+import org.apache.kafka.coordinator.group.Group
+import org.apache.kafka.coordinator.group.classic.ClassicGroupState
+import 
org.apache.kafka.coordinator.group.consumer.ConsumerGroup.ConsumerGroupState
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Tag
+import org.junit.jupiter.api.Timeout
+import org.junit.jupiter.api.extension.ExtendWith
+
+@Timeout(120)
+@ExtendWith(value = Array(classOf[ClusterTestExtensions]))
+@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1)
+@Tag("integration")
+class ConsumerProtocolMigrationTest(cluster: ClusterInstance) extends 
GroupCoordinatorBaseRequestTest(cluster) {
+  @ClusterTest(serverProperties = Array(
+    new ClusterConfigProperty(key = "group.coordinator.new.enable", value = 
"true"),
+    new ClusterConfigProperty(key = "offsets.topic.num.partitions", value = 
"1"),
+    new ClusterConfigProperty(key = "offsets.topic.replication.factor", value 
= "1")
+  ))
+  def testOfflineUpgrade(): Unit = {
+    // Creates the __consumer_offsets topics because it won't be created 
automatically
+    // in this test because it does not use FindCoordinator API.
+    createOffsetsTopic()
+
+    // Create the topic.
+    createTopic(
+      topic = "foo",
+      numPartitions = 3
+    )
+
+    // Create a classic group by joining a member.
+    val groupId = "grp"
+    val (memberId, _) = joinDynamicConsumerGroupWithOldProtocol(groupId)
+
+    // The joining request from a consumer group member is rejected.
+    val responseData = consumerGroupHeartbeat(
+      groupId = groupId,
+      rebalanceTimeoutMs = 5 * 60 * 1000,
+      subscribedTopicNames = List("foo"),
+      topicPartitions = List.empty,
+      expectedError = Errors.GROUP_ID_NOT_FOUND
+    )
+    assertEquals("Group grp is not a consumer group.", 
responseData.errorMessage)
+
+    // The member leaves the group.
+    leaveGroup(
+      groupId = groupId,
+      memberId = memberId,
+      useNewProtocol = false,
+      version = ApiKeys.LEAVE_GROUP.latestVersion(isUnstableApiEnabled)
+    )
+
+    // Verify that the group is empty.
+    val listGroupsResponseData1 = listGroups(
+      statesFilter = List.empty,
+      typesFilter = List(Group.GroupType.CLASSIC.toString)
+    )
+
+    val expectedListResponse1 = List(new ListGroupsResponseData.ListedGroup()
+      .setGroupId(groupId)
+      .setProtocolType("consumer")
+      .setGroupState(ClassicGroupState.EMPTY.toString)
+      .setGroupType(Group.GroupType.CLASSIC.toString))
+
+    assertEquals(expectedListResponse1, listGroupsResponseData1)

Review Comment:
   nit: I am not sure if it is really better but how about doing this?
   
   ```
   assertEquals(
       List(
            new ListGroupsResponseData.ListedGroup()
               .setGroupId(groupId)
               .setProtocolType("consumer")
               .setGroupState(ClassicGroupState.EMPTY.toString)
               .setGroupType(Group.GroupType.CLASSIC.toString)
       ),
       listGroups(
             statesFilter = List.empty,
             typesFilter = List(Group.GroupType.CLASSIC.toString)
       )
   )
   ``` 



##########
core/src/test/scala/unit/kafka/server/ConsumerProtocolMigrationTest.scala:
##########
@@ -0,0 +1,177 @@
+/**
+ * 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.server
+
+import kafka.test.ClusterInstance
+import kafka.test.annotation.{ClusterConfigProperty, ClusterTest, 
ClusterTestDefaults, Type}
+import kafka.test.junit.ClusterTestExtensions
+import org.apache.kafka.common.message.ListGroupsResponseData
+import org.apache.kafka.common.protocol.{ApiKeys, Errors}
+import org.apache.kafka.coordinator.group.Group
+import org.apache.kafka.coordinator.group.classic.ClassicGroupState
+import 
org.apache.kafka.coordinator.group.consumer.ConsumerGroup.ConsumerGroupState
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Tag
+import org.junit.jupiter.api.Timeout
+import org.junit.jupiter.api.extension.ExtendWith
+
+@Timeout(120)
+@ExtendWith(value = Array(classOf[ClusterTestExtensions]))
+@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1)
+@Tag("integration")
+class ConsumerProtocolMigrationTest(cluster: ClusterInstance) extends 
GroupCoordinatorBaseRequestTest(cluster) {
+  @ClusterTest(serverProperties = Array(
+    new ClusterConfigProperty(key = "group.coordinator.new.enable", value = 
"true"),
+    new ClusterConfigProperty(key = "offsets.topic.num.partitions", value = 
"1"),
+    new ClusterConfigProperty(key = "offsets.topic.replication.factor", value 
= "1")
+  ))
+  def testOfflineUpgrade(): Unit = {
+    // Creates the __consumer_offsets topics because it won't be created 
automatically
+    // in this test because it does not use FindCoordinator API.
+    createOffsetsTopic()
+
+    // Create the topic.
+    createTopic(
+      topic = "foo",
+      numPartitions = 3
+    )
+
+    // Create a classic group by joining a member.
+    val groupId = "grp"
+    val (memberId, _) = joinDynamicConsumerGroupWithOldProtocol(groupId)
+
+    // The joining request from a consumer group member is rejected.
+    val responseData = consumerGroupHeartbeat(
+      groupId = groupId,
+      rebalanceTimeoutMs = 5 * 60 * 1000,
+      subscribedTopicNames = List("foo"),
+      topicPartitions = List.empty,
+      expectedError = Errors.GROUP_ID_NOT_FOUND
+    )
+    assertEquals("Group grp is not a consumer group.", 
responseData.errorMessage)
+
+    // The member leaves the group.
+    leaveGroup(
+      groupId = groupId,
+      memberId = memberId,
+      useNewProtocol = false,
+      version = ApiKeys.LEAVE_GROUP.latestVersion(isUnstableApiEnabled)
+    )
+
+    // Verify that the group is empty.
+    val listGroupsResponseData1 = listGroups(
+      statesFilter = List.empty,
+      typesFilter = List(Group.GroupType.CLASSIC.toString)
+    )
+
+    val expectedListResponse1 = List(new ListGroupsResponseData.ListedGroup()
+      .setGroupId(groupId)
+      .setProtocolType("consumer")
+      .setGroupState(ClassicGroupState.EMPTY.toString)
+      .setGroupType(Group.GroupType.CLASSIC.toString))
+
+    assertEquals(expectedListResponse1, listGroupsResponseData1)
+
+    // The joining request with a consumer group member is accepted.
+    consumerGroupHeartbeat(
+      groupId = groupId,
+      memberId = memberId,
+      rebalanceTimeoutMs = 5 * 60 * 1000,
+      subscribedTopicNames = List("foo"),
+      topicPartitions = List.empty,
+      expectedError = Errors.NONE
+    )
+
+    // The group has become a consumer group.
+    val listGroupsResponseData2 = listGroups(
+      statesFilter = List.empty,
+      typesFilter = List(Group.GroupType.CONSUMER.toString)
+    )
+
+    val expectedListResponse2 = List(new ListGroupsResponseData.ListedGroup()
+      .setGroupId(groupId)
+      .setProtocolType("consumer")
+      .setGroupState(ConsumerGroupState.STABLE.toString)
+      .setGroupType(Group.GroupType.CONSUMER.toString))
+
+    assertEquals(expectedListResponse2, listGroupsResponseData2)
+  }
+
+  @ClusterTest(serverProperties = Array(
+    new ClusterConfigProperty(key = "group.coordinator.new.enable", value = 
"true"),
+    new ClusterConfigProperty(key = "offsets.topic.num.partitions", value = 
"1"),
+    new ClusterConfigProperty(key = "offsets.topic.replication.factor", value 
= "1")
+  ))
+  def testOfflineDowngrade(): Unit = {
+    // Creates the __consumer_offsets topics because it won't be created 
automatically
+    // in this test because it does not use FindCoordinator API.
+    createOffsetsTopic()
+
+    // Create the topic.
+    createTopic(
+      topic = "foo",
+      numPartitions = 3
+    )
+
+    // Create a consumer group by joining a member.
+    val groupId = "grp"
+    val (memberId, _) = joinConsumerGroupWithNewProtocol(groupId)
+
+    // The joining request from a classic group member is rejected.
+    val joinGroupResponseData = sendJoinRequest(groupId = groupId)
+    assertEquals(Errors.GROUP_ID_NOT_FOUND.code, 
joinGroupResponseData.errorCode)
+
+    // The member leaves the group.
+    leaveGroup(
+      groupId = groupId,
+      memberId = memberId,
+      useNewProtocol = true,
+      version = 
ApiKeys.CONSUMER_GROUP_HEARTBEAT.latestVersion(isUnstableApiEnabled)
+    )
+
+    // Verify that the group is empty.
+    val listGroupsResponseData1 = listGroups(
+      statesFilter = List.empty,
+      typesFilter = List(Group.GroupType.CONSUMER.toString)
+    )
+
+    val expectedListResponse1 = List(new ListGroupsResponseData.ListedGroup()
+      .setGroupId(groupId)
+      .setProtocolType("consumer")
+      .setGroupState(ClassicGroupState.EMPTY.toString)
+      .setGroupType(Group.GroupType.CONSUMER.toString))
+
+    assertEquals(expectedListResponse1, listGroupsResponseData1)
+
+    // The joining request with a classic group member is accepted.
+    joinDynamicConsumerGroupWithOldProtocol(groupId = groupId)
+
+    // The group has become a classic group.
+    val listGroupsResponseData2 = listGroups(
+      statesFilter = List.empty,
+      typesFilter = List(Group.GroupType.CLASSIC.toString)
+    )
+
+    val expectedListResponse2 = List(new ListGroupsResponseData.ListedGroup()
+      .setGroupId(groupId)
+      .setProtocolType("consumer")
+      .setGroupState(ClassicGroupState.STABLE.toString)
+      .setGroupType(Group.GroupType.CLASSIC.toString))
+
+    assertEquals(expectedListResponse2, listGroupsResponseData2)

Review Comment:
   ditto.



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