[fix][test] Fix `PersistentDispatcherFailoverConsumerTest#testAddRemoveConsumer` wrong logic.
@@ -420,30 +420,33 @@ public class PersistentDispatcherFailoverConsumerTest {
verify(consumer2, times(1)).notifyActiveConsumerChange(same(consumer1));
verify(consumer2, times(1)).notifyActiveConsumerChange(same(consumer0));
- // 7. Remove last consumer
+ // 7. Remove last consumer to make active consumer change.
pdfc.removeConsumer(consumer2);
consumers = pdfc.getConsumers();
assertSame(pdfc.getActiveConsumer().consumerName(), consumer1.consumerName());
assertEquals(3, consumers.size());
- // not consumer group changes
- assertNull(consumerChanges.poll());
+
+ change = consumerChanges.poll(10, TimeUnit.SECONDS);
+ assertNotNull(change);
+ verifyActiveConsumerChange(change, 0, false);
+ change = consumerChanges.poll(10, TimeUnit.SECONDS);
+ assertNotNull(change);
+ verifyActiveConsumerChange(change, 1, true);
+ change = consumerChanges.poll(10, TimeUnit.SECONDS);
+ assertNotNull(change);
+ verifyActiveConsumerChange(change, 1, true);
// 8. Verify if we cannot unsubscribe when more than one consumer is connected
assertFalse(pdfc.canUnsubscribe(consumer0));
- // 9. Remove active consumer
+ // 9. Remove inactive consumer
pdfc.removeConsumer(consumer0);
consumers = pdfc.getConsumers();
assertSame(pdfc.getActiveConsumer().consumerName(), consumer1.consumerName());
assertEquals(2, consumers.size());
- // the remaining consumers will receive notifications
- change = consumerChanges.poll(10, TimeUnit.SECONDS);
- assertNotNull(change);
- verifyActiveConsumerChange(change, 1, true);
- change = consumerChanges.poll(10, TimeUnit.SECONDS);
- assertNotNull(change);
- verifyActiveConsumerChange(change, 1, true);
+ // not consumer group changes
+ assertNull(consumerChanges.poll(10, TimeUnit.SECONDS));
// 10. Attempt to remove already removed consumer
String cause = "";
@@ -454,13 +457,13 @@ public class PersistentDispatcherFailoverConsumerTest {
}
assertEquals(cause, "Consumer was not connected");
- // 11. Remove active consumer
+ // 11. Remove same consumer
pdfc.removeConsumer(consumer1);
consumers = pdfc.getConsumers();
assertSame(pdfc.getActiveConsumer().consumerName(), consumer1.consumerName());
assertEquals(1, consumers.size());
// not consumer group changes
- assertNull(consumerChanges.poll());
+ assertNull(consumerChanges.poll(10, TimeUnit.SECONDS));
// 11. With only one consumer, unsubscribe is allowed
assertTrue(pdfc.canUnsubscribe(consumer1));
