Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -24,7 +24,6 @@ import net.sf.ehcache.Status;
|
||||
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* CacheManager backed by an EhCache {@link net.sf.ehcache.CacheManager}.
|
||||
@@ -81,8 +80,10 @@ public class EhCacheCacheManager extends AbstractTransactionSupportingCacheManag
|
||||
@Override
|
||||
protected Collection<Cache> loadCaches() {
|
||||
Status status = getCacheManager().getStatus();
|
||||
Assert.isTrue(Status.STATUS_ALIVE.equals(status),
|
||||
"An 'alive' EhCache CacheManager is required - current cache is " + status.toString());
|
||||
if (!Status.STATUS_ALIVE.equals(status)) {
|
||||
throw new IllegalStateException(
|
||||
"An 'alive' EhCache CacheManager is required - current cache is " + status.toString());
|
||||
}
|
||||
|
||||
String[] names = getCacheManager().getCacheNames();
|
||||
Collection<Cache> caches = new LinkedHashSet<Cache>(names.length);
|
||||
@@ -94,8 +95,7 @@ public class EhCacheCacheManager extends AbstractTransactionSupportingCacheManag
|
||||
|
||||
@Override
|
||||
protected Cache getMissingCache(String name) {
|
||||
// check the EhCache cache again
|
||||
// (in case the cache was added at runtime)
|
||||
// Check the EhCache cache again (in case the cache was added at runtime)
|
||||
Ehcache ehcache = getCacheManager().getEhcache(name);
|
||||
if (ehcache != null) {
|
||||
return new EhCacheCache(ehcache);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -30,9 +30,12 @@ import org.springframework.cache.transaction.AbstractTransactionSupportingCacheM
|
||||
public class EhCacheCacheManagerTests extends AbstractTransactionSupportingCacheManagerTests<EhCacheCacheManager> {
|
||||
|
||||
private CacheManager nativeCacheManager;
|
||||
|
||||
private EhCacheCacheManager cacheManager;
|
||||
|
||||
private EhCacheCacheManager transactionalCacheManager;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
nativeCacheManager = new CacheManager(new Configuration().name("EhCacheCacheManagerTests")
|
||||
@@ -58,7 +61,8 @@ public class EhCacheCacheManagerTests extends AbstractTransactionSupportingCache
|
||||
protected EhCacheCacheManager getCacheManager(boolean transactionAware) {
|
||||
if (transactionAware) {
|
||||
return transactionalCacheManager;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return cacheManager;
|
||||
}
|
||||
}
|
||||
@@ -77,4 +81,5 @@ public class EhCacheCacheManagerTests extends AbstractTransactionSupportingCache
|
||||
protected void removeNativeCache(String cacheName) {
|
||||
nativeCacheManager.removeCache(cacheName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -33,9 +33,12 @@ import static org.mockito.BDDMockito.*;
|
||||
public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheManagerTests<JCacheCacheManager> {
|
||||
|
||||
private CacheManagerMock cacheManagerMock;
|
||||
|
||||
private JCacheCacheManager cacheManager;
|
||||
|
||||
private JCacheCacheManager transactionalCacheManager;
|
||||
|
||||
|
||||
@Before
|
||||
public void setupOnce() {
|
||||
cacheManagerMock = new CacheManagerMock();
|
||||
@@ -55,7 +58,8 @@ public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheM
|
||||
protected JCacheCacheManager getCacheManager(boolean transactionAware) {
|
||||
if (transactionAware) {
|
||||
return transactionalCacheManager;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return cacheManager;
|
||||
}
|
||||
}
|
||||
@@ -75,9 +79,11 @@ public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheM
|
||||
cacheManagerMock.removeCache(cacheName);
|
||||
}
|
||||
|
||||
|
||||
private static class CacheManagerMock {
|
||||
|
||||
private final List<String> cacheNames;
|
||||
|
||||
private final CacheManager cacheManager;
|
||||
|
||||
private CacheManagerMock() {
|
||||
@@ -103,4 +109,5 @@ public class JCacheCacheManagerTests extends AbstractTransactionSupportingCacheM
|
||||
given(cacheManager.getCache(name)).willReturn(null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -42,11 +42,10 @@ public abstract class AbstractTransactionSupportingCacheManagerTests<T extends C
|
||||
|
||||
/**
|
||||
* Returns the {@link CacheManager} to use.
|
||||
*
|
||||
* @param transactionAware if the requested cache manager should be aware
|
||||
* of the transaction
|
||||
* @return the cache manager to use
|
||||
* @see org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager#setTransactionAware(boolean)
|
||||
* @see org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager#setTransactionAware
|
||||
*/
|
||||
protected abstract T getCacheManager(boolean transactionAware);
|
||||
|
||||
@@ -65,6 +64,7 @@ public abstract class AbstractTransactionSupportingCacheManagerTests<T extends C
|
||||
*/
|
||||
protected abstract void removeNativeCache(String cacheName);
|
||||
|
||||
|
||||
@Test
|
||||
public void getOnExistingCache() {
|
||||
assertThat(getCacheManager(false).getCache(CACHE_NAME), is(instanceOf(getCacheType())));
|
||||
@@ -77,10 +77,10 @@ public abstract class AbstractTransactionSupportingCacheManagerTests<T extends C
|
||||
addNativeCache(cacheName);
|
||||
assertFalse(cacheManager.getCacheNames().contains(cacheName));
|
||||
try {
|
||||
assertThat(cacheManager.getCache(cacheName),
|
||||
is(instanceOf(getCacheType())));
|
||||
assertThat(cacheManager.getCache(cacheName), is(instanceOf(getCacheType())));
|
||||
assertTrue(cacheManager.getCacheNames().contains(cacheName));
|
||||
} finally {
|
||||
}
|
||||
finally {
|
||||
removeNativeCache(cacheName);
|
||||
}
|
||||
}
|
||||
@@ -109,8 +109,10 @@ public abstract class AbstractTransactionSupportingCacheManagerTests<T extends C
|
||||
assertThat(cacheManager.getCache(cacheName),
|
||||
is(instanceOf(TransactionAwareCacheDecorator.class)));
|
||||
assertTrue(cacheManager.getCacheNames().contains(cacheName));
|
||||
} finally {
|
||||
}
|
||||
finally {
|
||||
removeNativeCache(cacheName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user