@@ -398,6 +398,26 @@ public void testGoodDefaultReplyHeaders() throws Exception {
398
398
}
399
399
}
400
400
401
+ @ Test
402
+ public void testGoodDefaultReplyHeadersStringCorrelation () throws Exception {
403
+ ReplyingKafkaTemplate <Integer , String , String > template = createTemplate (
404
+ new TopicPartitionOffset (A_REPLY , 3 ));
405
+ try {
406
+ template .setDefaultReplyTimeout (Duration .ofSeconds (30 ));
407
+ template .setBinaryCorrelation (false );
408
+ ProducerRecord <Integer , String > record = new ProducerRecord <>(A_REQUEST , "bar" );
409
+ RequestReplyFuture <Integer , String , String > future = template .sendAndReceive (record );
410
+ future .getSendFuture ().get (10 , TimeUnit .SECONDS ); // send ok
411
+ ConsumerRecord <Integer , String > consumerRecord = future .get (30 , TimeUnit .SECONDS );
412
+ assertThat (consumerRecord .value ()).isEqualTo ("BAR" );
413
+ assertThat (consumerRecord .partition ()).isEqualTo (3 );
414
+ }
415
+ finally {
416
+ template .stop ();
417
+ template .destroy ();
418
+ }
419
+ }
420
+
401
421
@ Test
402
422
public void testGoodSamePartition () throws Exception {
403
423
ReplyingKafkaTemplate <Integer , String , String > template = createTemplate (A_REPLY );
@@ -472,6 +492,35 @@ public void testAggregateNormal() throws Exception {
472
492
}
473
493
}
474
494
495
+ @ Test
496
+ public void testAggregateNormalStringCorrelation () throws Exception {
497
+ AggregatingReplyingKafkaTemplate <Integer , String , String > template = aggregatingTemplate (
498
+ new TopicPartitionOffset (D_REPLY , 0 ), 2 , new AtomicInteger ());
499
+ try {
500
+ template .setCorrelationHeaderName ("customCorrelation" );
501
+ template .setBinaryCorrelation (false );
502
+ template .setDefaultReplyTimeout (Duration .ofSeconds (30 ));
503
+ ProducerRecord <Integer , String > record = new ProducerRecord <>(D_REQUEST , null , null , null , "foo" );
504
+ RequestReplyFuture <Integer , String , Collection <ConsumerRecord <Integer , String >>> future =
505
+ template .sendAndReceive (record );
506
+ future .getSendFuture ().get (10 , TimeUnit .SECONDS ); // send ok
507
+ ConsumerRecord <Integer , Collection <ConsumerRecord <Integer , String >>> consumerRecord =
508
+ future .get (30 , TimeUnit .SECONDS );
509
+ assertThat (consumerRecord .value ().size ()).isEqualTo (2 );
510
+ Iterator <ConsumerRecord <Integer , String >> iterator = consumerRecord .value ().iterator ();
511
+ String value1 = iterator .next ().value ();
512
+ assertThat (value1 ).isIn ("fOO" , "FOO" );
513
+ String value2 = iterator .next ().value ();
514
+ assertThat (value2 ).isIn ("fOO" , "FOO" );
515
+ assertThat (value2 ).isNotSameAs (value1 );
516
+ assertThat (consumerRecord .topic ()).isEqualTo (AggregatingReplyingKafkaTemplate .AGGREGATED_RESULTS_TOPIC );
517
+ }
518
+ finally {
519
+ template .stop ();
520
+ template .destroy ();
521
+ }
522
+ }
523
+
475
524
@ SuppressWarnings ("unchecked" )
476
525
@ Test
477
526
@ Disabled ("time sensitive" )
@@ -480,6 +529,7 @@ public void testAggregateTimeout() throws Exception {
480
529
new TopicPartitionOffset (E_REPLY , 0 ), 3 , new AtomicInteger ());
481
530
try {
482
531
template .setDefaultReplyTimeout (Duration .ofSeconds (5 ));
532
+ template .setCorrelationHeaderName ("customCorrelation" );
483
533
ProducerRecord <Integer , String > record = new ProducerRecord <>(E_REQUEST , null , null , null , "foo" );
484
534
RequestReplyFuture <Integer , String , Collection <ConsumerRecord <Integer , String >>> future =
485
535
template .sendAndReceive (record );
@@ -508,14 +558,47 @@ public void testAggregateTimeout() throws Exception {
508
558
}
509
559
510
560
@ Test
511
- @ Disabled ("time sensitive" )
512
561
public void testAggregateTimeoutPartial () throws Exception {
513
562
AtomicInteger releaseCount = new AtomicInteger ();
514
563
AggregatingReplyingKafkaTemplate <Integer , String , String > template = aggregatingTemplate (
515
564
new TopicPartitionOffset (F_REPLY , 0 ), 3 , releaseCount );
516
565
template .setReturnPartialOnTimeout (true );
517
566
try {
518
567
template .setDefaultReplyTimeout (Duration .ofSeconds (5 ));
568
+ template .setCorrelationHeaderName ("customCorrelation" );
569
+ ProducerRecord <Integer , String > record = new ProducerRecord <>(F_REQUEST , null , null , null , "foo" );
570
+ RequestReplyFuture <Integer , String , Collection <ConsumerRecord <Integer , String >>> future =
571
+ template .sendAndReceive (record );
572
+ future .getSendFuture ().get (10 , TimeUnit .SECONDS ); // send ok
573
+ ConsumerRecord <Integer , Collection <ConsumerRecord <Integer , String >>> consumerRecord =
574
+ future .get (30 , TimeUnit .SECONDS );
575
+ assertThat (consumerRecord .value ().size ()).isEqualTo (2 );
576
+ Iterator <ConsumerRecord <Integer , String >> iterator = consumerRecord .value ().iterator ();
577
+ String value1 = iterator .next ().value ();
578
+ assertThat (value1 ).isIn ("fOO" , "FOO" );
579
+ String value2 = iterator .next ().value ();
580
+ assertThat (value2 ).isIn ("fOO" , "FOO" );
581
+ assertThat (value2 ).isNotSameAs (value1 );
582
+ assertThat (consumerRecord .topic ())
583
+ .isEqualTo (AggregatingReplyingKafkaTemplate .PARTIAL_RESULTS_AFTER_TIMEOUT_TOPIC );
584
+ assertThat (releaseCount .get ()).isEqualTo (3 );
585
+ }
586
+ finally {
587
+ template .stop ();
588
+ template .destroy ();
589
+ }
590
+ }
591
+
592
+ @ Test
593
+ public void testAggregateTimeoutPartialStringCorrelation () throws Exception {
594
+ AtomicInteger releaseCount = new AtomicInteger ();
595
+ AggregatingReplyingKafkaTemplate <Integer , String , String > template = aggregatingTemplate (
596
+ new TopicPartitionOffset (F_REPLY , 0 ), 3 , releaseCount );
597
+ template .setReturnPartialOnTimeout (true );
598
+ template .setBinaryCorrelation (false );
599
+ try {
600
+ template .setDefaultReplyTimeout (Duration .ofSeconds (5 ));
601
+ template .setCorrelationHeaderName ("customCorrelation" );
519
602
ProducerRecord <Integer , String > record = new ProducerRecord <>(F_REQUEST , null , null , null , "foo" );
520
603
RequestReplyFuture <Integer , String , Collection <ConsumerRecord <Integer , String >>> future =
521
604
template .sendAndReceive (record );
@@ -531,7 +614,7 @@ public void testAggregateTimeoutPartial() throws Exception {
531
614
assertThat (value2 ).isNotSameAs (value1 );
532
615
assertThat (consumerRecord .topic ())
533
616
.isEqualTo (AggregatingReplyingKafkaTemplate .PARTIAL_RESULTS_AFTER_TIMEOUT_TOPIC );
534
- assertThat (releaseCount .get ()).isEqualTo (2 );
617
+ assertThat (releaseCount .get ()).isEqualTo (3 );
535
618
}
536
619
finally {
537
620
template .stop ();
@@ -654,7 +737,7 @@ public AggregatingReplyingKafkaTemplate<Integer, String, String> aggregatingTemp
654
737
new AggregatingReplyingKafkaTemplate <>(this .config .pf (), container ,
655
738
(list , timeout ) -> {
656
739
releaseCount .incrementAndGet ();
657
- return list .size () == releaseSize ;
740
+ return list .size () == releaseSize || timeout ;
658
741
});
659
742
template .setSharedReplyTopic (true );
660
743
template .start ();
0 commit comments