mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-10-04 00:09:01 +00:00
Take async cache writes into consideration
Since Spring Data Redis 4.0 and when using Lettuce, entries may be written to the cache asynchronously. This means that they may not be immediately visible to a subsequent read. This commit adapts the test to use Awaitility to wait for the expected entry to become visible in the cache. Closes gh-50356
This commit is contained in:
+8
-3
@@ -16,7 +16,10 @@
|
||||
|
||||
package smoketest.cache;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import com.redis.testcontainers.RedisContainer;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
@@ -52,9 +55,11 @@ class SampleCacheApplicationRedisTests {
|
||||
countries.clear(); // Simple test assuming the cache is empty
|
||||
assertThat(countries.get("BE")).isNull();
|
||||
Country be = this.countryRepository.findByCode("BE");
|
||||
ValueWrapper belgium = countries.get("BE");
|
||||
assertThat(belgium).isNotNull();
|
||||
assertThat((Country) belgium.get()).isEqualTo(be);
|
||||
Awaitility.waitAtMost(Duration.ofSeconds(10)).untilAsserted(() -> {
|
||||
ValueWrapper belgium = countries.get("BE");
|
||||
assertThat(belgium).isNotNull();
|
||||
assertThat((Country) belgium.get()).isEqualTo(be);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user