dajac commented on code in PR #14656: URL: https://github.com/apache/kafka/pull/14656#discussion_r1395906098
########## core/src/test/scala/unit/kafka/server/HeartbeatRequestTest.scala: ########## @@ -0,0 +1,145 @@ +/** + * 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.protocol.{ApiKeys, Errors} +import org.junit.jupiter.api.{Tag, Timeout} +import org.junit.jupiter.api.extension.ExtendWith + +@Timeout(120) +@ExtendWith(value = Array(classOf[ClusterTestExtensions])) +@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1) +@Tag("integration") +class HeartbeatRequestTest(cluster: ClusterInstance) extends GroupCoordinatorBaseRequestTest(cluster) { + @ClusterTest(serverProperties = Array( + new ClusterConfigProperty(key = "unstable.api.versions.enable", value = "true"), + 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 testHeartbeatWithOldConsumerGroupProtocolAndNewGroupCoordinator(): Unit = { + testHeartbeat() + } + + @ClusterTest(clusterType = Type.ALL, serverProperties = Array( + new ClusterConfigProperty(key = "unstable.api.versions.enable", value = "false"), + new ClusterConfigProperty(key = "group.coordinator.new.enable", value = "false"), + new ClusterConfigProperty(key = "offsets.topic.num.partitions", value = "1"), + new ClusterConfigProperty(key = "offsets.topic.replication.factor", value = "1") + )) + def testHeartbeatWithOldConsumerGroupProtocolAndOldGroupCoordinator(): Unit = { + testHeartbeat() + } + + private def testHeartbeat(): 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 + ) + + for (version <- ApiKeys.HEARTBEAT.oldestVersion() to ApiKeys.HEARTBEAT.latestVersion(isUnstableApiEnabled)) { + Review Comment: nit: Let's remove this empty line. ########## core/src/test/scala/unit/kafka/server/HeartbeatRequestTest.scala: ########## @@ -0,0 +1,145 @@ +/** + * 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.protocol.{ApiKeys, Errors} +import org.junit.jupiter.api.{Tag, Timeout} +import org.junit.jupiter.api.extension.ExtendWith + +@Timeout(120) +@ExtendWith(value = Array(classOf[ClusterTestExtensions])) +@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1) +@Tag("integration") +class HeartbeatRequestTest(cluster: ClusterInstance) extends GroupCoordinatorBaseRequestTest(cluster) { + @ClusterTest(serverProperties = Array( + new ClusterConfigProperty(key = "unstable.api.versions.enable", value = "true"), Review Comment: nit: This is not required, I think. ########## core/src/test/scala/unit/kafka/server/HeartbeatRequestTest.scala: ########## @@ -0,0 +1,145 @@ +/** + * 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.protocol.{ApiKeys, Errors} +import org.junit.jupiter.api.{Tag, Timeout} +import org.junit.jupiter.api.extension.ExtendWith + +@Timeout(120) +@ExtendWith(value = Array(classOf[ClusterTestExtensions])) +@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1) +@Tag("integration") +class HeartbeatRequestTest(cluster: ClusterInstance) extends GroupCoordinatorBaseRequestTest(cluster) { + @ClusterTest(serverProperties = Array( + new ClusterConfigProperty(key = "unstable.api.versions.enable", value = "true"), + 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 testHeartbeatWithOldConsumerGroupProtocolAndNewGroupCoordinator(): Unit = { + testHeartbeat() + } + + @ClusterTest(clusterType = Type.ALL, serverProperties = Array( + new ClusterConfigProperty(key = "unstable.api.versions.enable", value = "false"), + new ClusterConfigProperty(key = "group.coordinator.new.enable", value = "false"), + new ClusterConfigProperty(key = "offsets.topic.num.partitions", value = "1"), + new ClusterConfigProperty(key = "offsets.topic.replication.factor", value = "1") + )) + def testHeartbeatWithOldConsumerGroupProtocolAndOldGroupCoordinator(): Unit = { + testHeartbeat() + } + + private def testHeartbeat(): Unit = { + Review Comment: nit: Let's remove this empty line. ########## core/src/test/scala/unit/kafka/server/LeaveGroupRequestTest.scala: ########## @@ -0,0 +1,141 @@ +/** + * 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.protocol.{ApiKeys, Errors} +import org.apache.kafka.common.requests.JoinGroupRequest +import org.junit.jupiter.api.{Tag, Timeout} +import org.junit.jupiter.api.extension.ExtendWith + +@Timeout(120) +@ExtendWith(value = Array(classOf[ClusterTestExtensions])) +@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1) +@Tag("integration") +class LeaveGroupRequestTest(cluster: ClusterInstance) extends GroupCoordinatorBaseRequestTest(cluster) { + @ClusterTest(serverProperties = Array( + new ClusterConfigProperty(key = "unstable.api.versions.enable", value = "true"), Review Comment: nit: This is not required, I think. ########## core/src/test/scala/unit/kafka/server/HeartbeatRequestTest.scala: ########## @@ -0,0 +1,145 @@ +/** + * 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.protocol.{ApiKeys, Errors} +import org.junit.jupiter.api.{Tag, Timeout} +import org.junit.jupiter.api.extension.ExtendWith + +@Timeout(120) +@ExtendWith(value = Array(classOf[ClusterTestExtensions])) +@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1) +@Tag("integration") +class HeartbeatRequestTest(cluster: ClusterInstance) extends GroupCoordinatorBaseRequestTest(cluster) { + @ClusterTest(serverProperties = Array( + new ClusterConfigProperty(key = "unstable.api.versions.enable", value = "true"), + 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 testHeartbeatWithOldConsumerGroupProtocolAndNewGroupCoordinator(): Unit = { + testHeartbeat() + } + + @ClusterTest(clusterType = Type.ALL, serverProperties = Array( + new ClusterConfigProperty(key = "unstable.api.versions.enable", value = "false"), + new ClusterConfigProperty(key = "group.coordinator.new.enable", value = "false"), + new ClusterConfigProperty(key = "offsets.topic.num.partitions", value = "1"), + new ClusterConfigProperty(key = "offsets.topic.replication.factor", value = "1") + )) + def testHeartbeatWithOldConsumerGroupProtocolAndOldGroupCoordinator(): Unit = { + testHeartbeat() + } + + private def testHeartbeat(): 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 + ) + + for (version <- ApiKeys.HEARTBEAT.oldestVersion() to ApiKeys.HEARTBEAT.latestVersion(isUnstableApiEnabled)) { + + val (memberId, memberEpoch) = joinDynamicConsumerGroupWithOldProtocol( + groupId = "grp", + completeRebalance = false + ) + + // Heartbeat with unknown group id and unknown member id. + heartbeat( + groupId = "grp-unknown", + memberId = "member-id-unknown", + generationId = -1, + expectedError = Errors.UNKNOWN_MEMBER_ID, + version = version.toShort + ) + + // Heartbeat with unknown group id. + heartbeat( + groupId = "grp-unknown", + memberId = memberId, + generationId = -1, + expectedError = Errors.UNKNOWN_MEMBER_ID, + version = version.toShort + ) + + // Heartbeat with unknown member id. + heartbeat( + groupId = "grp", + memberId = "member-id-unknown", + generationId = -1, + expectedError = Errors.UNKNOWN_MEMBER_ID, + version = version.toShort + ) + + // Heartbeat with unmatched generation id. + heartbeat( + groupId = "grp", + memberId = memberId, + generationId = -1, + expectedError = Errors.ILLEGAL_GENERATION, + version = version.toShort + ) + + // Heartbeat COMPLETING_REBALANCE group. + heartbeat( + groupId = "grp", + memberId = memberId, + generationId = memberEpoch, + version = version.toShort + ) + + syncGroupWithOldProtocol( + groupId = "grp", + memberId = memberId, + generationId = memberEpoch + ) + + // Heartbeat STABLE group. + heartbeat( + groupId = "grp", + memberId = memberId, + generationId = memberEpoch, + version = version.toShort + ) + + leaveGroup( + groupId = "grp", + memberId = memberId, + useNewProtocol = false, + version = ApiKeys.LEAVE_GROUP.latestVersion(isUnstableApiEnabled) + ) + + // Heartbeat empty group. + heartbeat( + groupId = "grp", + memberId = memberId, + generationId = -1, + expectedError = Errors.UNKNOWN_MEMBER_ID, + version = version.toShort + ) + } Review Comment: Have you considered adding one while in PREPARING_REBALANCE state in order to verify that we get the REBALANCE_IN_PROGRESS error? ########## core/src/test/scala/unit/kafka/server/LeaveGroupRequestTest.scala: ########## @@ -0,0 +1,141 @@ +/** + * 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.protocol.{ApiKeys, Errors} +import org.apache.kafka.common.requests.JoinGroupRequest +import org.junit.jupiter.api.{Tag, Timeout} +import org.junit.jupiter.api.extension.ExtendWith + +@Timeout(120) +@ExtendWith(value = Array(classOf[ClusterTestExtensions])) +@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1) +@Tag("integration") +class LeaveGroupRequestTest(cluster: ClusterInstance) extends GroupCoordinatorBaseRequestTest(cluster) { + @ClusterTest(serverProperties = Array( + new ClusterConfigProperty(key = "unstable.api.versions.enable", value = "true"), + 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 testLeaveGroupWithOldConsumerGroupProtocolAndNewGroupCoordinator(): Unit = { + testLeaveGroup() + } + + @ClusterTest(clusterType = Type.ALL, serverProperties = Array( + new ClusterConfigProperty(key = "unstable.api.versions.enable", value = "false"), + new ClusterConfigProperty(key = "group.coordinator.new.enable", value = "false"), + new ClusterConfigProperty(key = "offsets.topic.num.partitions", value = "1"), + new ClusterConfigProperty(key = "offsets.topic.replication.factor", value = "1") + )) + def testLeaveGroupWithOldConsumerGroupProtocolAndOldGroupCoordinator(): Unit = { + testLeaveGroup() + } + + private def testLeaveGroup(): Unit = { + Review Comment: nit: Let's remove this empty line. ########## core/src/test/scala/unit/kafka/server/LeaveGroupRequestTest.scala: ########## @@ -0,0 +1,141 @@ +/** + * 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.protocol.{ApiKeys, Errors} +import org.apache.kafka.common.requests.JoinGroupRequest +import org.junit.jupiter.api.{Tag, Timeout} +import org.junit.jupiter.api.extension.ExtendWith + +@Timeout(120) +@ExtendWith(value = Array(classOf[ClusterTestExtensions])) +@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1) +@Tag("integration") +class LeaveGroupRequestTest(cluster: ClusterInstance) extends GroupCoordinatorBaseRequestTest(cluster) { + @ClusterTest(serverProperties = Array( + new ClusterConfigProperty(key = "unstable.api.versions.enable", value = "true"), + 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 testLeaveGroupWithOldConsumerGroupProtocolAndNewGroupCoordinator(): Unit = { + testLeaveGroup() + } + + @ClusterTest(clusterType = Type.ALL, serverProperties = Array( + new ClusterConfigProperty(key = "unstable.api.versions.enable", value = "false"), + new ClusterConfigProperty(key = "group.coordinator.new.enable", value = "false"), + new ClusterConfigProperty(key = "offsets.topic.num.partitions", value = "1"), + new ClusterConfigProperty(key = "offsets.topic.replication.factor", value = "1") + )) + def testLeaveGroupWithOldConsumerGroupProtocolAndOldGroupCoordinator(): Unit = { + testLeaveGroup() + } + + private def testLeaveGroup(): 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 + ) + + for (version <- ApiKeys.LEAVE_GROUP.oldestVersion() to ApiKeys.LEAVE_GROUP.latestVersion(isUnstableApiEnabled)) { + Review Comment: ditto. ########## core/src/test/scala/unit/kafka/server/GroupCoordinatorBaseRequestTest.scala: ########## @@ -369,6 +411,26 @@ class GroupCoordinatorBaseRequestTest(cluster: ClusterInstance) { describeGroupsResponse.data.groups.asScala.toList } + protected def heartbeat( + groupId: String, + generationId: Int, + memberId: String, + groupInstanceId: String = null, + expectedError: Errors = Errors.NONE, + version: Short + ): Unit = { + val heartbeatRequest = new HeartbeatRequest.Builder( + new HeartbeatRequestData() + .setGroupId(groupId) + .setGenerationId(generationId) + .setMemberId(memberId) + .setGroupInstanceId(groupInstanceId) + ).build(version) + + val heartbeatResponse = connectAndReceive[HeartbeatResponse](heartbeatRequest) + assertEquals(expectedError.code(), heartbeatResponse.data().errorCode()) Review Comment: nit: You can remove some `()` here and there. I let you double check them. ########## core/src/test/scala/unit/kafka/server/LeaveGroupRequestTest.scala: ########## @@ -0,0 +1,141 @@ +/** + * 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.protocol.{ApiKeys, Errors} +import org.apache.kafka.common.requests.JoinGroupRequest +import org.junit.jupiter.api.{Tag, Timeout} +import org.junit.jupiter.api.extension.ExtendWith + +@Timeout(120) +@ExtendWith(value = Array(classOf[ClusterTestExtensions])) +@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1) +@Tag("integration") +class LeaveGroupRequestTest(cluster: ClusterInstance) extends GroupCoordinatorBaseRequestTest(cluster) { + @ClusterTest(serverProperties = Array( + new ClusterConfigProperty(key = "unstable.api.versions.enable", value = "true"), + 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 testLeaveGroupWithOldConsumerGroupProtocolAndNewGroupCoordinator(): Unit = { + testLeaveGroup() + } + + @ClusterTest(clusterType = Type.ALL, serverProperties = Array( + new ClusterConfigProperty(key = "unstable.api.versions.enable", value = "false"), + new ClusterConfigProperty(key = "group.coordinator.new.enable", value = "false"), + new ClusterConfigProperty(key = "offsets.topic.num.partitions", value = "1"), + new ClusterConfigProperty(key = "offsets.topic.replication.factor", value = "1") + )) + def testLeaveGroupWithOldConsumerGroupProtocolAndOldGroupCoordinator(): Unit = { + testLeaveGroup() + } + + private def testLeaveGroup(): 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 + ) + + for (version <- ApiKeys.LEAVE_GROUP.oldestVersion() to ApiKeys.LEAVE_GROUP.latestVersion(isUnstableApiEnabled)) { + + // Join the consumer group. Note that we don't heartbeat here so we must use + // a session long enough for the duration of the test. + val (memberId1, _) = joinDynamicConsumerGroupWithOldProtocol("grp-1") + if (version >= 3) { + joinStaticConsumerGroupWithOldProtocol("grp-2", "group-instance-id") + } + + // Request with empty group id. + leaveGroupWithOldProtocol( + groupId = "", + memberIds = List(memberId1), + expectedLeaveGroupError = Errors.INVALID_GROUP_ID, + expectedMemberErrors = List(Errors.NONE), + version = version.toShort + ) + + // Request with invalid group id and unknown member id should still get Errors.INVALID_GROUP_ID. + leaveGroupWithOldProtocol( + groupId = "", + memberIds = List("member-id-unknown"), + expectedLeaveGroupError = Errors.INVALID_GROUP_ID, + expectedMemberErrors = List(Errors.NONE), + version = version.toShort + ) + + // Request with unknown group id gets Errors.UNKNOWN_MEMBER_ID. + leaveGroupWithOldProtocol( + groupId = "grp-unknown", + memberIds = List(memberId1), + expectedLeaveGroupError = if (version >= 3) Errors.NONE else Errors.UNKNOWN_MEMBER_ID, + expectedMemberErrors = if (version >= 3) List(Errors.UNKNOWN_MEMBER_ID) else List.empty, + version = version.toShort + ) + + // Request with unknown member ids. + leaveGroupWithOldProtocol( + groupId = "grp-1", + memberIds = if (version >= 3) List("unknown-member-id", JoinGroupRequest.UNKNOWN_MEMBER_ID) else List("unknown-member-id"), + expectedLeaveGroupError = if (version >= 3) Errors.NONE else Errors.UNKNOWN_MEMBER_ID, + expectedMemberErrors = if (version >= 3) List(Errors.UNKNOWN_MEMBER_ID, Errors.UNKNOWN_MEMBER_ID) else List.empty, + version = version.toShort + ) + + // Success GroupLeave request. + leaveGroupWithOldProtocol( + groupId = "grp-1", + memberIds = if (version >= 3) List(memberId1) else List(memberId1), + expectedLeaveGroupError = Errors.NONE, + expectedMemberErrors = if (version >= 3) List(Errors.NONE) else List.empty, + version = version.toShort + ) + + if (version >= 3) { + // Request with fenced group instance id. + leaveGroupWithOldProtocol( + groupId = "grp-2", + memberIds = List("member-id-fenced"), + groupInstanceId = "group-instance-id", + expectedLeaveGroupError = Errors.NONE, + expectedMemberErrors = List(Errors.FENCED_INSTANCE_ID), + version = version.toShort + ) + + // Having unknown member id will not affect the request processing. + leaveGroupWithOldProtocol( + groupId = "grp-2", + memberIds = List(JoinGroupRequest.UNKNOWN_MEMBER_ID), + groupInstanceId = "group-instance-id", + expectedLeaveGroupError = Errors.NONE, + expectedMemberErrors = List(Errors.NONE), + version = version.toShort + ) Review Comment: Should we check that the group is empty after this as well? ########## core/src/test/scala/unit/kafka/server/GroupCoordinatorBaseRequestTest.scala: ########## @@ -421,26 +483,31 @@ class GroupCoordinatorBaseRequestTest(cluster: ClusterInstance) { protected def leaveGroupWithOldProtocol( groupId: String, memberIds: List[String], + groupInstanceId: String = null, expectedLeaveGroupError: Errors, - expectedMemberErrors: List[Errors] + expectedMemberErrors: List[Errors], + version: Short ): Unit = { - if (memberIds.size != expectedMemberErrors.size) { - fail("genericGroupLeave: memberIds and expectedMemberErrors have unmatched sizes.") - } - val leaveGroupRequest = new LeaveGroupRequest.Builder( groupId, - memberIds.map(memberId => new MemberIdentity().setMemberId(memberId)).asJava - ).build() + memberIds.map(memberId => new MemberIdentity() + .setMemberId(memberId) + .setGroupInstanceId(groupInstanceId) Review Comment: This is weird because the group instance id is supposed to be unique for each member. ########## core/src/test/scala/unit/kafka/server/LeaveGroupRequestTest.scala: ########## @@ -0,0 +1,141 @@ +/** + * 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.protocol.{ApiKeys, Errors} +import org.apache.kafka.common.requests.JoinGroupRequest +import org.junit.jupiter.api.{Tag, Timeout} +import org.junit.jupiter.api.extension.ExtendWith + +@Timeout(120) +@ExtendWith(value = Array(classOf[ClusterTestExtensions])) +@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1) +@Tag("integration") +class LeaveGroupRequestTest(cluster: ClusterInstance) extends GroupCoordinatorBaseRequestTest(cluster) { + @ClusterTest(serverProperties = Array( + new ClusterConfigProperty(key = "unstable.api.versions.enable", value = "true"), + 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 testLeaveGroupWithOldConsumerGroupProtocolAndNewGroupCoordinator(): Unit = { + testLeaveGroup() + } + + @ClusterTest(clusterType = Type.ALL, serverProperties = Array( + new ClusterConfigProperty(key = "unstable.api.versions.enable", value = "false"), + new ClusterConfigProperty(key = "group.coordinator.new.enable", value = "false"), + new ClusterConfigProperty(key = "offsets.topic.num.partitions", value = "1"), + new ClusterConfigProperty(key = "offsets.topic.replication.factor", value = "1") + )) + def testLeaveGroupWithOldConsumerGroupProtocolAndOldGroupCoordinator(): Unit = { + testLeaveGroup() + } + + private def testLeaveGroup(): 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 + ) + + for (version <- ApiKeys.LEAVE_GROUP.oldestVersion() to ApiKeys.LEAVE_GROUP.latestVersion(isUnstableApiEnabled)) { + + // Join the consumer group. Note that we don't heartbeat here so we must use + // a session long enough for the duration of the test. + val (memberId1, _) = joinDynamicConsumerGroupWithOldProtocol("grp-1") + if (version >= 3) { + joinStaticConsumerGroupWithOldProtocol("grp-2", "group-instance-id") + } + + // Request with empty group id. + leaveGroupWithOldProtocol( + groupId = "", + memberIds = List(memberId1), + expectedLeaveGroupError = Errors.INVALID_GROUP_ID, + expectedMemberErrors = List(Errors.NONE), + version = version.toShort + ) + + // Request with invalid group id and unknown member id should still get Errors.INVALID_GROUP_ID. + leaveGroupWithOldProtocol( + groupId = "", + memberIds = List("member-id-unknown"), + expectedLeaveGroupError = Errors.INVALID_GROUP_ID, + expectedMemberErrors = List(Errors.NONE), + version = version.toShort + ) + + // Request with unknown group id gets Errors.UNKNOWN_MEMBER_ID. + leaveGroupWithOldProtocol( + groupId = "grp-unknown", + memberIds = List(memberId1), + expectedLeaveGroupError = if (version >= 3) Errors.NONE else Errors.UNKNOWN_MEMBER_ID, + expectedMemberErrors = if (version >= 3) List(Errors.UNKNOWN_MEMBER_ID) else List.empty, + version = version.toShort + ) + + // Request with unknown member ids. + leaveGroupWithOldProtocol( + groupId = "grp-1", + memberIds = if (version >= 3) List("unknown-member-id", JoinGroupRequest.UNKNOWN_MEMBER_ID) else List("unknown-member-id"), + expectedLeaveGroupError = if (version >= 3) Errors.NONE else Errors.UNKNOWN_MEMBER_ID, + expectedMemberErrors = if (version >= 3) List(Errors.UNKNOWN_MEMBER_ID, Errors.UNKNOWN_MEMBER_ID) else List.empty, + version = version.toShort + ) + + // Success GroupLeave request. + leaveGroupWithOldProtocol( + groupId = "grp-1", + memberIds = if (version >= 3) List(memberId1) else List(memberId1), + expectedLeaveGroupError = Errors.NONE, + expectedMemberErrors = if (version >= 3) List(Errors.NONE) else List.empty, + version = version.toShort + ) Review Comment: Should we check that the group is actually empty after this? ########## core/src/test/scala/unit/kafka/server/LeaveGroupRequestTest.scala: ########## @@ -0,0 +1,141 @@ +/** + * 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.protocol.{ApiKeys, Errors} +import org.apache.kafka.common.requests.JoinGroupRequest +import org.junit.jupiter.api.{Tag, Timeout} +import org.junit.jupiter.api.extension.ExtendWith + +@Timeout(120) +@ExtendWith(value = Array(classOf[ClusterTestExtensions])) +@ClusterTestDefaults(clusterType = Type.KRAFT, brokers = 1) +@Tag("integration") +class LeaveGroupRequestTest(cluster: ClusterInstance) extends GroupCoordinatorBaseRequestTest(cluster) { + @ClusterTest(serverProperties = Array( + new ClusterConfigProperty(key = "unstable.api.versions.enable", value = "true"), + 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 testLeaveGroupWithOldConsumerGroupProtocolAndNewGroupCoordinator(): Unit = { + testLeaveGroup() + } + + @ClusterTest(clusterType = Type.ALL, serverProperties = Array( + new ClusterConfigProperty(key = "unstable.api.versions.enable", value = "false"), + new ClusterConfigProperty(key = "group.coordinator.new.enable", value = "false"), + new ClusterConfigProperty(key = "offsets.topic.num.partitions", value = "1"), + new ClusterConfigProperty(key = "offsets.topic.replication.factor", value = "1") + )) + def testLeaveGroupWithOldConsumerGroupProtocolAndOldGroupCoordinator(): Unit = { + testLeaveGroup() + } + + private def testLeaveGroup(): 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 + ) + + for (version <- ApiKeys.LEAVE_GROUP.oldestVersion() to ApiKeys.LEAVE_GROUP.latestVersion(isUnstableApiEnabled)) { + + // Join the consumer group. Note that we don't heartbeat here so we must use + // a session long enough for the duration of the test. + val (memberId1, _) = joinDynamicConsumerGroupWithOldProtocol("grp-1") + if (version >= 3) { + joinStaticConsumerGroupWithOldProtocol("grp-2", "group-instance-id") + } + + // Request with empty group id. + leaveGroupWithOldProtocol( + groupId = "", + memberIds = List(memberId1), + expectedLeaveGroupError = Errors.INVALID_GROUP_ID, + expectedMemberErrors = List(Errors.NONE), + version = version.toShort + ) + + // Request with invalid group id and unknown member id should still get Errors.INVALID_GROUP_ID. + leaveGroupWithOldProtocol( + groupId = "", + memberIds = List("member-id-unknown"), + expectedLeaveGroupError = Errors.INVALID_GROUP_ID, + expectedMemberErrors = List(Errors.NONE), + version = version.toShort + ) + + // Request with unknown group id gets Errors.UNKNOWN_MEMBER_ID. + leaveGroupWithOldProtocol( + groupId = "grp-unknown", + memberIds = List(memberId1), + expectedLeaveGroupError = if (version >= 3) Errors.NONE else Errors.UNKNOWN_MEMBER_ID, + expectedMemberErrors = if (version >= 3) List(Errors.UNKNOWN_MEMBER_ID) else List.empty, + version = version.toShort + ) + + // Request with unknown member ids. + leaveGroupWithOldProtocol( + groupId = "grp-1", + memberIds = if (version >= 3) List("unknown-member-id", JoinGroupRequest.UNKNOWN_MEMBER_ID) else List("unknown-member-id"), + expectedLeaveGroupError = if (version >= 3) Errors.NONE else Errors.UNKNOWN_MEMBER_ID, + expectedMemberErrors = if (version >= 3) List(Errors.UNKNOWN_MEMBER_ID, Errors.UNKNOWN_MEMBER_ID) else List.empty, + version = version.toShort + ) + + // Success GroupLeave request. + leaveGroupWithOldProtocol( + groupId = "grp-1", + memberIds = if (version >= 3) List(memberId1) else List(memberId1), Review Comment: I don't get this one. I suppose that we could just remove the version check, isn't it? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
