Rename default to testCache in Cache related tests
This simply renames the default cache from "default" to "testCache" as this might be a reserved names for third party cache providers.
This commit is contained in:
@@ -49,8 +49,6 @@ public abstract class AbstractAnnotationTests {
|
||||
|
||||
protected CacheManager cm;
|
||||
|
||||
protected CacheManager customCm;
|
||||
|
||||
/** @return a refreshed application context */
|
||||
protected abstract ConfigurableApplicationContext getApplicationContext();
|
||||
|
||||
@@ -60,10 +58,9 @@ public abstract class AbstractAnnotationTests {
|
||||
cs = ctx.getBean("service", CacheableService.class);
|
||||
ccs = ctx.getBean("classService", CacheableService.class);
|
||||
cm = ctx.getBean("cacheManager", CacheManager.class);
|
||||
customCm = ctx.getBean("customCacheManager", CacheManager.class);
|
||||
|
||||
Collection<String> cn = cm.getCacheNames();
|
||||
assertTrue(cn.contains("default"));
|
||||
assertTrue(cn.contains("testCache"));
|
||||
assertTrue(cn.contains("secondary"));
|
||||
assertTrue(cn.contains("primary"));
|
||||
}
|
||||
@@ -179,7 +176,7 @@ public abstract class AbstractAnnotationTests {
|
||||
assertSame(r1, r2);
|
||||
assertNotSame(r1, r10);
|
||||
service.evictAll(new Object());
|
||||
Cache cache = cm.getCache("default");
|
||||
Cache cache = cm.getCache("testCache");
|
||||
assertNull(cache.get(o1));
|
||||
assertNull(cache.get(o2));
|
||||
|
||||
@@ -202,7 +199,7 @@ public abstract class AbstractAnnotationTests {
|
||||
}
|
||||
|
||||
public void testUnlessExpression(CacheableService<?> service) throws Exception {
|
||||
Cache cache = cm.getCache("default");
|
||||
Cache cache = cm.getCache("testCache");
|
||||
cache.clear();
|
||||
service.unless(10);
|
||||
service.unless(11);
|
||||
@@ -249,7 +246,7 @@ public abstract class AbstractAnnotationTests {
|
||||
Object key = new Object();
|
||||
Object r1 = service.name(key);
|
||||
assertSame(r1, service.name(key));
|
||||
Cache cache = cm.getCache("default");
|
||||
Cache cache = cm.getCache("testCache");
|
||||
// assert the method name is used
|
||||
assertNotNull(cache.get(keyName));
|
||||
}
|
||||
@@ -258,7 +255,7 @@ public abstract class AbstractAnnotationTests {
|
||||
Object key = new Object();
|
||||
Object r1 = service.rootVars(key);
|
||||
assertSame(r1, service.rootVars(key));
|
||||
Cache cache = cm.getCache("default");
|
||||
Cache cache = cm.getCache("testCache");
|
||||
// assert the method name is used
|
||||
String expectedKey = "rootVarsrootVars" + AopProxyUtils.ultimateTargetClass(service) + service;
|
||||
assertNotNull(cache.get(expectedKey));
|
||||
@@ -292,7 +289,7 @@ public abstract class AbstractAnnotationTests {
|
||||
|
||||
public void testCacheUpdate(CacheableService<?> service) {
|
||||
Object o = new Object();
|
||||
Cache cache = cm.getCache("default");
|
||||
Cache cache = cm.getCache("testCache");
|
||||
assertNull(cache.get(o));
|
||||
Object r1 = service.update(o);
|
||||
assertSame(r1, cache.get(o).get());
|
||||
@@ -307,7 +304,7 @@ public abstract class AbstractAnnotationTests {
|
||||
Integer one = Integer.valueOf(1);
|
||||
Integer three = Integer.valueOf(3);
|
||||
|
||||
Cache cache = cm.getCache("default");
|
||||
Cache cache = cm.getCache("testCache");
|
||||
assertEquals(one, Integer.valueOf(service.conditionalUpdate(one).toString()));
|
||||
assertNull(cache.get(one));
|
||||
|
||||
@@ -567,7 +564,7 @@ public abstract class AbstractAnnotationTests {
|
||||
|
||||
@Test
|
||||
public void testClassMethodName() throws Exception {
|
||||
testMethodName(ccs, "namedefault");
|
||||
testMethodName(ccs, "nametestCache");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -585,7 +582,7 @@ public abstract class AbstractAnnotationTests {
|
||||
Object param = new Object();
|
||||
Object r1 = cs.customKeyGenerator(param);
|
||||
assertSame(r1, cs.customKeyGenerator(param));
|
||||
Cache cache = cm.getCache("default");
|
||||
Cache cache = cm.getCache("testCache");
|
||||
// Checks that the custom keyGenerator was used
|
||||
Object expectedKey = SomeCustomKeyGenerator.generateKey("customKeyGenerator", param);
|
||||
assertNotNull(cache.get(expectedKey));
|
||||
@@ -604,10 +601,12 @@ public abstract class AbstractAnnotationTests {
|
||||
|
||||
@Test
|
||||
public void testCustomCacheManager() {
|
||||
CacheManager customCm = ctx.getBean("customCacheManager", CacheManager.class);
|
||||
Object key = new Object();
|
||||
Object r1 = cs.customCacheManager(key);
|
||||
assertSame(r1, cs.customCacheManager(key));
|
||||
Cache cache = customCm.getCache("default");
|
||||
|
||||
Cache cache = customCm.getCache("testCache");
|
||||
assertNotNull(cache.get(key));
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.cache.annotation.Caching;
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@Cacheable("default")
|
||||
@Cacheable("testCache")
|
||||
public class AnnotatedClassCacheableService implements CacheableService<Object> {
|
||||
|
||||
private final AtomicLong counter = new AtomicLong();
|
||||
@@ -46,100 +46,100 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "default", unless = "#result > 10")
|
||||
@Cacheable(value = "testCache", unless = "#result > 10")
|
||||
public Object unless(int arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict("default")
|
||||
@CacheEvict("testCache")
|
||||
public void invalidate(Object arg1) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict("default")
|
||||
@CacheEvict("testCache")
|
||||
public void evictWithException(Object arg1) {
|
||||
throw new RuntimeException("exception thrown - evict should NOT occur");
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "default", allEntries = true)
|
||||
@CacheEvict(value = "testCache", allEntries = true)
|
||||
public void evictAll(Object arg1) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "default", beforeInvocation = true)
|
||||
@CacheEvict(value = "testCache", beforeInvocation = true)
|
||||
public void evictEarly(Object arg1) {
|
||||
throw new RuntimeException("exception thrown - evict should still occur");
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "default", key = "#p0")
|
||||
@CacheEvict(value = "testCache", key = "#p0")
|
||||
public void evict(Object arg1, Object arg2) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "default", key = "#p0", beforeInvocation = true)
|
||||
@CacheEvict(value = "testCache", key = "#p0", beforeInvocation = true)
|
||||
public void invalidateEarly(Object arg1, Object arg2) {
|
||||
throw new RuntimeException("exception thrown - evict should still occur");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "default", key = "#p0")
|
||||
@Cacheable(value = "testCache", key = "#p0")
|
||||
public Object key(Object arg1, Object arg2) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "default")
|
||||
@Cacheable(value = "testCache")
|
||||
public Object varArgsKey(Object... args) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "default", key = "#root.methodName + #root.caches[0].name")
|
||||
@Cacheable(value = "testCache", key = "#root.methodName + #root.caches[0].name")
|
||||
public Object name(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "default", key = "#root.methodName + #root.method.name + #root.targetClass + #root.target")
|
||||
@Cacheable(value = "testCache", key = "#root.methodName + #root.method.name + #root.targetClass + #root.target")
|
||||
public Object rootVars(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "default", keyGenerator = "customKyeGenerator")
|
||||
@Cacheable(value = "testCache", keyGenerator = "customKyeGenerator")
|
||||
public Object customKeyGenerator(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "default", keyGenerator = "unknownBeanName")
|
||||
@Cacheable(value = "testCache", keyGenerator = "unknownBeanName")
|
||||
public Object unknownCustomKeyGenerator(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "default", cacheManager = "customCacheManager")
|
||||
@Cacheable(value = "testCache", cacheManager = "customCacheManager")
|
||||
public Object customCacheManager(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "default", cacheManager = "unknownBeanName")
|
||||
@Cacheable(value = "testCache", cacheManager = "unknownBeanName")
|
||||
public Object unknownCustomCacheManager(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CachePut("default")
|
||||
@CachePut("testCache")
|
||||
public Object update(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CachePut(value = "default", condition = "#arg.equals(3)")
|
||||
@CachePut(value = "testCache", condition = "#arg.equals(3)")
|
||||
public Object conditionalUpdate(Object arg) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public class CustomInterceptorTests {
|
||||
|
||||
@Bean
|
||||
public CacheManager cacheManager() {
|
||||
return CacheTestUtils.createSimpleCacheManager("default", "primary", "secondary");
|
||||
return CacheTestUtils.createSimpleCacheManager("testCache", "primary", "secondary");
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -36,118 +36,118 @@ public class DefaultCacheableService implements CacheableService<Long> {
|
||||
private final AtomicLong nullInvocations = new AtomicLong();
|
||||
|
||||
@Override
|
||||
@Cacheable("default")
|
||||
@Cacheable("testCache")
|
||||
public Long cache(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict("default")
|
||||
@CacheEvict("testCache")
|
||||
public void invalidate(Object arg1) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict("default")
|
||||
@CacheEvict("testCache")
|
||||
public void evictWithException(Object arg1) {
|
||||
throw new RuntimeException("exception thrown - evict should NOT occur");
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "default", allEntries = true)
|
||||
@CacheEvict(value = "testCache", allEntries = true)
|
||||
public void evictAll(Object arg1) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "default", beforeInvocation = true)
|
||||
@CacheEvict(value = "testCache", beforeInvocation = true)
|
||||
public void evictEarly(Object arg1) {
|
||||
throw new RuntimeException("exception thrown - evict should still occur");
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "default", key = "#p0")
|
||||
@CacheEvict(value = "testCache", key = "#p0")
|
||||
public void evict(Object arg1, Object arg2) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = "default", key = "#p0", beforeInvocation = true)
|
||||
@CacheEvict(value = "testCache", key = "#p0", beforeInvocation = true)
|
||||
public void invalidateEarly(Object arg1, Object arg2) {
|
||||
throw new RuntimeException("exception thrown - evict should still occur");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "default", condition = "#classField == 3")
|
||||
@Cacheable(value = "testCache", condition = "#classField == 3")
|
||||
public Long conditional(int classField) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "default", unless = "#result > 10")
|
||||
@Cacheable(value = "testCache", unless = "#result > 10")
|
||||
public Long unless(int arg) {
|
||||
return (long) arg;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "default", key = "#p0")
|
||||
@Cacheable(value = "testCache", key = "#p0")
|
||||
public Long key(Object arg1, Object arg2) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "default")
|
||||
@Cacheable(value = "testCache")
|
||||
public Long varArgsKey(Object... args) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "default", key = "#root.methodName")
|
||||
@Cacheable(value = "testCache", key = "#root.methodName")
|
||||
public Long name(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "default", key = "#root.methodName + #root.method.name + #root.targetClass + #root.target")
|
||||
@Cacheable(value = "testCache", key = "#root.methodName + #root.method.name + #root.targetClass + #root.target")
|
||||
public Long rootVars(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "default", keyGenerator = "customKeyGenerator")
|
||||
@Cacheable(value = "testCache", keyGenerator = "customKeyGenerator")
|
||||
public Long customKeyGenerator(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "default", keyGenerator = "unknownBeanName")
|
||||
@Cacheable(value = "testCache", keyGenerator = "unknownBeanName")
|
||||
public Long unknownCustomKeyGenerator(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "default", cacheManager = "customCacheManager")
|
||||
@Cacheable(value = "testCache", cacheManager = "customCacheManager")
|
||||
public Long customCacheManager(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = "default", cacheManager = "unknownBeanName")
|
||||
@Cacheable(value = "testCache", cacheManager = "unknownBeanName")
|
||||
public Long unknownCustomCacheManager(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CachePut("default")
|
||||
@CachePut("testCache")
|
||||
public Long update(Object arg1) {
|
||||
return counter.getAndIncrement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@CachePut(value = "default", condition = "#arg.equals(3)")
|
||||
@CachePut(value = "testCache", condition = "#arg.equals(3)")
|
||||
public Long conditionalUpdate(Object arg) {
|
||||
return Long.valueOf(arg.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable("default")
|
||||
@Cacheable("testCache")
|
||||
public Long nullValue(Object arg1) {
|
||||
nullInvocations.incrementAndGet();
|
||||
return null;
|
||||
@@ -159,13 +159,13 @@ public class DefaultCacheableService implements CacheableService<Long> {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable("default")
|
||||
@Cacheable("testCache")
|
||||
public Long throwChecked(Object arg1) throws Exception {
|
||||
throw new Exception(arg1.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable("default")
|
||||
@Cacheable("testCache")
|
||||
public Long throwUnchecked(Object arg1) {
|
||||
throw new UnsupportedOperationException(arg1.toString());
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class EnableCachingIntegrationTests {
|
||||
private void fooGetSimple(ApplicationContext context, FooService service) {
|
||||
CacheManager cacheManager = context.getBean(CacheManager.class);
|
||||
|
||||
Cache cache = cacheManager.getCache("default");
|
||||
Cache cache = cacheManager.getCache("testCache");
|
||||
|
||||
Object key = new Object();
|
||||
assertCacheMiss(key, cache);
|
||||
@@ -57,7 +57,7 @@ public class EnableCachingIntegrationTests {
|
||||
@Override
|
||||
@Bean
|
||||
public CacheManager cacheManager() {
|
||||
return CacheTestUtils.createSimpleCacheManager("default");
|
||||
return CacheTestUtils.createSimpleCacheManager("testCache");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public class EnableCachingIntegrationTests {
|
||||
public Object getSimple(Object key);
|
||||
}
|
||||
|
||||
@CacheConfig(cacheNames = "default")
|
||||
@CacheConfig(cacheNames = "testCache")
|
||||
private static class FooServiceImpl implements FooService {
|
||||
private final AtomicLong counter = new AtomicLong();
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ public class EnableCachingTests extends AbstractAnnotationTests {
|
||||
@Override
|
||||
@Bean
|
||||
public CacheManager cacheManager() {
|
||||
return CacheTestUtils.createSimpleCacheManager("default", "primary", "secondary");
|
||||
return CacheTestUtils.createSimpleCacheManager("testCache", "primary", "secondary");
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -181,7 +181,7 @@ public class EnableCachingTests extends AbstractAnnotationTests {
|
||||
|
||||
@Bean
|
||||
public CacheManager customCacheManager() {
|
||||
return CacheTestUtils.createSimpleCacheManager("default");
|
||||
return CacheTestUtils.createSimpleCacheManager("testCache");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import java.lang.reflect.Method;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
final class SomeCustomKeyGenerator implements KeyGenerator {
|
||||
public final class SomeCustomKeyGenerator implements KeyGenerator {
|
||||
|
||||
@Override
|
||||
public Object generate(Object target, Method method, Object... params) {
|
||||
|
||||
Reference in New Issue
Block a user