Add cache abstraction tests using JSR-107
This commit adds an extra test implementation that runs the cache abstraction tests using a JSR-107 cache manager. This further covers JCacheCacheManager. The actual JSR-107 implementation is ehcache-jcache that requires at least ehcache 2.8.3. Since the ehcache-core artifact is no longer a public artifact, this commit switches to the full ehcache library, that is net.sf.ehcache:ehcache
This commit is contained in:
@@ -15,6 +15,8 @@ configure(allprojects) { project ->
|
||||
|
||||
ext.aspectjVersion = "1.8.1"
|
||||
ext.eclipseLinkVersion = "2.4.2"
|
||||
ext.ehcacheVersion = "2.8.3"
|
||||
ext.ehcacheJCacheVersion = "1.0.0"
|
||||
ext.groovyVersion = "2.3.3"
|
||||
ext.hibernate3Version = "3.6.10.Final"
|
||||
ext.hibernate4Version = "4.3.5.Final"
|
||||
@@ -578,7 +580,7 @@ project("spring-context-support") {
|
||||
optional("javax.mail:javax.mail-api:1.5.2")
|
||||
optional("javax.cache:cache-api:1.0.0")
|
||||
optional("com.google.guava:guava:17.0")
|
||||
optional("net.sf.ehcache:ehcache-core:2.6.7")
|
||||
optional("net.sf.ehcache:ehcache:${ehcacheVersion}")
|
||||
optional("org.quartz-scheduler:quartz:2.2.1")
|
||||
optional("org.codehaus.fabric3.api:commonj:1.1.0")
|
||||
optional("org.apache.velocity:velocity:1.7")
|
||||
@@ -591,11 +593,13 @@ project("spring-context-support") {
|
||||
exclude group: "org.olap4j", module: "olap4j"
|
||||
exclude group: "xml-apis", module: "xml-apis"
|
||||
}
|
||||
testCompile(project(":spring-context"))
|
||||
testCompile("org.apache.poi:poi:3.10-FINAL")
|
||||
testCompile("commons-beanutils:commons-beanutils:1.8.0") // for Velocity/JasperReports
|
||||
testCompile("commons-digester:commons-digester:1.8.1") // for Velocity/JasperReports
|
||||
testCompile("org.hsqldb:hsqldb:${hsqldbVersion}")
|
||||
testCompile("org.slf4j:slf4j-api:${slf4jVersion}")
|
||||
testCompile("org.ehcache:jcache:${ehcacheJCacheVersion}")
|
||||
testRuntime("com.sun.mail:javax.mail:1.5.2")
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +97,7 @@ public class EhCacheFactoryBean extends CacheConfiguration implements FactoryBea
|
||||
private Ehcache cache;
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public EhCacheFactoryBean() {
|
||||
setMaxEntriesLocalHeap(10000);
|
||||
setMaxElementsOnDisk(10000000);
|
||||
|
||||
116
spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheTest.java
vendored
Normal file
116
spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheTest.java
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cache.jcache;
|
||||
|
||||
import javax.cache.CacheManager;
|
||||
import javax.cache.Caching;
|
||||
import javax.cache.configuration.MutableConfiguration;
|
||||
|
||||
import org.ehcache.jcache.JCacheConfiguration;
|
||||
import org.junit.After;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.config.AbstractAnnotationTests;
|
||||
import org.springframework.cache.config.AnnotatedClassCacheableService;
|
||||
import org.springframework.cache.config.CacheableService;
|
||||
import org.springframework.cache.config.DefaultCacheableService;
|
||||
import org.springframework.cache.config.SomeCustomKeyGenerator;
|
||||
import org.springframework.cache.interceptor.KeyGenerator;
|
||||
import org.springframework.cache.interceptor.SimpleKeyGenerator;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class JCacheEhCacheTest extends AbstractAnnotationTests {
|
||||
|
||||
private CacheManager jCacheManager;
|
||||
|
||||
@Override
|
||||
protected ConfigurableApplicationContext getApplicationContext() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EnableCachingConfig.class);
|
||||
jCacheManager = context.getBean("jCacheManager", CacheManager.class);
|
||||
return context;
|
||||
}
|
||||
|
||||
@After
|
||||
public void shutdown() {
|
||||
jCacheManager.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test
|
||||
@Ignore("Multi cache manager support to be added")
|
||||
public void testCustomCacheManager() {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
static class EnableCachingConfig extends CachingConfigurerSupport {
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
public org.springframework.cache.CacheManager cacheManager() {
|
||||
return new JCacheCacheManager(jCacheManager());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CacheManager jCacheManager() {
|
||||
CacheManager cacheManager = Caching.getCachingProvider().getCacheManager();
|
||||
final MutableConfiguration<Object, Object> mutableConfiguration
|
||||
= new MutableConfiguration<Object, Object>();
|
||||
mutableConfiguration.setStoreByValue(false); // Otherwise value has to be Serializable
|
||||
cacheManager.createCache("testCache",
|
||||
new JCacheConfiguration<Object, Object>(mutableConfiguration));
|
||||
cacheManager.createCache("primary",
|
||||
new JCacheConfiguration<Object, Object>(mutableConfiguration));
|
||||
cacheManager.createCache("secondary",
|
||||
new JCacheConfiguration<Object, Object>(mutableConfiguration));
|
||||
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CacheableService<?> service() {
|
||||
return new DefaultCacheableService();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CacheableService<?> classService() {
|
||||
return new AnnotatedClassCacheableService();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
public KeyGenerator keyGenerator() {
|
||||
return new SimpleKeyGenerator();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public KeyGenerator customKeyGenerator() {
|
||||
return new SomeCustomKeyGenerator();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user