1515 */
1616package org .springframework .data .redis .cache ;
1717
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 ;
2022
2123import io .netty .util .concurrent .DefaultThreadFactory ;
2224
@@ -573,10 +575,16 @@ void cacheGetWithTimeToIdleExpirationAfterEntryExpiresShouldReturnNull() {
573575 void retrieveCacheValueUsingJedis () {
574576
575577 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 () {
577585
578586 assertThatExceptionOfType (UnsupportedOperationException .class )
579- .isThrownBy (() -> this .cache .retrieve (this .binaryCacheKey , () -> CompletableFuture . completedFuture ("TEST" )))
587+ .isThrownBy (() -> this .cache .retrieve (this .binaryCacheKey , () -> usingCompletedFuture ("TEST" )))
580588 .withMessageContaining ("RedisCache" );
581589 }
582590
@@ -611,9 +619,11 @@ void retrieveReturnsCachedValueWhenLockIsReleased() throws Exception {
611619 usingRedisCacheConfiguration ());
612620
613621 DefaultRedisCacheWriter cacheWriter = (DefaultRedisCacheWriter ) cache .getCacheWriter ();
622+
614623 cacheWriter .lock ("cache" );
615624
616625 CompletableFuture <String > value = (CompletableFuture <String >) cache .retrieve (this .key );
626+
617627 assertThat (value ).isNotDone ();
618628
619629 cacheWriter .unlock ("cache" );
@@ -626,11 +636,12 @@ void retrieveReturnsCachedValueWhenLockIsReleased() throws Exception {
626636 @ EnabledOnRedisDriver (RedisDriver .LETTUCE )
627637 void retrieveReturnsLoadedValue () throws Exception {
628638
629- RedisCache cache = new RedisCache ("cache" , usingLockingRedisCacheWriter (), usingRedisCacheConfiguration ());
630639 AtomicBoolean loaded = new AtomicBoolean (false );
631640 Person jon = new Person ("Jon" , Date .from (Instant .now ()));
632641 CompletableFuture <Person > valueLoader = CompletableFuture .completedFuture (jon );
633642
643+ RedisCache cache = new RedisCache ("cache" , usingLockingRedisCacheWriter (), usingRedisCacheConfiguration ());
644+
634645 Supplier <CompletableFuture <Person >> valueLoaderSupplier = () -> {
635646 loaded .set (true );
636647 return valueLoader ;
@@ -648,15 +659,15 @@ void retrieveReturnsLoadedValue() throws Exception {
648659 @ EnabledOnRedisDriver (RedisDriver .LETTUCE )
649660 void retrieveStoresLoadedValue () throws Exception {
650661
651- RedisCache cache = new RedisCache ("cache" , usingLockingRedisCacheWriter (), usingRedisCacheConfiguration ());
652662 Person jon = new Person ("Jon" , Date .from (Instant .now ()));
653663 Supplier <CompletableFuture <Person >> valueLoaderSupplier = () -> CompletableFuture .completedFuture (jon );
654664
665+ RedisCache cache = new RedisCache ("cache" , usingLockingRedisCacheWriter (), usingRedisCacheConfiguration ());
666+
655667 cache .retrieve (this .key , valueLoaderSupplier ).get ();
656668
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 ());
660671 }
661672
662673 @ ParameterizedRedisTest // GH-2650
@@ -674,6 +685,10 @@ void retrieveReturnsNull() throws Exception {
674685 assertThat (value ).isDone ();
675686 }
676687
688+ private <T > CompletableFuture <T > usingCompletedFuture (T value ) {
689+ return CompletableFuture .completedFuture (value );
690+ }
691+
677692 private RedisCacheConfiguration usingRedisCacheConfiguration () {
678693 return usingRedisCacheConfiguration (Function .identity ());
679694 }
0 commit comments