@@ -2769,7 +2769,6 @@ public void rePausePartitionAfterRebalance() throws Exception {
2769
2769
rebal .get ().onPartitionsAssigned (Set .of (tp0 , tp1 ));
2770
2770
return null ;
2771
2771
}).given (consumer ).subscribe (eq (foos ), any (ConsumerRebalanceListener .class ));
2772
- final CountDownLatch resumeLatch = new CountDownLatch (1 );
2773
2772
ContainerProperties containerProps = new ContainerProperties ("foo" );
2774
2773
containerProps .setGroupId ("grp" );
2775
2774
containerProps .setAckMode (AckMode .RECORD );
@@ -2780,7 +2779,6 @@ public void rePausePartitionAfterRebalance() throws Exception {
2780
2779
KafkaMessageListenerContainer <Integer , String > container =
2781
2780
new KafkaMessageListenerContainer <>(cf , containerProps );
2782
2781
container .start ();
2783
- InOrder inOrder = inOrder (consumer );
2784
2782
assertThat (firstPoll .await (10 , TimeUnit .SECONDS )).isNotNull ();
2785
2783
container .pausePartition (tp0 );
2786
2784
container .pausePartition (tp1 );
@@ -2811,7 +2809,6 @@ public void resumePartitionAfterRevokeAndReAssign() throws Exception {
2811
2809
ConsumerFactory <Integer , String > cf = mock (ConsumerFactory .class );
2812
2810
Consumer <Integer , String > consumer = mock (Consumer .class );
2813
2811
given (cf .createConsumer (eq ("grp" ), eq ("clientId" ), isNull (), any ())).willReturn (consumer );
2814
- AtomicBoolean first = new AtomicBoolean (true );
2815
2812
TopicPartition tp0 = new TopicPartition ("foo" , 0 );
2816
2813
TopicPartition tp1 = new TopicPartition ("foo" , 1 );
2817
2814
given (consumer .assignment ()).willReturn (Set .of (tp0 , tp1 ));
@@ -3462,7 +3459,6 @@ public void testCooperativeRebalance() throws Exception {
3462
3459
containerProps .setGroupId ("grp" );
3463
3460
containerProps .setClientId ("clientId" );
3464
3461
containerProps .setMessageListener ((MessageListener <?, ?>) msg -> { });
3465
- Properties consumerProps = new Properties ();
3466
3462
KafkaMessageListenerContainer <Integer , String > container =
3467
3463
new KafkaMessageListenerContainer <>(cf , containerProps );
3468
3464
container .start ();
@@ -3606,7 +3602,6 @@ else if (call == 1) {
3606
3602
}).given (consumer ).subscribe (any (Collection .class ), any (ConsumerRebalanceListener .class ));
3607
3603
List <Map <TopicPartition , OffsetAndMetadata >> commits = new ArrayList <>();
3608
3604
AtomicBoolean firstCommit = new AtomicBoolean (true );
3609
- AtomicInteger commitCount = new AtomicInteger ();
3610
3605
willAnswer (invoc -> {
3611
3606
commits .add (invoc .getArgument (0 , Map .class ));
3612
3607
if (!firstCommit .getAndSet (false )) {
@@ -3888,6 +3883,11 @@ public void testInvokeRecordInterceptorAllSkipped(AckMode ackMode, boolean early
3888
3883
latch .countDown ();
3889
3884
return null ;
3890
3885
}).given (consumer ).commitSync (any (), any ());
3886
+ CountDownLatch closeLatch = new CountDownLatch (1 );
3887
+ willAnswer (inv -> {
3888
+ closeLatch .countDown ();
3889
+ return null ;
3890
+ }).given (consumer ).close ();
3891
3891
TopicPartitionOffset [] topicPartition = new TopicPartitionOffset [] {
3892
3892
new TopicPartitionOffset ("foo" , 0 ) };
3893
3893
@@ -3902,6 +3902,7 @@ public void testInvokeRecordInterceptorAllSkipped(AckMode ackMode, boolean early
3902
3902
containerProps .setKafkaAwareTransactionManager (mock (KafkaAwareTransactionManager .class ));
3903
3903
}
3904
3904
3905
+ CountDownLatch afterRecordLatch = new CountDownLatch (2 );
3905
3906
RecordInterceptor <Integer , String > recordInterceptor = spy (new RecordInterceptor <Integer , String >() {
3906
3907
3907
3908
@ Override
@@ -3912,6 +3913,10 @@ public ConsumerRecord<Integer, String> intercept(ConsumerRecord<Integer, String>
3912
3913
return null ;
3913
3914
}
3914
3915
3916
+ public void afterRecord (ConsumerRecord <Integer , String > record , Consumer <Integer , String > consumer ) {
3917
+ afterRecordLatch .countDown ();
3918
+ }
3919
+
3915
3920
});
3916
3921
3917
3922
KafkaMessageListenerContainer <Integer , String > container =
@@ -3920,6 +3925,9 @@ public ConsumerRecord<Integer, String> intercept(ConsumerRecord<Integer, String>
3920
3925
container .setInterceptBeforeTx (early );
3921
3926
container .start ();
3922
3927
assertThat (latch .await (10 , TimeUnit .SECONDS )).isTrue ();
3928
+ assertThat (afterRecordLatch .await (10 , TimeUnit .SECONDS )).isTrue ();
3929
+ container .stop ();
3930
+ assertThat (closeLatch .await (10 , TimeUnit .SECONDS )).isTrue ();
3923
3931
3924
3932
InOrder inOrder = inOrder (recordInterceptor , consumer );
3925
3933
inOrder .verify (recordInterceptor ).setupThreadState (eq (consumer ));
@@ -3946,12 +3954,12 @@ public ConsumerRecord<Integer, String> intercept(ConsumerRecord<Integer, String>
3946
3954
inOrder .verify (consumer ).commitSync (eq (Map .of (new TopicPartition ("foo" , 0 ), new OffsetAndMetadata (2L ))),
3947
3955
any (Duration .class ));
3948
3956
}
3949
- container . stop ();
3957
+ inOrder . verify ( consumer ). close ();
3950
3958
}
3951
3959
3952
3960
@ ParameterizedTest (name = "{index} testInvokeBatchInterceptorAllSkipped early intercept {0}" )
3953
3961
@ ValueSource (booleans = { true , false })
3954
- @ SuppressWarnings ({ "unchecked" , "deprecation" } )
3962
+ @ SuppressWarnings ("unchecked" )
3955
3963
public void testInvokeBatchInterceptorAllSkipped (boolean early ) throws Exception {
3956
3964
ConsumerFactory <Integer , String > cf = mock (ConsumerFactory .class );
3957
3965
Consumer <Integer , String > consumer = mock (Consumer .class );
0 commit comments