@@ -647,6 +647,40 @@ public void testBrokerDownEvent() throws Exception {
647
647
container .stop ();
648
648
}
649
649
650
+ @ SuppressWarnings ({ "unchecked" , "rawtypes" })
651
+ @ Test
652
+ public void testNonResponsiveConsumerEventNotIssuedWithActiveConsumer () throws Exception {
653
+ ConsumerFactory <Integer , String > cf = mock (ConsumerFactory .class );
654
+ Consumer <Integer , String > consumer = mock (Consumer .class );
655
+ given (cf .createConsumer (isNull (), eq ("" ))).willReturn (consumer );
656
+ ConsumerRecords records = new ConsumerRecords (Collections .emptyMap ());
657
+ CountDownLatch latch = new CountDownLatch (20 );
658
+ given (consumer .poll (anyLong ())).willAnswer (i -> {
659
+ Thread .sleep (100 );
660
+ latch .countDown ();
661
+ return records ;
662
+ });
663
+ TopicPartitionInitialOffset [] topicPartition = new TopicPartitionInitialOffset [] {
664
+ new TopicPartitionInitialOffset ("foo" , 0 ) };
665
+ ContainerProperties containerProps = new ContainerProperties (topicPartition );
666
+ containerProps .setNoPollThreshold (2.0f );
667
+ containerProps .setPollTimeout (100 );
668
+ containerProps .setMonitorInterval (1 );
669
+ containerProps .setMessageListener (mock (MessageListener .class ));
670
+ KafkaMessageListenerContainer <Integer , String > container =
671
+ new KafkaMessageListenerContainer <>(cf , containerProps );
672
+ final AtomicInteger eventCounter = new AtomicInteger ();
673
+ container .setApplicationEventPublisher (e -> {
674
+ if (e instanceof NonResponsiveConsumerEvent ) {
675
+ eventCounter .incrementAndGet ();
676
+ }
677
+ });
678
+ container .start ();
679
+ assertThat (latch .await (10 , TimeUnit .SECONDS )).isTrue ();
680
+ container .stop ();
681
+ assertThat (eventCounter .get ()).isEqualTo (0 );
682
+ }
683
+
650
684
@ Test
651
685
public void testBatchAck () throws Exception {
652
686
logger .info ("Start batch ack" );
0 commit comments