frankvicky commented on code in PR #23747:
URL: https://github.com/apache/kafka/pull/23747#discussion_r4221275840


##########
core/src/test/scala/unit/kafka/server/StreamsGroupTopologyDescriptionRequestTest.scala:
##########
@@ -592,6 +593,161 @@ class StreamsGroupTopologyDescriptionRequestTest(cluster: 
ClusterInstance) exten
     }
   }
 
+  @ClusterTest(serverProperties = Array(
+    new ClusterConfigProperty(
+      key = 
GroupCoordinatorConfig.STREAMS_GROUP_TOPOLOGY_DESCRIPTION_PLUGIN_CLASS_CONFIG,
+      value = "kafka.server.FailingTopologyDescriptionPlugin"),
+    // Keeps the periodic cleanup cycle from also deleting the topology while 
the test runs.
+    new ClusterConfigProperty(key = 
GroupCoordinatorConfig.OFFSETS_RETENTION_CHECK_INTERVAL_MS_CONFIG, value = 
"3600000")
+  ))
+  def testClassicJoinDeletesStoredTopologyAndConvertsEmptyStreamsGroup(): Unit 
= {
+    val admin = cluster.admin()
+    val groupId = "test-group"
+    val topicName = "test-topic"
+
+    try {
+      FailingTopologyDescriptionPlugin.reset()
+      createEmptyStreamsGroupWithStoredTopology(admin, groupId, topicName)
+
+      assertEquals(Errors.NONE.code(), classicJoin(groupId).errorCode())
+      assertEquals(1, 
FailingTopologyDescriptionPlugin.deleteTopologyAttempts(groupId))
+      assertEquals(Errors.GROUP_ID_NOT_FOUND.code(), 
streamsGroupDescribe(List(groupId)).head.errorCode())
+      assertEquals("consumer", 
describeGroups(List(groupId)).head.protocolType())

Review Comment:
   nit:
   `describeGroups` only resolves classic groups (`classicGroup(groupId, ...)` 
throws `GroupIdNotFoundException` for every other group type), so the 
`protocolType == "consumer"` check implicitly relies on the describe 
succeeding. 
   Asserting `errorCode == NONE` first makes the "it is now a classic group" 
intent explicit.
   WDYT?



##########
core/src/test/scala/unit/kafka/server/StreamsGroupTopologyDescriptionRequestTest.scala:
##########
@@ -592,6 +593,161 @@ class StreamsGroupTopologyDescriptionRequestTest(cluster: 
ClusterInstance) exten
     }
   }
 
+  @ClusterTest(serverProperties = Array(
+    new ClusterConfigProperty(
+      key = 
GroupCoordinatorConfig.STREAMS_GROUP_TOPOLOGY_DESCRIPTION_PLUGIN_CLASS_CONFIG,
+      value = "kafka.server.FailingTopologyDescriptionPlugin"),
+    // Keeps the periodic cleanup cycle from also deleting the topology while 
the test runs.
+    new ClusterConfigProperty(key = 
GroupCoordinatorConfig.OFFSETS_RETENTION_CHECK_INTERVAL_MS_CONFIG, value = 
"3600000")
+  ))
+  def testClassicJoinDeletesStoredTopologyAndConvertsEmptyStreamsGroup(): Unit 
= {
+    val admin = cluster.admin()
+    val groupId = "test-group"
+    val topicName = "test-topic"
+
+    try {
+      FailingTopologyDescriptionPlugin.reset()
+      createEmptyStreamsGroupWithStoredTopology(admin, groupId, topicName)
+
+      assertEquals(Errors.NONE.code(), classicJoin(groupId).errorCode())
+      assertEquals(1, 
FailingTopologyDescriptionPlugin.deleteTopologyAttempts(groupId))
+      assertEquals(Errors.GROUP_ID_NOT_FOUND.code(), 
streamsGroupDescribe(List(groupId)).head.errorCode())
+      assertEquals("consumer", 
describeGroups(List(groupId)).head.protocolType())
+    } finally {
+      FailingTopologyDescriptionPlugin.reset()
+      admin.close()
+    }
+  }
+
+  @ClusterTest(serverProperties = Array(
+    new ClusterConfigProperty(
+      key = 
GroupCoordinatorConfig.STREAMS_GROUP_TOPOLOGY_DESCRIPTION_PLUGIN_CLASS_CONFIG,
+      value = "kafka.server.FailingTopologyDescriptionPlugin")
+  ))
+  def testClassicJoinIsRejectedRetriablyWhenPluginDeleteFails(): Unit = {
+    val admin = cluster.admin()
+    val groupId = "test-group"
+    val topicName = "test-topic"
+
+    try {
+      FailingTopologyDescriptionPlugin.reset()
+      createEmptyStreamsGroupWithStoredTopology(admin, groupId, topicName)
+
+      FailingTopologyDescriptionPlugin.failDeleteTopologyWith(new 
RuntimeException("plugin offline"))
+      assertEquals(Errors.REBALANCE_IN_PROGRESS.code(), 
classicJoin(groupId).errorCode())
+      assertEquals(1, 
FailingTopologyDescriptionPlugin.deleteTopologyAttempts(groupId))
+      assertStillStreamsGroup(groupId)
+    } finally {
+      FailingTopologyDescriptionPlugin.reset()
+      admin.close()
+    }
+  }
+
+  @Timeout(120)
+  @ClusterTest(serverProperties = Array(
+    new ClusterConfigProperty(
+      key = 
GroupCoordinatorConfig.STREAMS_GROUP_TOPOLOGY_DESCRIPTION_PLUGIN_CLASS_CONFIG,
+      value = "kafka.server.FailingTopologyDescriptionPlugin"),
+    // Drives the periodic topology cleanup cycle, which runs on the offsets 
retention check interval.
+    new ClusterConfigProperty(key = 
GroupCoordinatorConfig.OFFSETS_RETENTION_CHECK_INTERVAL_MS_CONFIG, value = 
"500")
+  ))
+  def testPeriodicCleanupClearsTopologyAfterFailedClassicJoin(): Unit = {
+    val admin = cluster.admin()
+    val groupId = "test-group"
+    val topicName = "test-topic"
+
+    try {
+      FailingTopologyDescriptionPlugin.reset()
+      // Fail deletes before the group becomes empty: once it is, the cleanup 
cycle (500 ms) may
+      // run at any moment and would otherwise delete the topology before the 
join is attempted.
+      FailingTopologyDescriptionPlugin.failDeleteTopologyWith(new 
RuntimeException("plugin offline"))
+      createEmptyStreamsGroupWithStoredTopology(admin, groupId, topicName)
+
+      // The plugin cannot delete: the classic join is rejected and the group 
stays a streams group.
+      assertEquals(Errors.REBALANCE_IN_PROGRESS.code(), 
classicJoin(groupId).errorCode())
+      assertStillStreamsGroup(groupId)
+
+      // The plugin recovers. The failed join armed a back-off (at least 24s) 
that stops further
+      // joins from calling the plugin, and only a successful cleanup cycle 
clears it. So a join
+      // that gets past REBALANCE_IN_PROGRESS shows the periodic cycle emptied 
the plugin.
+      FailingTopologyDescriptionPlugin.failDeleteTopologyWith(null)
+      var joinResponse: JoinGroupResponseData = null
+      TestUtils.waitUntilTrue(() => {
+        joinResponse = sendJoinRequest(groupId = groupId)
+        joinResponse.errorCode() != Errors.REBALANCE_IN_PROGRESS.code()
+      }, "Classic join was still rejected after the plugin recovered.")
+
+      // The group converts once the member re-joins with the member id the 
broker assigned.
+      assertEquals(Errors.MEMBER_ID_REQUIRED.code(), joinResponse.errorCode())
+      assertEquals(Errors.NONE.code(), sendJoinRequest(groupId = groupId, 
memberId = joinResponse.memberId()).errorCode())
+      assertEquals(Errors.GROUP_ID_NOT_FOUND.code(), 
streamsGroupDescribe(List(groupId)).head.errorCode())
+      assertEquals("consumer", 
describeGroups(List(groupId)).head.protocolType())

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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to