diff --git a/source/java/org/alfresco/RepositoryStartStopTest.java b/source/java/org/alfresco/RepositoryStartStopTest.java index ac718bfb08..39c1d89ee0 100644 --- a/source/java/org/alfresco/RepositoryStartStopTest.java +++ b/source/java/org/alfresco/RepositoryStartStopTest.java @@ -20,6 +20,8 @@ package org.alfresco; import java.lang.reflect.Field; +import net.sf.ehcache.CacheManager; + import org.alfresco.model.ContentModel; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; @@ -30,6 +32,7 @@ import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.transaction.TransactionService; import org.alfresco.util.ApplicationContextHelper; import org.springframework.context.ApplicationContext; +import org.springframework.context.support.AbstractApplicationContext; import junit.framework.TestCase; @@ -78,6 +81,17 @@ public class RepositoryStartStopTest extends TestCase ); } + /** + * Checks that all our EHCache instances have been shutdown + */ + public static void assertAllCachesShutdown() throws Exception { + assertEquals( + "All Caches should have been shut down, but some remained", + 0, + CacheManager.ALL_CACHE_MANAGERS.size() + ); + } + private ApplicationContext getMinimalContext() { ApplicationContextHelper.setUseLazyLoading(false); ApplicationContextHelper.setNoAutoStart(true); @@ -109,6 +123,7 @@ public class RepositoryStartStopTest extends TestCase ApplicationContextHelper.closeApplicationContext(); assertNoCachedApplicationContext(); + assertAllCachesShutdown(); } /** @@ -129,6 +144,7 @@ public class RepositoryStartStopTest extends TestCase // Close it down ApplicationContextHelper.closeApplicationContext(); assertNoCachedApplicationContext(); + assertAllCachesShutdown(); // Re-open it, we get a fresh copy ApplicationContext ctx2 = getMinimalContext(); @@ -143,10 +159,11 @@ public class RepositoryStartStopTest extends TestCase // And finally close it ApplicationContextHelper.closeApplicationContext(); assertNoCachedApplicationContext(); + assertAllCachesShutdown(); } /** - * Using a fulll autostarting context: + * Using a full autostarting context: * Test that we can bring up and close down * a context twice without error, using it * when running. @@ -166,6 +183,7 @@ public class RepositoryStartStopTest extends TestCase // Close it down ApplicationContextHelper.closeApplicationContext(); assertNoCachedApplicationContext(); + assertAllCachesShutdown(); // Re-open it, we get a fresh copy ApplicationContext ctx2 = getFullContext(); @@ -176,9 +194,13 @@ public class RepositoryStartStopTest extends TestCase ctx = getFullContext(); assertEquals(ctx, ctx2); + // Refresh it, shouldn't break anything + ((AbstractApplicationContext)ctx).refresh(); + // And finally close it ApplicationContextHelper.closeApplicationContext(); assertNoCachedApplicationContext(); + assertAllCachesShutdown(); } /** @@ -202,6 +224,7 @@ public class RepositoryStartStopTest extends TestCase // Close ApplicationContextHelper.closeApplicationContext(); assertNoCachedApplicationContext(); + assertAllCachesShutdown(); // Now open the full one @@ -217,6 +240,7 @@ public class RepositoryStartStopTest extends TestCase // Close it ApplicationContextHelper.closeApplicationContext(); assertNoCachedApplicationContext(); + assertAllCachesShutdown(); // Back to the minimal one @@ -227,6 +251,7 @@ public class RepositoryStartStopTest extends TestCase // Close ApplicationContextHelper.closeApplicationContext(); assertNoCachedApplicationContext(); + assertAllCachesShutdown(); // And finally we want the full one again @@ -237,6 +262,7 @@ public class RepositoryStartStopTest extends TestCase // Close and we're done ApplicationContextHelper.closeApplicationContext(); assertNoCachedApplicationContext(); + assertAllCachesShutdown(); } public void doTestBasicWriteOperations(ApplicationContext ctx) throws Exception diff --git a/source/java/org/alfresco/repo/cache/EhCacheManagerFactoryBean.java b/source/java/org/alfresco/repo/cache/EhCacheManagerFactoryBean.java index 8654d6b9e2..3b44934227 100644 --- a/source/java/org/alfresco/repo/cache/EhCacheManagerFactoryBean.java +++ b/source/java/org/alfresco/repo/cache/EhCacheManagerFactoryBean.java @@ -93,6 +93,12 @@ public class EhCacheManagerFactoryBean implements FactoryBean, InitializingBean, public void destroy() { logger.info("Shutting down EHCache CacheManager"); + if(logger.isDebugEnabled()) { + String[] caches = this.cacheManager.getCacheNames(); + for(String cache : caches) { + logger.debug("Shutting down EHCache instance " + cache); + } + } this.cacheManager.shutdown(); } } diff --git a/source/java/org/alfresco/repo/cache/InternalEhCacheManagerFactoryBean.java b/source/java/org/alfresco/repo/cache/InternalEhCacheManagerFactoryBean.java index 7386fa3354..da28737b55 100644 --- a/source/java/org/alfresco/repo/cache/InternalEhCacheManagerFactoryBean.java +++ b/source/java/org/alfresco/repo/cache/InternalEhCacheManagerFactoryBean.java @@ -61,7 +61,7 @@ import org.springframework.util.ResourceUtils; * * @author Derek Hulley */ -public class InternalEhCacheManagerFactoryBean implements FactoryBean, CacheProvider +public class InternalEhCacheManagerFactoryBean implements FactoryBean, CacheProvider { public static final String CUSTOM_CONFIGURATION_FILE = "classpath:alfresco/extension/ehcache-custom.xml"; public static final String DEFAULT_CONFIGURATION_FILE = "classpath:alfresco/ehcache-default.xml"; @@ -192,6 +192,13 @@ public class InternalEhCacheManagerFactoryBean implements FactoryBean, CacheProv { synchronized (getClass()) { + if(logger.isDebugEnabled()) { + String[] caches = InternalEhCacheManagerFactoryBean.getInstance().getCacheNames(); + for(String regionName : caches) { + logger.debug("Stopped EHCache region: " + regionName); + } + } + InternalEhCacheManagerFactoryBean.getInstance().shutdown(); initialized = false; } @@ -202,7 +209,7 @@ public class InternalEhCacheManagerFactoryBean implements FactoryBean, CacheProv * * @see #initCacheManager() */ - public Object getObject() throws Exception + public CacheManager getObject() throws Exception { return InternalEhCacheManagerFactoryBean.getInstance(); } @@ -210,7 +217,7 @@ public class InternalEhCacheManagerFactoryBean implements FactoryBean, CacheProv /** * @return Returns the singleton cache manager type */ - public Class getObjectType() + public Class getObjectType() { return CacheManager.class; }