Add some more debugging on cache shutdown - if Debug level is set, report which caches get shutdown

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19128 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Nick Burch
2010-03-08 17:16:18 +00:00
parent d2c2565599
commit 724d28279b
3 changed files with 43 additions and 4 deletions

View File

@@ -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

View File

@@ -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();
}
}

View File

@@ -61,7 +61,7 @@ import org.springframework.util.ResourceUtils;
*
* @author Derek Hulley
*/
public class InternalEhCacheManagerFactoryBean implements FactoryBean, CacheProvider
public class InternalEhCacheManagerFactoryBean implements FactoryBean<CacheManager>, 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<CacheManager> getObjectType()
{
return CacheManager.class;
}