lianetm commented on code in PR #17418: URL: https://github.com/apache/kafka/pull/17418#discussion_r1797021034
########## clients/src/test/java/org/apache/kafka/clients/consumer/internals/ShareConsumerImplTest.java: ########## @@ -306,32 +344,49 @@ public void testCompleteQuietly() { @Test public void testSubscribeGeneratesEvent() { - consumer = newConsumer(); + SubscriptionState subscriptions = new SubscriptionState(new LogContext(), OffsetResetStrategy.NONE); + consumer = newConsumer( + mock(ShareFetchBuffer.class), + subscriptions, + "group-id", + "client-id"); String topic = "topic1"; - consumer.subscribe(singletonList(topic)); + final List<String> subscriptionTopic = singletonList(topic); + completeShareSubscriptionChangeApplicationEventSuccessfully(subscriptions, subscriptionTopic); + consumer.subscribe(subscriptionTopic); assertEquals(singleton(topic), consumer.subscription()); - verify(applicationEventHandler).add(ArgumentMatchers.isA(ShareSubscriptionChangeEvent.class)); + verify(applicationEventHandler).addAndGet(ArgumentMatchers.isA(ShareSubscriptionChangeEvent.class)); } @Test public void testUnsubscribeGeneratesUnsubscribeEvent() { - consumer = newConsumer(); - completeShareUnsubscribeApplicationEventSuccessfully(); + SubscriptionState subscriptions = new SubscriptionState(new LogContext(), OffsetResetStrategy.NONE); + consumer = newConsumer( + mock(ShareFetchBuffer.class), + subscriptions, + "group-id", + "client-id"); + completeShareUnsubscribeApplicationEventSuccessfully(subscriptions); consumer.unsubscribe(); assertTrue(consumer.subscription().isEmpty()); - verify(applicationEventHandler).add(ArgumentMatchers.isA(ShareUnsubscribeEvent.class)); + verify(applicationEventHandler).addAndGet(ArgumentMatchers.isA(ShareUnsubscribeEvent.class)); } @Test public void testSubscribeToEmptyListActsAsUnsubscribe() { - consumer = newConsumer(); - completeShareUnsubscribeApplicationEventSuccessfully(); + SubscriptionState subscriptions = new SubscriptionState(new LogContext(), OffsetResetStrategy.NONE); + consumer = newConsumer( + mock(ShareFetchBuffer.class), + subscriptions, + "group-id", + "client-id"); + completeShareUnsubscribeApplicationEventSuccessfully(subscriptions); consumer.subscribe(Collections.emptyList()); assertTrue(consumer.subscription().isEmpty()); Review Comment: as above, remove? ########## clients/src/test/java/org/apache/kafka/clients/consumer/internals/ShareConsumerImplTest.java: ########## @@ -306,32 +344,49 @@ public void testCompleteQuietly() { @Test public void testSubscribeGeneratesEvent() { - consumer = newConsumer(); + SubscriptionState subscriptions = new SubscriptionState(new LogContext(), OffsetResetStrategy.NONE); + consumer = newConsumer( + mock(ShareFetchBuffer.class), + subscriptions, + "group-id", + "client-id"); String topic = "topic1"; - consumer.subscribe(singletonList(topic)); + final List<String> subscriptionTopic = singletonList(topic); + completeShareSubscriptionChangeApplicationEventSuccessfully(subscriptions, subscriptionTopic); + consumer.subscribe(subscriptionTopic); assertEquals(singleton(topic), consumer.subscription()); - verify(applicationEventHandler).add(ArgumentMatchers.isA(ShareSubscriptionChangeEvent.class)); + verify(applicationEventHandler).addAndGet(ArgumentMatchers.isA(ShareSubscriptionChangeEvent.class)); } @Test public void testUnsubscribeGeneratesUnsubscribeEvent() { - consumer = newConsumer(); - completeShareUnsubscribeApplicationEventSuccessfully(); + SubscriptionState subscriptions = new SubscriptionState(new LogContext(), OffsetResetStrategy.NONE); + consumer = newConsumer( + mock(ShareFetchBuffer.class), + subscriptions, + "group-id", + "client-id"); + completeShareUnsubscribeApplicationEventSuccessfully(subscriptions); consumer.unsubscribe(); assertTrue(consumer.subscription().isEmpty()); Review Comment: this assertion doesn't bring much value now right? The subscription is cleared in the background now, this is only passing here because we mock it ourselves in the `completeShareUnsubscribeApplicationEventSuccessfully` (verifying that the event was generated is all that matters I would say) -- 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