4747import org .apache .kafka .common .serialization .StringSerializer ;
4848import org .assertj .core .api .InstanceOfAssertFactories ;
4949import org .junit .jupiter .api .Test ;
50+
5051import org .springframework .beans .factory .annotation .Autowired ;
5152import org .springframework .context .annotation .Bean ;
5253import org .springframework .context .annotation .Configuration ;
9495
9596@ SpringJUnitConfig
9697@ DirtiesContext
97- @ EmbeddedKafka (topics = { AsyncCompletableFutureRetryTopicClassLevelIntegrationTests .FIRST_TOPIC ,
98- AsyncCompletableFutureRetryTopicClassLevelIntegrationTests .SECOND_TOPIC ,
99- AsyncCompletableFutureRetryTopicClassLevelIntegrationTests .THIRD_TOPIC ,
100- AsyncCompletableFutureRetryTopicClassLevelIntegrationTests .FOURTH_TOPIC ,
101- AsyncCompletableFutureRetryTopicClassLevelIntegrationTests .TWO_LISTENERS_TOPIC ,
102- AsyncCompletableFutureRetryTopicClassLevelIntegrationTests .MANUAL_TOPIC })
98+ @ EmbeddedKafka (topics = {
99+ AsyncCompletableFutureRetryTopicClassLevelIntegrationTests .FIRST_TOPIC ,
100+ AsyncCompletableFutureRetryTopicClassLevelIntegrationTests .SECOND_TOPIC ,
101+ AsyncCompletableFutureRetryTopicClassLevelIntegrationTests .THIRD_TOPIC ,
102+ AsyncCompletableFutureRetryTopicClassLevelIntegrationTests .FOURTH_TOPIC ,
103+ AsyncCompletableFutureRetryTopicClassLevelIntegrationTests .TWO_LISTENERS_TOPIC ,
104+ AsyncCompletableFutureRetryTopicClassLevelIntegrationTests .MANUAL_TOPIC })
103105@ TestPropertySource (properties = { "five.attempts=5" , "kafka.template=customKafkaTemplate" })
104106public class AsyncCompletableFutureRetryTopicClassLevelIntegrationTests {
105107
@@ -167,8 +169,9 @@ void shouldRetrySecondTopic() {
167169 }
168170
169171 @ Test
170- void shouldRetryThirdTopicWithTimeout (@ Autowired KafkaAdmin admin ,
171- @ Autowired KafkaListenerEndpointRegistry registry ) throws Exception {
172+ void shouldRetryThirdTopicWithTimeout (
173+ @ Autowired KafkaAdmin admin ,
174+ @ Autowired KafkaListenerEndpointRegistry registry ) throws Exception {
172175
173176 kafkaTemplate .send (THIRD_TOPIC , "Testing topic 3" );
174177 assertThat (awaitLatch (latchContainer .countDownLatch3 )).isTrue ();
@@ -215,26 +218,34 @@ void shouldRetryFourthTopicWithNoDlt() {
215218 }
216219
217220 @ Test
218- void shouldRetryFifthTopicWithTwoListenersAndManualAssignment (@ Autowired
219- FifthTopicListener1 listener1 ,
220- @ Autowired FifthTopicListener2 listener2 ) {
221+ void shouldRetryFifthTopicWithTwoListenersAndManualAssignment (
222+ @ Autowired FifthTopicListener1 listener1 ,
223+ @ Autowired FifthTopicListener2 listener2 ) {
221224
222225 kafkaTemplate .send (TWO_LISTENERS_TOPIC , 0 , "0" , "Testing topic 5 - 0" );
223226 kafkaTemplate .send (TWO_LISTENERS_TOPIC , 1 , "0" , "Testing topic 5 - 1" );
224227 assertThat (awaitLatch (latchContainer .countDownLatch51 )).isTrue ();
225228 assertThat (awaitLatch (latchContainer .countDownLatch52 )).isTrue ();
226229 assertThat (awaitLatch (latchContainer .countDownLatchDltThree )).isTrue ();
227- assertThat (listener1 .topics ).containsExactly (TWO_LISTENERS_TOPIC , TWO_LISTENERS_TOPIC
228- + "-listener1-0" , TWO_LISTENERS_TOPIC + "-listener1-1" , TWO_LISTENERS_TOPIC + "-listener1-2" ,
229- TWO_LISTENERS_TOPIC + "-listener1-dlt" );
230- assertThat (listener2 .topics ).containsExactly (TWO_LISTENERS_TOPIC , TWO_LISTENERS_TOPIC
231- + "-listener2-0" , TWO_LISTENERS_TOPIC + "-listener2-1" , TWO_LISTENERS_TOPIC + "-listener2-2" ,
232- TWO_LISTENERS_TOPIC + "-listener2-dlt" );
230+ assertThat (listener1 .topics ).containsExactly (
231+ TWO_LISTENERS_TOPIC ,
232+ TWO_LISTENERS_TOPIC + "-listener1-0" ,
233+ TWO_LISTENERS_TOPIC + "-listener1-1" ,
234+ TWO_LISTENERS_TOPIC + "-listener1-2" ,
235+ TWO_LISTENERS_TOPIC + "-listener1-dlt"
236+ );
237+ assertThat (listener2 .topics ).containsExactly (
238+ TWO_LISTENERS_TOPIC ,
239+ TWO_LISTENERS_TOPIC + "-listener2-0" ,
240+ TWO_LISTENERS_TOPIC + "-listener2-1" ,
241+ TWO_LISTENERS_TOPIC + "-listener2-2" ,
242+ TWO_LISTENERS_TOPIC + "-listener2-dlt" );
233243 }
234244
235245 @ Test
236- void shouldRetryManualTopicWithDefaultDlt (@ Autowired KafkaListenerEndpointRegistry registry ,
237- @ Autowired ConsumerFactory <String , String > cf ) {
246+ void shouldRetryManualTopicWithDefaultDlt (
247+ @ Autowired KafkaListenerEndpointRegistry registry ,
248+ @ Autowired ConsumerFactory <String , String > cf ) {
238249
239250 kafkaTemplate .send (MANUAL_TOPIC , "Testing topic 6" );
240251 assertThat (awaitLatch (latchContainer .countDownLatch6 )).isTrue ();
@@ -243,9 +254,10 @@ void shouldRetryManualTopicWithDefaultDlt(@Autowired KafkaListenerEndpointRegist
243254 .forEach (id -> {
244255 ConcurrentMessageListenerContainer <?, ?> container =
245256 (ConcurrentMessageListenerContainer <?, ?>) registry .getListenerContainer (id );
246- assertThat (container ).extracting ("commonErrorHandler" )
247- .extracting ("seekAfterError" , InstanceOfAssertFactories .BOOLEAN )
248- .isFalse ();
257+ assertThat (container )
258+ .extracting ("commonErrorHandler" )
259+ .extracting ("seekAfterError" , InstanceOfAssertFactories .BOOLEAN )
260+ .isFalse ();
249261 });
250262 Consumer <String , String > consumer = cf .createConsumer ("manual-dlt" , "" );
251263 Set <org .apache .kafka .common .TopicPartition > tp =
@@ -276,14 +288,21 @@ void shouldFirstReuseRetryTopic(@Autowired
276288 assertThat (awaitLatch (latchContainer .countDownLatchReuseOne )).isTrue ();
277289 assertThat (awaitLatch (latchContainer .countDownLatchReuseTwo )).isTrue ();
278290 assertThat (awaitLatch (latchContainer .countDownLatchReuseThree )).isTrue ();
279- assertThat (listener1 .topics ).containsExactly (FIRST_REUSE_RETRY_TOPIC ,
280- FIRST_REUSE_RETRY_TOPIC + "-retry" );
281- assertThat (listener2 .topics ).containsExactly (SECOND_REUSE_RETRY_TOPIC ,
282- SECOND_REUSE_RETRY_TOPIC + "-retry-30" , SECOND_REUSE_RETRY_TOPIC + "-retry-60" ,
283- SECOND_REUSE_RETRY_TOPIC + "-retry-100" , SECOND_REUSE_RETRY_TOPIC + "-retry-100" );
284- assertThat (listener3 .topics ).containsExactly (THIRD_REUSE_RETRY_TOPIC ,
285- THIRD_REUSE_RETRY_TOPIC + "-retry" , THIRD_REUSE_RETRY_TOPIC + "-retry" ,
286- THIRD_REUSE_RETRY_TOPIC + "-retry" , THIRD_REUSE_RETRY_TOPIC + "-retry" );
291+ assertThat (listener1 .topics ).containsExactly (
292+ FIRST_REUSE_RETRY_TOPIC ,
293+ FIRST_REUSE_RETRY_TOPIC + "-retry" );
294+ assertThat (listener2 .topics ).containsExactly (
295+ SECOND_REUSE_RETRY_TOPIC ,
296+ SECOND_REUSE_RETRY_TOPIC + "-retry-30" ,
297+ SECOND_REUSE_RETRY_TOPIC + "-retry-60" ,
298+ SECOND_REUSE_RETRY_TOPIC + "-retry-100" ,
299+ SECOND_REUSE_RETRY_TOPIC + "-retry-100" );
300+ assertThat (listener3 .topics ).containsExactly (
301+ THIRD_REUSE_RETRY_TOPIC ,
302+ THIRD_REUSE_RETRY_TOPIC + "-retry" ,
303+ THIRD_REUSE_RETRY_TOPIC + "-retry" ,
304+ THIRD_REUSE_RETRY_TOPIC + "-retry" ,
305+ THIRD_REUSE_RETRY_TOPIC + "-retry" );
287306 }
288307
289308 @ Test
@@ -324,7 +343,8 @@ public CompletableFuture<Void> listen(String message, @Header(KafkaHeaders.RECEI
324343 container .countDownLatch1 .countDown ();
325344 try {
326345 Thread .sleep (1 );
327- } catch (InterruptedException e ) {
346+ }
347+ catch (InterruptedException e ) {
328348 throw new RuntimeException (e );
329349 }
330350 throw new RuntimeException ("Woooops... in topic " + receivedTopic );
@@ -345,7 +365,8 @@ public CompletableFuture<Void> listenAgain(String message, @Header(KafkaHeaders.
345365 container .countDownIfNotKnown (receivedTopic , container .countDownLatch2 );
346366 try {
347367 Thread .sleep (1 );
348- } catch (InterruptedException e ) {
368+ }
369+ catch (InterruptedException e ) {
349370 throw new RuntimeException (e );
350371 }
351372 throw new IllegalStateException ("Another woooops... " + receivedTopic );
@@ -377,7 +398,8 @@ public CompletableFuture<Void> listenWithAnnotation(String message, @Header(Kafk
377398 container .countDownIfNotKnown (receivedTopic , container .countDownLatch3 );
378399 try {
379400 Thread .sleep (1 );
380- } catch (InterruptedException e ) {
401+ }
402+ catch (InterruptedException e ) {
381403 throw new RuntimeException (e );
382404 }
383405 throw new MyRetryException ("Annotated woooops... " + receivedTopic );
@@ -405,7 +427,8 @@ public CompletableFuture<Void> listenNoDlt(String message, @Header(KafkaHeaders.
405427 container .countDownIfNotKnown (receivedTopic , container .countDownLatch4 );
406428 try {
407429 Thread .sleep (1 );
408- } catch (InterruptedException e ) {
430+ }
431+ catch (InterruptedException e ) {
409432 throw new RuntimeException (e );
410433 }
411434 throw new IllegalStateException ("Another woooops... " + receivedTopic );
@@ -456,7 +479,8 @@ public CompletableFuture<Void> listenWithAnnotation(String message, @Header(Kafk
456479 container .countDownIfNotKnown (receivedTopic , container .countDownLatch51 );
457480 try {
458481 Thread .sleep (1 );
459- } catch (InterruptedException e ) {
482+ }
483+ catch (InterruptedException e ) {
460484 throw new RuntimeException (e );
461485 }
462486 throw new RuntimeException ("Annotated woooops... " + receivedTopic );
@@ -488,7 +512,8 @@ public CompletableFuture<Void> listenWithAnnotation2(String message, @Header(Kaf
488512 container .countDownLatch52 .countDown ();
489513 try {
490514 Thread .sleep (1 );
491- } catch (InterruptedException e ) {
515+ }
516+ catch (InterruptedException e ) {
492517 throw new RuntimeException (e );
493518 }
494519 throw new RuntimeException ("Annotated woooops... " + receivedTopic );
@@ -511,13 +536,16 @@ static class SixthTopicDefaultDLTListener {
511536 CountDownLatchContainer container ;
512537
513538 @ KafkaHandler
514- public CompletableFuture <Void > listenNoDlt (String message , @ Header (KafkaHeaders .RECEIVED_TOPIC ) String receivedTopic ,
515- @ SuppressWarnings ("unused" ) Acknowledgment ack ) {
539+ public CompletableFuture <Void > listenNoDlt (
540+ String message ,
541+ @ Header (KafkaHeaders .RECEIVED_TOPIC ) String receivedTopic ,
542+ @ SuppressWarnings ("unused" ) Acknowledgment ack ) {
516543 return CompletableFuture .supplyAsync (() -> {
517544 container .countDownIfNotKnown (receivedTopic , container .countDownLatch6 );
518545 try {
519546 Thread .sleep (1 );
520- } catch (InterruptedException e ) {
547+ }
548+ catch (InterruptedException e ) {
521549 throw new RuntimeException (e );
522550 }
523551 throw new IllegalStateException ("Another woooops... " + receivedTopic );
@@ -545,7 +573,8 @@ public CompletableFuture<Object> listenWithAnnotation2(String message, @Header(K
545573 container .countDownIfNotKnown (receivedTopic , container .countDownLatchNoRetry );
546574 try {
547575 Thread .sleep (1 );
548- } catch (InterruptedException e ) {
576+ }
577+ catch (InterruptedException e ) {
549578 throw new RuntimeException (e );
550579 }
551580 throw new MyDontRetryException ("Annotated second woooops... " + receivedTopic );
@@ -579,7 +608,8 @@ public CompletableFuture<Void> listen1(String message, @Header(KafkaHeaders.RECE
579608 container .countDownLatchReuseOne .countDown ();
580609 try {
581610 Thread .sleep (1 );
582- } catch (InterruptedException e ) {
611+ }
612+ catch (InterruptedException e ) {
583613 throw new RuntimeException (e );
584614 }
585615 throw new RuntimeException ("Another woooops... " + receivedTopic );
@@ -609,7 +639,8 @@ public CompletableFuture<Void> listen2(String message, @Header(KafkaHeaders.RECE
609639 container .countDownLatchReuseTwo .countDown ();
610640 try {
611641 Thread .sleep (1 );
612- } catch (InterruptedException e ) {
642+ }
643+ catch (InterruptedException e ) {
613644 throw new RuntimeException (e );
614645 }
615646 throw new RuntimeException ("Another woooops... " + receivedTopic );
@@ -635,7 +666,8 @@ public CompletableFuture<Void> listen3(String message, @Header(KafkaHeaders.RECE
635666 container .countDownLatchReuseThree .countDown ();
636667 try {
637668 Thread .sleep (1 );
638- } catch (InterruptedException e ) {
669+ }
670+ catch (InterruptedException e ) {
639671 throw new RuntimeException (e );
640672 }
641673 throw new RuntimeException ("Another woooops... " + receivedTopic );
0 commit comments