You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "lucasbru (via GitHub)" <gi...@apache.org> on 2025/09/23 14:29:23 UTC

[PR] MINOR: Fix StreamsRebalanceListenerInvoker [kafka]

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

   StreamsRebalanceListenerInvoker was implemented to match the behavior of ConsumerRebalanceListenerInvoker, however StreamsRebalanceListener has a subtly different interface than ConsumerRebalanceListener - it does not throw exceptions, but returns it as an Optional.
   
   In the interest of consistency, this change fixes this mismatch by changing the StreamsRebalanceListener interface to behave more like the ConsumerRebalanceListener - throwing exceptions directly.
   
   In another minor fix, the StreamsRebalanceListenerInvoker is changed to simply skip callback execution instead of throwing an IllegalStateException when no streamRebalanceListener is defined. This can happen when the consumer is closed before Consumer.subscribe is called.
   
   


-- 
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] MINOR: Fix StreamsRebalanceListenerInvoker [kafka]

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


-- 
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] MINOR: Fix StreamsRebalanceListenerInvoker [kafka]

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


##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/DefaultStreamsRebalanceListenerTest.java:
##########
@@ -109,9 +108,9 @@ void testOnTasksRevokedWithException() {
 
         createRebalanceListenerWithRebalanceData(new StreamsRebalanceData(UUID.randomUUID(), Optional.empty(), Map.of(), Map.of()));
 
-        final Optional<Exception> result = defaultStreamsRebalanceListener.onTasksRevoked(Set.of());
+        final Exception actualException = assertThrows(RuntimeException.class, () -> defaultStreamsRebalanceListener.onTasksRevoked(Set.of()));
 
-        assertTrue(result.isPresent());
+        assertEquals(actualException,  exception);

Review Comment:
   [nitpick] Extra space before 'exception' parameter. Should be 'assertEquals(actualException, exception);' for consistent formatting.



##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/DefaultStreamsRebalanceListenerTest.java:
##########
@@ -211,9 +208,10 @@ void testOnAllTasksLostWithException() {
         final StreamsRebalanceData streamsRebalanceData = mock(StreamsRebalanceData.class);
         when(streamsRebalanceData.subtopologies()).thenReturn(Map.of());
         createRebalanceListenerWithRebalanceData(streamsRebalanceData);
-        final Optional<Exception> result = defaultStreamsRebalanceListener.onAllTasksLost();
-        assertTrue(result.isPresent());
-        assertEquals(exception, result.get());
+
+        final Exception actualException = assertThrows(RuntimeException.class, () -> defaultStreamsRebalanceListener.onAllTasksLost());
+
+        assertEquals(exception,  actualException);

Review Comment:
   [nitpick] Extra space before 'actualException' parameter. Should be 'assertEquals(exception, actualException);' for consistent formatting.



-- 
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] MINOR: Fix StreamsRebalanceListenerInvoker [kafka]

Posted by "lucasbru (via GitHub)" <gi...@apache.org>.
lucasbru commented on PR #20575:
URL: https://github.com/apache/kafka/pull/20575#issuecomment-3325162432

   > Overall LGTM, but I am somewhat surprised that we don't need more code changes.
   > 
   > I was expected to see changed on the caller code of `StreamsRebalanceListener`, but it seems it's only called from `StreamsRebalanceListenerInvoker`? And the original code did not check if the returned `Optional` returns an exception or not?
   > 
   > So this code "auto fixes" the incorrect code of `StreamsRebalanceListenerInvoker`?
   > 
   > Just want to make sure I get this right.
   
   Yes, exactly.


-- 
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] MINOR: Fix StreamsRebalanceListenerInvoker [kafka]

Posted by "lucasbru (via GitHub)" <gi...@apache.org>.
lucasbru commented on PR #20575:
URL: https://github.com/apache/kafka/pull/20575#issuecomment-3380654981

   Cherry-picked to `4.1` branch.


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