Only call EhCacheManagerFactoryBean's destroy() method when actually initialized

This commit is contained in:
Juergen Hoeller 2013-03-20 10:05:56 +01:00
parent 5472e975f6
commit af3c3ef15c
1 changed files with 3 additions and 1 deletions

View File

@ -81,6 +81,7 @@ public class EhCacheSupportTests extends TestCase {
private void doTestEhCacheFactoryBean(boolean useCacheManagerFb) throws Exception { private void doTestEhCacheFactoryBean(boolean useCacheManagerFb) throws Exception {
Cache cache; Cache cache;
EhCacheManagerFactoryBean cacheManagerFb = null; EhCacheManagerFactoryBean cacheManagerFb = null;
boolean cacheManagerFbInitialized = false;
try { try {
EhCacheFactoryBean cacheFb = new EhCacheFactoryBean(); EhCacheFactoryBean cacheFb = new EhCacheFactoryBean();
Class<? extends Ehcache> objectType = cacheFb.getObjectType(); Class<? extends Ehcache> objectType = cacheFb.getObjectType();
@ -90,6 +91,7 @@ public class EhCacheSupportTests extends TestCase {
cacheManagerFb = new EhCacheManagerFactoryBean(); cacheManagerFb = new EhCacheManagerFactoryBean();
cacheManagerFb.setConfigLocation(new ClassPathResource("testEhcache.xml", getClass())); cacheManagerFb.setConfigLocation(new ClassPathResource("testEhcache.xml", getClass()));
cacheManagerFb.afterPropertiesSet(); cacheManagerFb.afterPropertiesSet();
cacheManagerFbInitialized = true;
cacheFb.setCacheManager(cacheManagerFb.getObject()); cacheFb.setCacheManager(cacheManagerFb.getObject());
} }
@ -144,7 +146,7 @@ public class EhCacheSupportTests extends TestCase {
assertTrue("overridden diskExpiryThreadIntervalSeconds is correct", config.getDiskExpiryThreadIntervalSeconds() == 10); assertTrue("overridden diskExpiryThreadIntervalSeconds is correct", config.getDiskExpiryThreadIntervalSeconds() == 10);
} }
finally { finally {
if (useCacheManagerFb && cacheManagerFb != null) { if (cacheManagerFbInitialized) {
cacheManagerFb.destroy(); cacheManagerFb.destroy();
} }
else { else {