@@ -664,6 +664,40 @@ public void testNonResponsiveConsumerEvent() throws Exception {
664
664
container .stop ();
665
665
}
666
666
667
+ @ SuppressWarnings ({ "unchecked" , "rawtypes" })
668
+ @ Test
669
+ public void testNonResponsiveConsumerEventNotIssuedWithActiveConsumer () throws Exception {
670
+ ConsumerFactory <Integer , String > cf = mock (ConsumerFactory .class );
671
+ Consumer <Integer , String > consumer = mock (Consumer .class );
672
+ given (cf .createConsumer (isNull (), eq ("" ), isNull ())).willReturn (consumer );
673
+ ConsumerRecords records = new ConsumerRecords (Collections .emptyMap ());
674
+ CountDownLatch latch = new CountDownLatch (20 );
675
+ given (consumer .poll (anyLong ())).willAnswer (i -> {
676
+ Thread .sleep (100 );
677
+ latch .countDown ();
678
+ return records ;
679
+ });
680
+ TopicPartitionInitialOffset [] topicPartition = new TopicPartitionInitialOffset [] {
681
+ new TopicPartitionInitialOffset ("foo" , 0 ) };
682
+ ContainerProperties containerProps = new ContainerProperties (topicPartition );
683
+ containerProps .setNoPollThreshold (2.0f );
684
+ containerProps .setPollTimeout (100 );
685
+ containerProps .setMonitorInterval (1 );
686
+ containerProps .setMessageListener (mock (MessageListener .class ));
687
+ KafkaMessageListenerContainer <Integer , String > container =
688
+ new KafkaMessageListenerContainer <>(cf , containerProps );
689
+ final AtomicInteger eventCounter = new AtomicInteger ();
690
+ container .setApplicationEventPublisher (e -> {
691
+ if (e instanceof NonResponsiveConsumerEvent ) {
692
+ eventCounter .incrementAndGet ();
693
+ }
694
+ });
695
+ container .start ();
696
+ assertThat (latch .await (10 , TimeUnit .SECONDS )).isTrue ();
697
+ container .stop ();
698
+ assertThat (eventCounter .get ()).isEqualTo (0 );
699
+ }
700
+
667
701
@ Test
668
702
public void testBatchAck () throws Exception {
669
703
logger .info ("Start batch ack" );
0 commit comments