poorbarcode commented on code in PR #19934:
URL: https://github.com/apache/pulsar/pull/19934#discussion_r1154038820


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/nonpersistent/NonPersistentStickyKeyDispatcherMultipleConsumers.java:
##########
@@ -84,6 +86,11 @@ public 
NonPersistentStickyKeyDispatcherMultipleConsumers(NonPersistentTopic topi
 
     @Override
     public synchronized void addConsumer(Consumer consumer) throws 
BrokerServiceException {
+        if (IS_CLOSED_UPDATER.get(this) == TRUE) {
+            log.warn("[{}] Dispatcher is already closed. Closing consumer {}", 
name, consumer);
+            consumer.disconnect();
+            return;
+        }

Review Comment:
   `super.addConsumer(consumer)` already did this check, right? If yes, we 
should not repeatedly check it.



##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentStickyKeyDispatcherMultipleConsumers.java:
##########
@@ -102,6 +102,11 @@ public class 
PersistentStickyKeyDispatcherMultipleConsumers extends PersistentDi
 
     @Override
     public synchronized void addConsumer(Consumer consumer) throws 
BrokerServiceException {
+        if (IS_CLOSED_UPDATER.get(this) == TRUE) {
+            log.warn("[{}] Dispatcher is already closed. Closing consumer {}", 
name, consumer);
+            consumer.disconnect();
+            return;
+        }
         super.addConsumer(consumer);

Review Comment:
   `super.addConsumer(consumer)` already did this check, right? If yes, we 
should not repeatedly check it.



##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/nonpersistent/NonPersistentStickyKeyDispatcherMultipleConsumersTest.java:
##########
@@ -94,6 +94,15 @@ public void setup() throws Exception {
             new HashRangeAutoSplitStickyKeyConsumerSelector());
     }
 
+    @Test(timeOut = 10000)
+    public void testAddConsumerWhenClosed() throws Exception {
+        nonpersistentDispatcher.close().get();
+        Consumer consumer = mock(Consumer.class);
+        nonpersistentDispatcher.addConsumer(consumer);
+        verify(consumer, times(1)).disconnect();
+        assertEquals(0, nonpersistentDispatcher.getConsumers().size());

Review Comment:
   Should we add a verify: `this consumer does not exist in the selector`?



##########
pulsar-broker/src/test/java/org/apache/pulsar/broker/service/persistent/PersistentStickyKeyDispatcherMultipleConsumersTest.java:
##########
@@ -159,6 +159,15 @@ public void cleanup() {
         }
     }
 
+    @Test(timeOut = 10000)
+    public void testAddConsumerWhenClosed() throws Exception {
+        persistentDispatcher.close().get();
+        Consumer consumer = mock(Consumer.class);
+        persistentDispatcher.addConsumer(consumer);
+        verify(consumer, times(1)).disconnect();
+        assertEquals(0, persistentDispatcher.getConsumers().size());

Review Comment:
   Should we add a verify: `this consumer does not exist in the selector`?



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