lucasbru commented on code in PR #15440: URL: https://github.com/apache/kafka/pull/15440#discussion_r1507649418
########## clients/src/test/java/org/apache/kafka/clients/consumer/internals/MembershipManagerImplTest.java: ########## @@ -764,6 +766,44 @@ public void testLeaveGroupWhenMemberOwnsAssignment() { testLeaveGroupReleasesAssignmentAndResetsEpochToSendLeaveGroup(membershipManager); } + @Test + public void testLeaveGroupWhenAssignmentEmpty() { + String topicName = "topic1"; + TopicPartition ownedPartition = new TopicPartition(topicName, 0); + MembershipManager membershipManager = createMemberInStableState(); + + // We own a partition and rebalance listener is registered + when(subscriptionState.assignedPartitions()).thenReturn(Collections.singleton(ownedPartition)); + when(subscriptionState.hasAutoAssignedPartitions()).thenReturn(true); + when(subscriptionState.rebalanceListener()).thenReturn(Optional.of(mock(ConsumerRebalanceListener.class))); + doNothing().when(subscriptionState).markPendingRevocation(anySet()); + + // Trigger leave group + CompletableFuture<Void> leaveResult1 = membershipManager.leaveGroup(); + + // Rebalance listener not yet triggered + final ArgumentCaptor<ConsumerRebalanceListenerCallbackNeededEvent> consumerRebalanceListener = + ArgumentCaptor.forClass(ConsumerRebalanceListenerCallbackNeededEvent.class); + verify(backgroundEventHandler).add(consumerRebalanceListener.capture()); + final ConsumerRebalanceListenerCallbackNeededEvent callbackEvent = consumerRebalanceListener.getValue(); + assertFalse(leaveResult1.isDone()); + assertEquals(MemberState.PREPARE_LEAVING, membershipManager.state()); + + // Clear the assignment + when(subscriptionState.assignedPartitions()).thenReturn(Collections.emptySet()); + when(subscriptionState.hasAutoAssignedPartitions()).thenReturn(false); + + // Complete the callback + callbackEvent.future().complete(null); + + // Completed the listener Review Comment: Done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org