@@ -621,15 +621,25 @@ private void testRecordAckMockForeignThreadGuts(AckMode ackMode) throws Exceptio
621
621
new ConsumerRecord <>("foo" , 0 , 0L , 1 , "foo" ),
622
622
new ConsumerRecord <>("foo" , 0 , 1L , 1 , "bar" )));
623
623
ConsumerRecords <Integer , String > consumerRecords = new ConsumerRecords <>(records );
624
+ long sleepFor = ackMode .equals (AckMode .MANUAL_IMMEDIATE ) ? 20_000 : 50 ;
625
+ AtomicBoolean first = new AtomicBoolean (true );
624
626
given (consumer .poll (any (Duration .class ))).willAnswer (i -> {
625
- Thread .sleep (50 );
627
+ if (!first .getAndSet (false )) {
628
+ try {
629
+ Thread .sleep (sleepFor );
630
+ }
631
+ catch (@ SuppressWarnings ("unused" ) InterruptedException ex ) {
632
+ throw new WakeupException ();
633
+ }
634
+ }
626
635
return consumerRecords ;
627
636
});
628
637
TopicPartitionInitialOffset [] topicPartition = new TopicPartitionInitialOffset [] {
629
638
new TopicPartitionInitialOffset ("foo" , 0 ) };
630
639
ContainerProperties containerProps = new ContainerProperties (topicPartition );
631
640
containerProps .setGroupId ("grp" );
632
641
containerProps .setAckMode (ackMode );
642
+ containerProps .setMissingTopicsFatal (false );
633
643
final CountDownLatch latch = new CountDownLatch (2 );
634
644
final List <Acknowledgment > acks = new ArrayList <>();
635
645
final AtomicReference <Thread > consumerThread = new AtomicReference <>();
@@ -647,6 +657,10 @@ public void onMessage(ConsumerRecord<Integer, String> data, Acknowledgment ackno
647
657
}
648
658
649
659
});
660
+ willAnswer (inv -> {
661
+ consumerThread .get ().interrupt ();
662
+ return null ;
663
+ }).given (consumer ).wakeup ();
650
664
651
665
final CountDownLatch commitLatch = new CountDownLatch (1 );
652
666
final AtomicReference <Thread > commitThread = new AtomicReference <>();
@@ -663,6 +677,7 @@ public void onMessage(ConsumerRecord<Integer, String> data, Acknowledgment ackno
663
677
new KafkaMessageListenerContainer <>(cf , containerProps );
664
678
container .start ();
665
679
assertThat (latch .await (10 , TimeUnit .SECONDS )).isTrue ();
680
+ long t1 = System .currentTimeMillis ();
666
681
acks .get (1 ).acknowledge ();
667
682
assertThat (commitLatch .await (10 , TimeUnit .SECONDS )).isTrue ();
668
683
InOrder inOrder = inOrder (messageListener , consumer );
@@ -671,6 +686,7 @@ public void onMessage(ConsumerRecord<Integer, String> data, Acknowledgment ackno
671
686
inOrder .verify (consumer ).commitSync (anyMap (), any ());
672
687
container .stop ();
673
688
assertThat (commitThread .get ()).isSameAs (consumerThread .get ());
689
+ assertThat (System .currentTimeMillis () - t1 ).isLessThan (15_000 );
674
690
}
675
691
676
692
@ SuppressWarnings ("unchecked" )
0 commit comments