Search in sources :

Example 1 with JCacheCacheManager

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

the class CacheAutoConfigurationTests method jCacheCacheWithProvider.

@Test
public void jCacheCacheWithProvider() {
    String cachingProviderFqn = MockCachingProvider.class.getName();
    load(DefaultCacheConfiguration.class, "spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn);
    JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
    assertThat(cacheManager.getCacheNames()).isEmpty();
    assertThat(this.context.getBean(javax.cache.CacheManager.class)).isEqualTo(cacheManager.getCacheManager());
}
Also used : JCacheCacheManager(org.springframework.cache.jcache.JCacheCacheManager) Test(org.junit.Test)

Example 2 with JCacheCacheManager

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

the class CacheAutoConfigurationTests method hazelcastAsJCacheWithExistingHazelcastInstance.

@Test
public void hazelcastAsJCacheWithExistingHazelcastInstance() throws IOException {
    String cachingProviderFqn = HazelcastCachingProvider.class.getName();
    load(new Class[] { HazelcastAutoConfiguration.class, DefaultCacheConfiguration.class }, "spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn);
    JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
    javax.cache.CacheManager jCacheManager = cacheManager.getCacheManager();
    assertThat(jCacheManager).isInstanceOf(com.hazelcast.cache.HazelcastCacheManager.class);
    assertThat(this.context.getBeansOfType(HazelcastInstance.class)).hasSize(1);
    HazelcastInstance hazelcastInstance = this.context.getBean(HazelcastInstance.class);
    assertThat(((com.hazelcast.cache.HazelcastCacheManager) jCacheManager).getHazelcastInstance()).isSameAs(hazelcastInstance);
    assertThat(hazelcastInstance.getName()).isEqualTo("default-instance");
    assertThat(Hazelcast.getAllHazelcastInstances()).hasSize(1);
}
Also used : HazelcastCacheManager(com.hazelcast.spring.cache.HazelcastCacheManager) HazelcastInstance(com.hazelcast.core.HazelcastInstance) JCacheCacheManager(org.springframework.cache.jcache.JCacheCacheManager) Test(org.junit.Test)

Example 3 with JCacheCacheManager

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

the class CacheAutoConfigurationTests method jCacheCacheWithCachesAndCustomizer.

@Test
public void jCacheCacheWithCachesAndCustomizer() {
    String cachingProviderFqn = HazelcastCachingProvider.class.getName();
    try {
        load(JCacheWithCustomizerConfiguration.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);
        // see customizer
        assertThat(cacheManager.getCacheNames()).containsOnly("foo", "custom1");
    } finally {
        Caching.getCachingProvider(cachingProviderFqn).close();
    }
}
Also used : JCacheCacheManager(org.springframework.cache.jcache.JCacheCacheManager) Test(org.junit.Test)

Example 4 with JCacheCacheManager

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

the class CacheAutoConfigurationTests method hazelcastAsJCacheWithConfig.

@Test
public void hazelcastAsJCacheWithConfig() throws IOException {
    String cachingProviderFqn = HazelcastCachingProvider.class.getName();
    try {
        String configLocation = "org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.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(Hazelcast.getAllHazelcastInstances()).hasSize(1);
    } finally {
        Caching.getCachingProvider(cachingProviderFqn).close();
    }
}
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 5 with JCacheCacheManager

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

the class CacheAutoConfigurationTests method jCacheCacheWithCaches.

@Test
public void jCacheCacheWithCaches() {
    String cachingProviderFqn = MockCachingProvider.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)

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