|
|
@ -105,38 +105,33 @@ public class CacheAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void noEnableCaching() {
|
|
|
|
public void noEnableCaching() {
|
|
|
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
|
|
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class).run(
|
|
|
|
.run((context) -> {
|
|
|
|
(context) -> assertThat(context).doesNotHaveBean(CacheManager.class));
|
|
|
|
assertThat(context).doesNotHaveBean(CacheManager.class);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void cacheManagerBackOff() {
|
|
|
|
public void cacheManagerBackOff() {
|
|
|
|
this.contextRunner.withUserConfiguration(CustomCacheManagerConfiguration.class)
|
|
|
|
this.contextRunner.withUserConfiguration(CustomCacheManagerConfiguration.class)
|
|
|
|
.run((context) -> {
|
|
|
|
.run((context) -> assertThat(
|
|
|
|
assertThat(getCacheManager(context, ConcurrentMapCacheManager.class)
|
|
|
|
getCacheManager(context, ConcurrentMapCacheManager.class)
|
|
|
|
.getCacheNames()).containsOnly("custom1");
|
|
|
|
.getCacheNames()).containsOnly("custom1"));
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void cacheManagerFromSupportBackOff() {
|
|
|
|
public void cacheManagerFromSupportBackOff() {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner
|
|
|
|
.withUserConfiguration(CustomCacheManagerFromSupportConfiguration.class)
|
|
|
|
.withUserConfiguration(CustomCacheManagerFromSupportConfiguration.class)
|
|
|
|
.run((context) -> {
|
|
|
|
.run((context) -> assertThat(
|
|
|
|
assertThat(getCacheManager(context, ConcurrentMapCacheManager.class)
|
|
|
|
getCacheManager(context, ConcurrentMapCacheManager.class)
|
|
|
|
.getCacheNames()).containsOnly("custom1");
|
|
|
|
.getCacheNames()).containsOnly("custom1"));
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void cacheResolverFromSupportBackOff() throws Exception {
|
|
|
|
public void cacheResolverFromSupportBackOff() throws Exception {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner
|
|
|
|
.withUserConfiguration(CustomCacheResolverFromSupportConfiguration.class)
|
|
|
|
.withUserConfiguration(CustomCacheResolverFromSupportConfiguration.class)
|
|
|
|
.run((context) -> {
|
|
|
|
.run((context) -> assertThat(context)
|
|
|
|
assertThat(context).doesNotHaveBean(CacheManager.class);
|
|
|
|
.doesNotHaveBean(CacheManager.class));
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -151,21 +146,19 @@ public class CacheAutoConfigurationTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void notSupportedCachingMode() {
|
|
|
|
public void notSupportedCachingMode() {
|
|
|
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
|
|
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
|
|
|
.withPropertyValues("spring.cache.type=foobar").run((context) -> {
|
|
|
|
.withPropertyValues("spring.cache.type=foobar")
|
|
|
|
assertThat(context).getFailure()
|
|
|
|
.run((context) -> assertThat(context).getFailure()
|
|
|
|
.isInstanceOf(BeanCreationException.class)
|
|
|
|
.isInstanceOf(BeanCreationException.class).hasMessageContaining(
|
|
|
|
.hasMessageContaining(
|
|
|
|
"Failed to bind properties under 'spring.cache.type'"));
|
|
|
|
"Failed to bind properties under 'spring.cache.type'");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void simpleCacheExplicit() {
|
|
|
|
public void simpleCacheExplicit() {
|
|
|
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
|
|
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
|
|
|
.withPropertyValues("spring.cache.type=simple").run((context) -> {
|
|
|
|
.withPropertyValues("spring.cache.type=simple")
|
|
|
|
assertThat(getCacheManager(context, ConcurrentMapCacheManager.class)
|
|
|
|
.run((context) -> assertThat(
|
|
|
|
.getCacheNames()).isEmpty();
|
|
|
|
getCacheManager(context, ConcurrentMapCacheManager.class)
|
|
|
|
});
|
|
|
|
.getCacheNames()).isEmpty());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -206,13 +199,11 @@ public class CacheAutoConfigurationTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void genericCacheExplicit() {
|
|
|
|
public void genericCacheExplicit() {
|
|
|
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
|
|
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
|
|
|
.withPropertyValues("spring.cache.type=generic").run((context) -> {
|
|
|
|
.withPropertyValues("spring.cache.type=generic")
|
|
|
|
assertThat(context).getFailure()
|
|
|
|
.run((context) -> assertThat(context).getFailure()
|
|
|
|
.isInstanceOf(BeanCreationException.class)
|
|
|
|
.isInstanceOf(BeanCreationException.class)
|
|
|
|
.hasMessageContaining(
|
|
|
|
.hasMessageContaining("No cache manager could be auto-configured")
|
|
|
|
"No cache manager could be auto-configured")
|
|
|
|
.hasMessageContaining("GENERIC"));
|
|
|
|
.hasMessageContaining("GENERIC");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -339,13 +330,11 @@ public class CacheAutoConfigurationTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void jCacheCacheNoProviderExplicit() {
|
|
|
|
public void jCacheCacheNoProviderExplicit() {
|
|
|
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
|
|
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
|
|
|
.withPropertyValues("spring.cache.type=jcache").run((context) -> {
|
|
|
|
.withPropertyValues("spring.cache.type=jcache")
|
|
|
|
assertThat(context).getFailure()
|
|
|
|
.run((context) -> assertThat(context).getFailure()
|
|
|
|
.isInstanceOf(BeanCreationException.class)
|
|
|
|
.isInstanceOf(BeanCreationException.class)
|
|
|
|
.hasMessageContaining(
|
|
|
|
.hasMessageContaining("No cache manager could be auto-configured")
|
|
|
|
"No cache manager could be auto-configured")
|
|
|
|
.hasMessageContaining("JCACHE"));
|
|
|
|
.hasMessageContaining("JCACHE");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -416,11 +405,9 @@ public class CacheAutoConfigurationTests {
|
|
|
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
|
|
|
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
|
|
|
|
.withPropertyValues("spring.cache.type=jcache",
|
|
|
|
.withPropertyValues("spring.cache.type=jcache",
|
|
|
|
"spring.cache.jcache.provider=" + wrongCachingProviderClassName)
|
|
|
|
"spring.cache.jcache.provider=" + wrongCachingProviderClassName)
|
|
|
|
.run((context) -> {
|
|
|
|
.run((context) -> assertThat(context).getFailure()
|
|
|
|
assertThat(context).getFailure()
|
|
|
|
.isInstanceOf(BeanCreationException.class)
|
|
|
|
.isInstanceOf(BeanCreationException.class)
|
|
|
|
.hasMessageContaining(wrongCachingProviderClassName));
|
|
|
|
.hasMessageContaining(wrongCachingProviderClassName);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -448,12 +435,10 @@ public class CacheAutoConfigurationTests {
|
|
|
|
.withPropertyValues("spring.cache.type=jcache",
|
|
|
|
.withPropertyValues("spring.cache.type=jcache",
|
|
|
|
"spring.cache.jcache.provider=" + cachingProviderFqn,
|
|
|
|
"spring.cache.jcache.provider=" + cachingProviderFqn,
|
|
|
|
"spring.cache.jcache.config=" + configLocation)
|
|
|
|
"spring.cache.jcache.config=" + configLocation)
|
|
|
|
.run((context) -> {
|
|
|
|
.run((context) -> assertThat(context).getFailure()
|
|
|
|
assertThat(context).getFailure()
|
|
|
|
.isInstanceOf(BeanCreationException.class)
|
|
|
|
.isInstanceOf(BeanCreationException.class)
|
|
|
|
.hasMessageContaining("does not exist")
|
|
|
|
.hasMessageContaining("does not exist")
|
|
|
|
.hasMessageContaining(configLocation));
|
|
|
|
.hasMessageContaining(configLocation);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -692,10 +677,9 @@ public class CacheAutoConfigurationTests {
|
|
|
|
.withPropertyValues("spring.cache.type=infinispan",
|
|
|
|
.withPropertyValues("spring.cache.type=infinispan",
|
|
|
|
"spring.cache.cacheNames[0]=foo",
|
|
|
|
"spring.cache.cacheNames[0]=foo",
|
|
|
|
"spring.cache.cacheNames[1]=bar")
|
|
|
|
"spring.cache.cacheNames[1]=bar")
|
|
|
|
.run((context) -> {
|
|
|
|
.run((context) -> assertThat(
|
|
|
|
assertThat(getCacheManager(context, SpringEmbeddedCacheManager.class)
|
|
|
|
getCacheManager(context, SpringEmbeddedCacheManager.class)
|
|
|
|
.getCacheNames()).containsOnly("foo", "bar");
|
|
|
|
.getCacheNames()).containsOnly("foo", "bar"));
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -719,10 +703,9 @@ public class CacheAutoConfigurationTests {
|
|
|
|
"spring.cache.jcache.provider=" + cachingProviderClassName,
|
|
|
|
"spring.cache.jcache.provider=" + cachingProviderClassName,
|
|
|
|
"spring.cache.cacheNames[0]=foo",
|
|
|
|
"spring.cache.cacheNames[0]=foo",
|
|
|
|
"spring.cache.cacheNames[1]=bar")
|
|
|
|
"spring.cache.cacheNames[1]=bar")
|
|
|
|
.run((context) -> {
|
|
|
|
.run((context) -> assertThat(
|
|
|
|
assertThat(getCacheManager(context, JCacheCacheManager.class)
|
|
|
|
getCacheManager(context, JCacheCacheManager.class)
|
|
|
|
.getCacheNames()).containsOnly("foo", "bar");
|
|
|
|
.getCacheNames()).containsOnly("foo", "bar"));
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -751,11 +734,10 @@ public class CacheAutoConfigurationTests {
|
|
|
|
"spring.cache.jcache.provider=" + cachingProviderClassName,
|
|
|
|
"spring.cache.jcache.provider=" + cachingProviderClassName,
|
|
|
|
"spring.cache.cacheNames[0]=foo",
|
|
|
|
"spring.cache.cacheNames[0]=foo",
|
|
|
|
"spring.cache.cacheNames[1]=bar")
|
|
|
|
"spring.cache.cacheNames[1]=bar")
|
|
|
|
.run((context) -> {
|
|
|
|
.run((context) ->
|
|
|
|
// see customizer
|
|
|
|
// see customizer
|
|
|
|
assertThat(getCacheManager(context, JCacheCacheManager.class)
|
|
|
|
assertThat(getCacheManager(context, JCacheCacheManager.class)
|
|
|
|
.getCacheNames()).containsOnly("foo", "custom1");
|
|
|
|
.getCacheNames()).containsOnly("foo", "custom1"));
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
finally {
|
|
|
|
Caching.getCachingProvider(cachingProviderClassName).close();
|
|
|
|
Caching.getCachingProvider(cachingProviderClassName).close();
|
|
|
|