You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "dongnuo123 (via GitHub)" <gi...@apache.org> on 2024/03/07 21:37:11 UTC

[PR] KAFKA-16353: Offline protocol migration integration tests [kafka]

dongnuo123 opened a new pull request, #15492:
URL: https://github.com/apache/kafka/pull/15492

   This patch adds integration tests for offline protocol migration.
   
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   


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


Re: [PR] KAFKA-16353: Offline protocol migration integration tests [kafka]

Posted by "dajac (via GitHub)" <gi...@apache.org>.
dajac commented on code in PR #15492:
URL: https://github.com/apache/kafka/pull/15492#discussion_r1539495661


##########
core/src/test/scala/unit/kafka/server/GroupCoordinatorBaseRequestTest.scala:
##########
@@ -82,7 +83,7 @@ class GroupCoordinatorBaseRequestTest(cluster: ClusterInstance) {
 
     TestUtils.waitUntilTrue(() => {
       resultFuture.isDone && !resultFuture.isCancelled && !resultFuture.isCompletedExceptionally
-    }, msg = s"Could not commit the offsets successfully. Last response ${resultFuture.get()}.")
+    }, msg = s"Could not commit the offsets successfully. Last response ${resultFuture.get(0, TimeUnit.MILLISECONDS)}.")
   }

Review Comment:
   Sorry. I meant that you could replace this entire code by `resultFuture.get(JTestUtils.DEFAULT_MAX_WAIT_MS, TimeUnit.SECONDS)`.



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


Re: [PR] KAFKA-16353: Offline protocol migration integration tests [kafka]

Posted by "dajac (via GitHub)" <gi...@apache.org>.
dajac commented on code in PR #15492:
URL: https://github.com/apache/kafka/pull/15492#discussion_r1539493833


##########
core/src/test/scala/unit/kafka/server/GroupCoordinatorBaseRequestTest.scala:
##########
@@ -73,6 +74,17 @@ class GroupCoordinatorBaseRequestTest(cluster: ClusterInstance) {
     )
   }
 
+  protected def alterConsumerGroupOffsets(
+    groupId: String,
+    offsets: Map[TopicPartition, OffsetAndMetadata]
+  ): Unit = {
+    val resultFuture = cluster.createAdminClient().alterConsumerGroupOffsets(groupId, offsets.asJava).all
+
+    TestUtils.waitUntilTrue(() => {
+      resultFuture.isDone && !resultFuture.isCancelled && !resultFuture.isCompletedExceptionally
+    }, msg = s"Could not commit the offsets successfully. Last response ${resultFuture.get()}.")

Review Comment:
   Hum... `.get` will throw the exception if the future is completed exceptionally or timed out. It should be enough, no?



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


Re: [PR] KAFKA-16353: Offline protocol migration integration tests [kafka]

Posted by "dajac (via GitHub)" <gi...@apache.org>.
dajac merged PR #15492:
URL: https://github.com/apache/kafka/pull/15492


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


Re: [PR] KAFKA-16353: Offline protocol migration integration tests [kafka]

Posted by "dongnuo123 (via GitHub)" <gi...@apache.org>.
dongnuo123 commented on code in PR #15492:
URL: https://github.com/apache/kafka/pull/15492#discussion_r1539521510


##########
core/src/test/scala/unit/kafka/server/GroupCoordinatorBaseRequestTest.scala:
##########
@@ -82,7 +83,7 @@ class GroupCoordinatorBaseRequestTest(cluster: ClusterInstance) {
 
     TestUtils.waitUntilTrue(() => {
       resultFuture.isDone && !resultFuture.isCancelled && !resultFuture.isCompletedExceptionally
-    }, msg = s"Could not commit the offsets successfully. Last response ${resultFuture.get()}.")
+    }, msg = s"Could not commit the offsets successfully. Last response ${resultFuture.get(0, TimeUnit.MILLISECONDS)}.")
   }

Review Comment:
   Yeah I didn't realize that. Just changed to use `commitOffset`



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


Re: [PR] KAFKA-16353: Offline protocol migration integration tests [kafka]

Posted by "dongnuo123 (via GitHub)" <gi...@apache.org>.
dongnuo123 commented on code in PR #15492:
URL: https://github.com/apache/kafka/pull/15492#discussion_r1539481450


##########
core/src/test/scala/unit/kafka/server/GroupCoordinatorBaseRequestTest.scala:
##########
@@ -73,6 +74,17 @@ class GroupCoordinatorBaseRequestTest(cluster: ClusterInstance) {
     )
   }
 
+  protected def alterConsumerGroupOffsets(
+    groupId: String,
+    offsets: Map[TopicPartition, OffsetAndMetadata]
+  ): Unit = {
+    val resultFuture = cluster.createAdminClient().alterConsumerGroupOffsets(groupId, offsets.asJava).all
+
+    TestUtils.waitUntilTrue(() => {
+      resultFuture.isDone && !resultFuture.isCancelled && !resultFuture.isCompletedExceptionally
+    }, msg = s"Could not commit the offsets successfully. Last response ${resultFuture.get()}.")

Review Comment:
   Oh yes, you are right. Let me change this



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


Re: [PR] KAFKA-16353: Offline protocol migration integration tests [kafka]

Posted by "dajac (via GitHub)" <gi...@apache.org>.
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-unsubscribe@kafka.apache.org

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


Re: [PR] KAFKA-16353: Offline protocol migration integration tests [kafka]

Posted by "dongnuo123 (via GitHub)" <gi...@apache.org>.
dongnuo123 commented on code in PR #15492:
URL: https://github.com/apache/kafka/pull/15492#discussion_r1539503171


##########
core/src/test/scala/unit/kafka/server/GroupCoordinatorBaseRequestTest.scala:
##########
@@ -73,6 +74,17 @@ class GroupCoordinatorBaseRequestTest(cluster: ClusterInstance) {
     )
   }
 
+  protected def alterConsumerGroupOffsets(
+    groupId: String,
+    offsets: Map[TopicPartition, OffsetAndMetadata]
+  ): Unit = {
+    val resultFuture = cluster.createAdminClient().alterConsumerGroupOffsets(groupId, offsets.asJava).all
+
+    TestUtils.waitUntilTrue(() => {
+      resultFuture.isDone && !resultFuture.isCancelled && !resultFuture.isCompletedExceptionally
+    }, msg = s"Could not commit the offsets successfully. Last response ${resultFuture.get()}.")

Review Comment:
   Ok let me remove the wait until true..



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


Re: [PR] KAFKA-16353: Offline protocol migration integration tests [kafka]

Posted by "dajac (via GitHub)" <gi...@apache.org>.
dajac commented on code in PR #15492:
URL: https://github.com/apache/kafka/pull/15492#discussion_r1539500107


##########
core/src/test/scala/unit/kafka/server/GroupCoordinatorBaseRequestTest.scala:
##########
@@ -82,7 +83,7 @@ class GroupCoordinatorBaseRequestTest(cluster: ClusterInstance) {
 
     TestUtils.waitUntilTrue(() => {
       resultFuture.isDone && !resultFuture.isCancelled && !resultFuture.isCompletedExceptionally
-    }, msg = s"Could not commit the offsets successfully. Last response ${resultFuture.get()}.")
+    }, msg = s"Could not commit the offsets successfully. Last response ${resultFuture.get(0, TimeUnit.MILLISECONDS)}.")
   }

Review Comment:
   Another question, could we use `commitOffset` method?



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


Re: [PR] KAFKA-16353: Offline protocol migration integration tests [kafka]

Posted by "dajac (via GitHub)" <gi...@apache.org>.
dajac commented on code in PR #15492:
URL: https://github.com/apache/kafka/pull/15492#discussion_r1539453693


##########
core/src/test/scala/unit/kafka/server/GroupCoordinatorBaseRequestTest.scala:
##########
@@ -73,6 +74,17 @@ class GroupCoordinatorBaseRequestTest(cluster: ClusterInstance) {
     )
   }
 
+  protected def alterConsumerGroupOffsets(
+    groupId: String,
+    offsets: Map[TopicPartition, OffsetAndMetadata]
+  ): Unit = {
+    val resultFuture = cluster.createAdminClient().alterConsumerGroupOffsets(groupId, offsets.asJava).all
+
+    TestUtils.waitUntilTrue(() => {
+      resultFuture.isDone && !resultFuture.isCancelled && !resultFuture.isCompletedExceptionally
+    }, msg = s"Could not commit the offsets successfully. Last response ${resultFuture.get()}.")

Review Comment:
   This is a bit weird. Is there a reason not to use `resultFuture.get()` with a timeout?



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


Re: [PR] KAFKA-16353: Offline protocol migration integration tests [kafka]

Posted by "dongnuo123 (via GitHub)" <gi...@apache.org>.
dongnuo123 commented on code in PR #15492:
URL: https://github.com/apache/kafka/pull/15492#discussion_r1539484746


##########
core/src/test/scala/unit/kafka/server/GroupCoordinatorBaseRequestTest.scala:
##########
@@ -73,6 +74,17 @@ class GroupCoordinatorBaseRequestTest(cluster: ClusterInstance) {
     )
   }
 
+  protected def alterConsumerGroupOffsets(
+    groupId: String,
+    offsets: Map[TopicPartition, OffsetAndMetadata]
+  ): Unit = {
+    val resultFuture = cluster.createAdminClient().alterConsumerGroupOffsets(groupId, offsets.asJava).all
+
+    TestUtils.waitUntilTrue(() => {
+      resultFuture.isDone && !resultFuture.isCancelled && !resultFuture.isCompletedExceptionally
+    }, msg = s"Could not commit the offsets successfully. Last response ${resultFuture.get()}.")

Review Comment:
   I was wondering how to get the error message from the future 🤔



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