@@ -2767,17 +2767,25 @@ public void rePausePartitionAfterRebalance() throws Exception {
2767
2767
TopicPartition tp1 = new TopicPartition ("foo" , 1 );
2768
2768
given (consumer .assignment ()).willReturn (Set .of (tp0 , tp1 ));
2769
2769
final CountDownLatch pauseLatch1 = new CountDownLatch (1 );
2770
- final CountDownLatch pauseLatch2 = new CountDownLatch (2 );
2770
+ final CountDownLatch suspendConsumerThread = new CountDownLatch (1 );
2771
2771
Set <TopicPartition > pausedParts = ConcurrentHashMap .newKeySet ();
2772
+ Thread testThread = Thread .currentThread ();
2773
+ AtomicBoolean paused = new AtomicBoolean ();
2772
2774
willAnswer (i -> {
2773
2775
pausedParts .clear ();
2774
2776
pausedParts .addAll (i .getArgument (0 ));
2775
- pauseLatch1 .countDown ();
2776
- pauseLatch2 .countDown ();
2777
+ if (!Thread .currentThread ().equals (testThread )) {
2778
+ paused .set (true );
2779
+ }
2777
2780
return null ;
2778
2781
}).given (consumer ).pause (any ());
2779
2782
given (consumer .paused ()).willReturn (pausedParts );
2780
2783
given (consumer .poll (any (Duration .class ))).willAnswer (i -> {
2784
+ if (paused .get ()) {
2785
+ pauseLatch1 .countDown ();
2786
+ // hold up the consumer thread while we revoke/assign partitions on the test thread
2787
+ suspendConsumerThread .await (10 , TimeUnit .SECONDS );
2788
+ }
2781
2789
Thread .sleep (50 );
2782
2790
return ConsumerRecords .empty ();
2783
2791
});
@@ -2808,15 +2816,14 @@ public void rePausePartitionAfterRebalance() throws Exception {
2808
2816
.contains (tp0 , tp1 );
2809
2817
rebal .get ().onPartitionsRevoked (Set .of (tp0 , tp1 ));
2810
2818
rebal .get ().onPartitionsAssigned (Collections .singleton (tp0 ));
2811
- assertThat (pauseLatch2 .await (10 , TimeUnit .SECONDS )).isTrue ();
2812
2819
assertThat (pausedParts ).hasSize (1 )
2813
2820
.contains (tp0 );
2814
2821
assertThat (container ).extracting ("listenerConsumer" )
2815
2822
.extracting ("pausedPartitions" )
2816
2823
.asInstanceOf (InstanceOfAssertFactories .collection (TopicPartition .class ))
2817
2824
.hasSize (1 )
2818
- .containsExactlyInAnyOrder (tp0 );
2819
-
2825
+ .contains (tp0 );
2826
+ suspendConsumerThread . countDown ();
2820
2827
container .stop ();
2821
2828
}
2822
2829
0 commit comments