Search in sources :

Example 6 with JCacheCacheManager

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

the class CacheAutoConfigurationTests method jCacheCacheWithConfig.

@Test
public void jCacheCacheWithConfig() throws IOException {
    String cachingProviderFqn = MockCachingProvider.class.getName();
    String configLocation = "org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml";
    load(JCacheCustomConfiguration.class, "spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn, "spring.cache.jcache.config=" + configLocation);
    JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
    Resource configResource = new ClassPathResource(configLocation);
    assertThat(cacheManager.getCacheManager().getURI()).isEqualTo(configResource.getURI());
}
Also used : Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) JCacheCacheManager(org.springframework.cache.jcache.JCacheCacheManager) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 7 with JCacheCacheManager

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

the class CacheAutoConfigurationTests method ehcache3AsJCacheWithConfig.

@Test
public void ehcache3AsJCacheWithConfig() throws IOException {
    String cachingProviderFqn = EhcacheCachingProvider.class.getName();
    String configLocation = "ehcache3.xml";
    load(DefaultCacheConfiguration.class, "spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn, "spring.cache.jcache.config=" + configLocation);
    JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
    Resource configResource = new ClassPathResource(configLocation);
    assertThat(cacheManager.getCacheManager().getURI()).isEqualTo(configResource.getURI());
    assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
}
Also used : Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) JCacheCacheManager(org.springframework.cache.jcache.JCacheCacheManager) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 8 with JCacheCacheManager

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

the class CacheAutoConfigurationTests method infinispanAsJCacheWithCaches.

@Test
public void infinispanAsJCacheWithCaches() {
    String cachingProviderFqn = JCachingProvider.class.getName();
    load(DefaultCacheConfiguration.class, "spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn, "spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar");
    JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
    assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
}
Also used : JCacheCacheManager(org.springframework.cache.jcache.JCacheCacheManager) Test(org.junit.Test)

Example 9 with JCacheCacheManager

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

the class CacheAutoConfigurationTests method jCacheCacheWithCachesAndCustomConfig.

@Test
public void jCacheCacheWithCachesAndCustomConfig() {
    String cachingProviderFqn = MockCachingProvider.class.getName();
    load(JCacheCustomConfiguration.class, "spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn, "spring.cache.cacheNames[0]=one", "spring.cache.cacheNames[1]=two");
    JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
    assertThat(cacheManager.getCacheNames()).containsOnly("one", "two");
    CompleteConfiguration<?, ?> defaultCacheConfiguration = this.context.getBean(CompleteConfiguration.class);
    verify(cacheManager.getCacheManager()).createCache("one", defaultCacheConfiguration);
    verify(cacheManager.getCacheManager()).createCache("two", defaultCacheConfiguration);
}
Also used : JCacheCacheManager(org.springframework.cache.jcache.JCacheCacheManager) Test(org.junit.Test)

Example 10 with JCacheCacheManager

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

the class CacheAutoConfigurationTests method hazelcastAsJCacheWithCaches.

@Test
public void hazelcastAsJCacheWithCaches() {
    String cachingProviderFqn = HazelcastCachingProvider.class.getName();
    try {
        load(DefaultCacheConfiguration.class, "spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn, "spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar");
        JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
        assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
        assertThat(Hazelcast.getAllHazelcastInstances()).hasSize(1);
    } finally {
        Caching.getCachingProvider(cachingProviderFqn).close();
    }
}
Also used : JCacheCacheManager(org.springframework.cache.jcache.JCacheCacheManager) Test(org.junit.Test)

Aggregations

JCacheCacheManager (org.springframework.cache.jcache.JCacheCacheManager)14 Test (org.junit.Test)13 ClassPathResource (org.springframework.core.io.ClassPathResource)4 Resource (org.springframework.core.io.Resource)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 HazelcastCacheManager (com.hazelcast.spring.cache.HazelcastCacheManager)1 CacheManager (javax.cache.CacheManager)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1