15
15
*/
16
16
package org .springframework .data .redis .cache ;
17
17
18
- import static org .assertj .core .api .Assertions .*;
19
- import static org .awaitility .Awaitility .*;
18
+ import static org .assertj .core .api .Assertions .assertThat ;
19
+ import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
20
+ import static org .assertj .core .api .Assertions .assertThatIllegalStateException ;
21
+ import static org .awaitility .Awaitility .await ;
20
22
21
23
import io .netty .util .concurrent .DefaultThreadFactory ;
22
24
@@ -573,10 +575,16 @@ void cacheGetWithTimeToIdleExpirationAfterEntryExpiresShouldReturnNull() {
573
575
void retrieveCacheValueUsingJedis () {
574
576
575
577
assertThatExceptionOfType (UnsupportedOperationException .class )
576
- .isThrownBy (() -> this .cache .retrieve (this .binaryCacheKey )).withMessageContaining ("RedisCache" );
578
+ .isThrownBy (() -> this .cache .retrieve (this .binaryCacheKey , () -> usingCompletedFuture ("TEST" )))
579
+ .withMessageContaining ("RedisCache" );
580
+ }
581
+
582
+ @ ParameterizedRedisTest // GH-2650
583
+ @ EnabledOnRedisDriver (RedisDriver .JEDIS )
584
+ void retrieveLoadedValueUsingJedis () {
577
585
578
586
assertThatExceptionOfType (UnsupportedOperationException .class )
579
- .isThrownBy (() -> this .cache .retrieve (this .binaryCacheKey , () -> CompletableFuture . completedFuture ("TEST" )))
587
+ .isThrownBy (() -> this .cache .retrieve (this .binaryCacheKey , () -> usingCompletedFuture ("TEST" )))
580
588
.withMessageContaining ("RedisCache" );
581
589
}
582
590
@@ -611,9 +619,11 @@ void retrieveReturnsCachedValueWhenLockIsReleased() throws Exception {
611
619
usingRedisCacheConfiguration ());
612
620
613
621
DefaultRedisCacheWriter cacheWriter = (DefaultRedisCacheWriter ) cache .getCacheWriter ();
622
+
614
623
cacheWriter .lock ("cache" );
615
624
616
625
CompletableFuture <String > value = (CompletableFuture <String >) cache .retrieve (this .key );
626
+
617
627
assertThat (value ).isNotDone ();
618
628
619
629
cacheWriter .unlock ("cache" );
@@ -626,11 +636,12 @@ void retrieveReturnsCachedValueWhenLockIsReleased() throws Exception {
626
636
@ EnabledOnRedisDriver (RedisDriver .LETTUCE )
627
637
void retrieveReturnsLoadedValue () throws Exception {
628
638
629
- RedisCache cache = new RedisCache ("cache" , usingLockingRedisCacheWriter (), usingRedisCacheConfiguration ());
630
639
AtomicBoolean loaded = new AtomicBoolean (false );
631
640
Person jon = new Person ("Jon" , Date .from (Instant .now ()));
632
641
CompletableFuture <Person > valueLoader = CompletableFuture .completedFuture (jon );
633
642
643
+ RedisCache cache = new RedisCache ("cache" , usingLockingRedisCacheWriter (), usingRedisCacheConfiguration ());
644
+
634
645
Supplier <CompletableFuture <Person >> valueLoaderSupplier = () -> {
635
646
loaded .set (true );
636
647
return valueLoader ;
@@ -648,15 +659,15 @@ void retrieveReturnsLoadedValue() throws Exception {
648
659
@ EnabledOnRedisDriver (RedisDriver .LETTUCE )
649
660
void retrieveStoresLoadedValue () throws Exception {
650
661
651
- RedisCache cache = new RedisCache ("cache" , usingLockingRedisCacheWriter (), usingRedisCacheConfiguration ());
652
662
Person jon = new Person ("Jon" , Date .from (Instant .now ()));
653
663
Supplier <CompletableFuture <Person >> valueLoaderSupplier = () -> CompletableFuture .completedFuture (jon );
654
664
665
+ RedisCache cache = new RedisCache ("cache" , usingLockingRedisCacheWriter (), usingRedisCacheConfiguration ());
666
+
655
667
cache .retrieve (this .key , valueLoaderSupplier ).get ();
656
668
657
- doWithConnection (
658
- connection -> assertThat (connection .keyCommands ().exists ("cache::key-1" .getBytes (StandardCharsets .UTF_8 )))
659
- .isTrue ());
669
+ doWithConnection (connection ->
670
+ assertThat (connection .keyCommands ().exists ("cache::key-1" .getBytes (StandardCharsets .UTF_8 ))).isTrue ());
660
671
}
661
672
662
673
@ ParameterizedRedisTest // GH-2650
@@ -674,6 +685,10 @@ void retrieveReturnsNull() throws Exception {
674
685
assertThat (value ).isDone ();
675
686
}
676
687
688
+ private <T > CompletableFuture <T > usingCompletedFuture (T value ) {
689
+ return CompletableFuture .completedFuture (value );
690
+ }
691
+
677
692
private RedisCacheConfiguration usingRedisCacheConfiguration () {
678
693
return usingRedisCacheConfiguration (Function .identity ());
679
694
}
0 commit comments