|
|
@ -584,45 +584,52 @@ public class CacheAutoConfigurationTests {
|
|
|
|
validateGuavaCacheWithStats();
|
|
|
|
validateGuavaCacheWithStats();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void validateGuavaCacheWithStats() {
|
|
|
|
|
|
|
|
GuavaCacheManager cacheManager = validateCacheManager(GuavaCacheManager.class);
|
|
|
|
|
|
|
|
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
|
|
|
|
|
|
|
|
Cache foo = cacheManager.getCache("foo");
|
|
|
|
|
|
|
|
foo.get("1");
|
|
|
|
|
|
|
|
assertThat(((GuavaCache) foo).getNativeCache().stats().missCount()).isEqualTo(1L);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void caffeineCacheWithCaches() {
|
|
|
|
public void caffeineCacheWithExplicitCaches() {
|
|
|
|
load(DefaultCacheConfiguration.class, "spring.cache.type=caffeine",
|
|
|
|
load(DefaultCacheConfiguration.class, "spring.cache.type=caffeine",
|
|
|
|
"spring.cache.cacheNames[0]=spring", "spring.cache.cacheNames[1]=boot");
|
|
|
|
"spring.cache.cacheNames=foo");
|
|
|
|
CaffeineCacheManager cacheManager = validateCacheManager(
|
|
|
|
CaffeineCacheManager cacheManager = validateCacheManager(
|
|
|
|
CaffeineCacheManager.class);
|
|
|
|
CaffeineCacheManager.class);
|
|
|
|
assertThat(cacheManager.getCacheNames()).containsOnly("spring", "boot");
|
|
|
|
assertThat(cacheManager.getCacheNames()).containsOnly("foo");
|
|
|
|
|
|
|
|
Cache foo = cacheManager.getCache("foo");
|
|
|
|
|
|
|
|
foo.get("1");
|
|
|
|
|
|
|
|
// See next tests: no spec given so stats should be disabled
|
|
|
|
|
|
|
|
assertThat(((CaffeineCache) foo).getNativeCache().stats().missCount()).isEqualTo(0L);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void caffeineCacheNotAllowNullValues() {
|
|
|
|
public void caffeineCacheWithCustomizers() {
|
|
|
|
load(DefaultCacheConfiguration.class, "spring.cache.type=caffeine",
|
|
|
|
testCustomizers(DefaultCacheAndCustomizersConfiguration.class, "caffeine",
|
|
|
|
"spring.cache.caffeine.allow-null-values=false");
|
|
|
|
"allCacheManagerCustomizer", "caffeineCacheManagerCustomizer");
|
|
|
|
CaffeineCacheManager cacheManager = validateCacheManager(
|
|
|
|
|
|
|
|
CaffeineCacheManager.class);
|
|
|
|
|
|
|
|
assertThat(cacheManager.isAllowNullValues()).isFalse();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void caffeineCacheWithNullCaches() {
|
|
|
|
public void caffeineCacheWithExplicitCacheBuilder() {
|
|
|
|
load(CaffeineCacheBuilderConfiguration.class, "spring.cache.type=caffeine",
|
|
|
|
load(CaffeineCacheBuilderConfiguration.class, "spring.cache.type=caffeine",
|
|
|
|
"spring.cache.cacheNames[0]=caffeine", "spring.cache.cacheNames[1]=cache");
|
|
|
|
"spring.cache.cacheNames=foo,bar");
|
|
|
|
CaffeineCacheManager cacheManager = validateCacheManager(
|
|
|
|
validateCaffeineCacheWithStats();
|
|
|
|
CaffeineCacheManager.class);
|
|
|
|
|
|
|
|
assertThat(cacheManager.isAllowNullValues()).isTrue();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void caffeineCacheExplicitWithSpec() {
|
|
|
|
public void caffeineCacheExplicitWithSpec() {
|
|
|
|
load(DefaultCacheConfiguration.class, "spring.cache.type=caffeine",
|
|
|
|
load(CaffeineCacheSpecConfiguration.class, "spring.cache.type=caffeine",
|
|
|
|
"spring.cache.caffeine.spec=recordStats", "spring.cache.cacheNames[0]=foo",
|
|
|
|
"spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar");
|
|
|
|
"spring.cache.cacheNames[1]=bar");
|
|
|
|
|
|
|
|
validateCaffeineCacheWithStats();
|
|
|
|
validateCaffeineCacheWithStats();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void caffeineCacheExplicitWithCacheBuilder() {
|
|
|
|
public void caffeineCacheExplicitWithSpecString() {
|
|
|
|
load(CaffeineCacheBuilderConfiguration2.class, "spring.cache.type=caffeine",
|
|
|
|
load(DefaultCacheConfiguration.class, "spring.cache.type=caffeine",
|
|
|
|
"spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar");
|
|
|
|
"spring.cache.caffeine.spec=recordStats", "spring.cache.cacheNames[0]=foo",
|
|
|
|
|
|
|
|
"spring.cache.cacheNames[1]=bar");
|
|
|
|
validateCaffeineCacheWithStats();
|
|
|
|
validateCaffeineCacheWithStats();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -634,14 +641,6 @@ public class CacheAutoConfigurationTests {
|
|
|
|
assertThat(((CaffeineCache) foo).getNativeCache().stats().missCount()).isEqualTo(1L);
|
|
|
|
assertThat(((CaffeineCache) foo).getNativeCache().stats().missCount()).isEqualTo(1L);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void validateGuavaCacheWithStats() {
|
|
|
|
|
|
|
|
GuavaCacheManager cacheManager = validateCacheManager(GuavaCacheManager.class);
|
|
|
|
|
|
|
|
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
|
|
|
|
|
|
|
|
Cache foo = cacheManager.getCache("foo");
|
|
|
|
|
|
|
|
foo.get("1");
|
|
|
|
|
|
|
|
assertThat(((GuavaCache) foo).getNativeCache().stats().missCount()).isEqualTo(1L);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private <T extends CacheManager> T validateCacheManager(Class<T> type) {
|
|
|
|
private <T extends CacheManager> T validateCacheManager(Class<T> type) {
|
|
|
|
CacheManager cacheManager = this.context.getBean(CacheManager.class);
|
|
|
|
CacheManager cacheManager = this.context.getBean(CacheManager.class);
|
|
|
|
assertThat(cacheManager).as("Wrong cache manager type").isInstanceOf(type);
|
|
|
|
assertThat(cacheManager).as("Wrong cache manager type").isInstanceOf(type);
|
|
|
@ -897,14 +896,14 @@ public class CacheAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
Caffeine<Object, Object> cacheBuilder() {
|
|
|
|
Caffeine<Object, Object> cacheBuilder() {
|
|
|
|
return Caffeine.newBuilder().maximumSize(10);
|
|
|
|
return Caffeine.newBuilder().recordStats();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
@EnableCaching
|
|
|
|
@EnableCaching
|
|
|
|
static class CaffeineCacheBuilderConfiguration2 {
|
|
|
|
static class CaffeineCacheSpecConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
CaffeineSpec caffeineSpec() {
|
|
|
|
CaffeineSpec caffeineSpec() {
|
|
|
@ -964,6 +963,12 @@ public class CacheAutoConfigurationTests {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
|
|
|
public CacheManagerCustomizer<CaffeineCacheManager> caffeineCacheManagerCustomizer() {
|
|
|
|
|
|
|
|
return new CacheManagerTestCustomizer<CaffeineCacheManager>() {
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static abstract class CacheManagerTestCustomizer<T extends CacheManager>
|
|
|
|
static abstract class CacheManagerTestCustomizer<T extends CacheManager>
|
|
|
|