Search in sources :

Example 11 with CacheManager

use of org.springframework.cache.CacheManager in project spring-boot by spring-projects.

the class AbstractCacheAutoConfigurationTests method getCacheManager.

protected <T extends CacheManager> T getCacheManager(AssertableApplicationContext loaded, Class<T> type) {
    CacheManager cacheManager = loaded.getBean(CacheManager.class);
    assertThat(cacheManager).as("Wrong cache manager type").isInstanceOf(type);
    return type.cast(cacheManager);
}
Also used : CaffeineCacheManager(org.springframework.cache.caffeine.CaffeineCacheManager) SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) CouchbaseCacheManager(org.springframework.data.couchbase.cache.CouchbaseCacheManager) RedisCacheManager(org.springframework.data.redis.cache.RedisCacheManager) ConcurrentMapCacheManager(org.springframework.cache.concurrent.ConcurrentMapCacheManager) HazelcastCacheManager(com.hazelcast.spring.cache.HazelcastCacheManager) CacheManager(org.springframework.cache.CacheManager)

Example 12 with CacheManager

use of org.springframework.cache.CacheManager in project spring-boot by spring-projects.

the class AutoConfigureCacheWithExistingCacheManagerIntegrationTests method shouldNotReplaceExistingCacheManager.

@Test
void shouldNotReplaceExistingCacheManager() {
    CacheManager bean = this.applicationContext.getBean(CacheManager.class);
    assertThat(bean).isInstanceOf(ConcurrentMapCacheManager.class);
}
Also used : CacheManager(org.springframework.cache.CacheManager) ConcurrentMapCacheManager(org.springframework.cache.concurrent.ConcurrentMapCacheManager) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with CacheManager

use of org.springframework.cache.CacheManager in project spring-boot by spring-projects.

the class AutoConfigureCacheIntegrationTests method shouldConfigureNoOpCacheManager.

@Test
void shouldConfigureNoOpCacheManager() {
    CacheManager bean = this.applicationContext.getBean(CacheManager.class);
    assertThat(bean).isInstanceOf(NoOpCacheManager.class);
}
Also used : NoOpCacheManager(org.springframework.cache.support.NoOpCacheManager) CacheManager(org.springframework.cache.CacheManager) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with CacheManager

use of org.springframework.cache.CacheManager in project spring-boot by spring-projects.

the class CachesEndpointTests method namedCacheWithSeveralCacheManagers.

@Test
void namedCacheWithSeveralCacheManagers() {
    Map<String, CacheManager> cacheManagers = new LinkedHashMap<>();
    cacheManagers.put("test", new ConcurrentMapCacheManager("b", "dupe-cache"));
    cacheManagers.put("another", new ConcurrentMapCacheManager("c", "dupe-cache"));
    CachesEndpoint endpoint = new CachesEndpoint(cacheManagers);
    assertThatExceptionOfType(NonUniqueCacheException.class).isThrownBy(() -> endpoint.cache("dupe-cache", null)).withMessageContaining("dupe-cache").withMessageContaining("test").withMessageContaining("another");
}
Also used : ConcurrentMapCacheManager(org.springframework.cache.concurrent.ConcurrentMapCacheManager) SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) ConcurrentMapCacheManager(org.springframework.cache.concurrent.ConcurrentMapCacheManager) CacheManager(org.springframework.cache.CacheManager) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 15 with CacheManager

use of org.springframework.cache.CacheManager in project spring-boot by spring-projects.

the class CachesEndpointTests method allCachesWithSeveralCacheManagers.

@Test
void allCachesWithSeveralCacheManagers() {
    Map<String, CacheManager> cacheManagers = new LinkedHashMap<>();
    cacheManagers.put("test", new ConcurrentMapCacheManager("a", "b"));
    cacheManagers.put("another", new ConcurrentMapCacheManager("a", "c"));
    CachesEndpoint endpoint = new CachesEndpoint(cacheManagers);
    Map<String, CacheManagerDescriptor> allDescriptors = endpoint.caches().getCacheManagers();
    assertThat(allDescriptors).containsOnlyKeys("test", "another");
    assertThat(allDescriptors.get("test").getCaches()).containsOnlyKeys("a", "b");
    assertThat(allDescriptors.get("another").getCaches()).containsOnlyKeys("a", "c");
}
Also used : CacheManagerDescriptor(org.springframework.boot.actuate.cache.CachesEndpoint.CacheManagerDescriptor) ConcurrentMapCacheManager(org.springframework.cache.concurrent.ConcurrentMapCacheManager) SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) ConcurrentMapCacheManager(org.springframework.cache.concurrent.ConcurrentMapCacheManager) CacheManager(org.springframework.cache.CacheManager) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Aggregations

CacheManager (org.springframework.cache.CacheManager)28 Test (org.junit.jupiter.api.Test)12 ConcurrentMapCacheManager (org.springframework.cache.concurrent.ConcurrentMapCacheManager)10 SimpleCacheManager (org.springframework.cache.support.SimpleCacheManager)10 Cache (org.springframework.cache.Cache)8 LinkedHashMap (java.util.LinkedHashMap)5 HazelcastCacheManager (com.hazelcast.spring.cache.HazelcastCacheManager)4 CaffeineCacheManager (org.springframework.cache.caffeine.CaffeineCacheManager)4 EhCacheCacheManager (org.springframework.cache.ehcache.EhCacheCacheManager)4 NoOpCacheManager (org.springframework.cache.support.NoOpCacheManager)4 RedisCacheManager (org.springframework.data.redis.cache.RedisCacheManager)4 JCacheCacheManager (org.springframework.cache.jcache.JCacheCacheManager)3 CouchbaseCacheManager (com.couchbase.client.spring.cache.CouchbaseCacheManager)2 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 SpringEmbeddedCacheManager (org.infinispan.spring.provider.SpringEmbeddedCacheManager)2 CacheEntry (org.springframework.boot.actuate.cache.CachesEndpoint.CacheEntry)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2