19
19
import static org .assertj .core .api .Assumptions .*;
20
20
21
21
import reactor .core .publisher .Flux ;
22
+ import reactor .core .publisher .Mono ;
22
23
import reactor .test .StepVerifier ;
23
24
24
25
import java .time .Duration ;
27
28
import java .util .Collections ;
28
29
import java .util .HashMap ;
29
30
import java .util .Map ;
31
+ import java .util .function .Function ;
30
32
31
33
import org .junit .jupiter .api .BeforeEach ;
32
34
@@ -441,7 +443,29 @@ void listenToChannelShouldReceiveChannelMessagesCorrectly() throws InterruptedEx
441
443
442
444
redisTemplate .listenToChannel (channel ).as (StepVerifier ::create ) //
443
445
.thenAwait (Duration .ofMillis (500 )) // just make sure we the subscription completed
444
- .then (() -> redisTemplate .convertAndSend (channel , message ).block ()) //
446
+ .then (() -> redisTemplate .convertAndSend (channel , message ).subscribe ()) //
447
+ .assertNext (received -> {
448
+
449
+ assertThat (received ).isInstanceOf (ChannelMessage .class );
450
+ assertThat (received .getMessage ()).isEqualTo (message );
451
+ assertThat (received .getChannel ()).isEqualTo (channel );
452
+ }) //
453
+ .thenAwait (Duration .ofMillis (10 )) //
454
+ .thenCancel () //
455
+ .verify (Duration .ofSeconds (3 ));
456
+ }
457
+
458
+ @ ParameterizedRedisTest // GH-1622
459
+ @ EnabledIfLongRunningTest
460
+ void listenToLaterChannelShouldReceiveChannelMessagesCorrectly () {
461
+
462
+ String channel = "my-channel" ;
463
+
464
+ V message = valueFactory .instance ();
465
+
466
+ redisTemplate .listenToChannelLater (channel ) //
467
+ .doOnNext (it -> redisTemplate .convertAndSend (channel , message ).subscribe ()).flatMapMany (Function .identity ()) //
468
+ .as (StepVerifier ::create ) //
445
469
.assertNext (received -> {
446
470
447
471
assertThat (received ).isInstanceOf (ChannelMessage .class );
@@ -455,7 +479,7 @@ void listenToChannelShouldReceiveChannelMessagesCorrectly() throws InterruptedEx
455
479
456
480
@ ParameterizedRedisTest // DATAREDIS-612
457
481
@ EnabledIfLongRunningTest
458
- void listenToChannelPatternShouldReceiveChannelMessagesCorrectly () throws InterruptedException {
482
+ void listenToPatternShouldReceiveChannelMessagesCorrectly () {
459
483
460
484
String channel = "my-channel" ;
461
485
String pattern = "my-*" ;
@@ -466,7 +490,32 @@ void listenToChannelPatternShouldReceiveChannelMessagesCorrectly() throws Interr
466
490
467
491
stream .as (StepVerifier ::create ) //
468
492
.thenAwait (Duration .ofMillis (500 )) // just make sure we the subscription completed
469
- .then (() -> redisTemplate .convertAndSend (channel , message ).block ()) //
493
+ .then (() -> redisTemplate .convertAndSend (channel , message ).subscribe ()) //
494
+ .assertNext (received -> {
495
+
496
+ assertThat (received ).isInstanceOf (PatternMessage .class );
497
+ assertThat (received .getMessage ()).isEqualTo (message );
498
+ assertThat (received .getChannel ()).isEqualTo (channel );
499
+ assertThat (((PatternMessage ) received ).getPattern ()).isEqualTo (pattern );
500
+ }) //
501
+ .thenCancel () //
502
+ .verify (Duration .ofSeconds (3 ));
503
+ }
504
+
505
+ @ ParameterizedRedisTest // GH-1622
506
+ @ EnabledIfLongRunningTest
507
+ void listenToPatternLaterShouldReceiveChannelMessagesCorrectly () {
508
+
509
+ String channel = "my-channel" ;
510
+ String pattern = "my-*" ;
511
+
512
+ V message = valueFactory .instance ();
513
+
514
+ Mono <Flux <? extends Message <String , V >>> stream = redisTemplate .listenToPatternLater (pattern );
515
+
516
+ stream .doOnNext (it -> redisTemplate .convertAndSend (channel , message ).subscribe ()) //
517
+ .flatMapMany (Function .identity ()) //
518
+ .as (StepVerifier ::create ) //
470
519
.assertNext (received -> {
471
520
472
521
assertThat (received ).isInstanceOf (PatternMessage .class );
0 commit comments