mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -20,6 +20,8 @@ package org.alfresco;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import net.sf.ehcache.CacheManager;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
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.service.transaction.TransactionService;
|
||||||
import org.alfresco.util.ApplicationContextHelper;
|
import org.alfresco.util.ApplicationContextHelper;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.support.AbstractApplicationContext;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
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() {
|
private ApplicationContext getMinimalContext() {
|
||||||
ApplicationContextHelper.setUseLazyLoading(false);
|
ApplicationContextHelper.setUseLazyLoading(false);
|
||||||
ApplicationContextHelper.setNoAutoStart(true);
|
ApplicationContextHelper.setNoAutoStart(true);
|
||||||
@@ -109,6 +123,7 @@ public class RepositoryStartStopTest extends TestCase
|
|||||||
ApplicationContextHelper.closeApplicationContext();
|
ApplicationContextHelper.closeApplicationContext();
|
||||||
|
|
||||||
assertNoCachedApplicationContext();
|
assertNoCachedApplicationContext();
|
||||||
|
assertAllCachesShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -129,6 +144,7 @@ public class RepositoryStartStopTest extends TestCase
|
|||||||
// Close it down
|
// Close it down
|
||||||
ApplicationContextHelper.closeApplicationContext();
|
ApplicationContextHelper.closeApplicationContext();
|
||||||
assertNoCachedApplicationContext();
|
assertNoCachedApplicationContext();
|
||||||
|
assertAllCachesShutdown();
|
||||||
|
|
||||||
// Re-open it, we get a fresh copy
|
// Re-open it, we get a fresh copy
|
||||||
ApplicationContext ctx2 = getMinimalContext();
|
ApplicationContext ctx2 = getMinimalContext();
|
||||||
@@ -143,10 +159,11 @@ public class RepositoryStartStopTest extends TestCase
|
|||||||
// And finally close it
|
// And finally close it
|
||||||
ApplicationContextHelper.closeApplicationContext();
|
ApplicationContextHelper.closeApplicationContext();
|
||||||
assertNoCachedApplicationContext();
|
assertNoCachedApplicationContext();
|
||||||
|
assertAllCachesShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Using a fulll autostarting context:
|
* Using a full autostarting context:
|
||||||
* Test that we can bring up and close down
|
* Test that we can bring up and close down
|
||||||
* a context twice without error, using it
|
* a context twice without error, using it
|
||||||
* when running.
|
* when running.
|
||||||
@@ -166,6 +183,7 @@ public class RepositoryStartStopTest extends TestCase
|
|||||||
// Close it down
|
// Close it down
|
||||||
ApplicationContextHelper.closeApplicationContext();
|
ApplicationContextHelper.closeApplicationContext();
|
||||||
assertNoCachedApplicationContext();
|
assertNoCachedApplicationContext();
|
||||||
|
assertAllCachesShutdown();
|
||||||
|
|
||||||
// Re-open it, we get a fresh copy
|
// Re-open it, we get a fresh copy
|
||||||
ApplicationContext ctx2 = getFullContext();
|
ApplicationContext ctx2 = getFullContext();
|
||||||
@@ -176,9 +194,13 @@ public class RepositoryStartStopTest extends TestCase
|
|||||||
ctx = getFullContext();
|
ctx = getFullContext();
|
||||||
assertEquals(ctx, ctx2);
|
assertEquals(ctx, ctx2);
|
||||||
|
|
||||||
|
// Refresh it, shouldn't break anything
|
||||||
|
((AbstractApplicationContext)ctx).refresh();
|
||||||
|
|
||||||
// And finally close it
|
// And finally close it
|
||||||
ApplicationContextHelper.closeApplicationContext();
|
ApplicationContextHelper.closeApplicationContext();
|
||||||
assertNoCachedApplicationContext();
|
assertNoCachedApplicationContext();
|
||||||
|
assertAllCachesShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -202,6 +224,7 @@ public class RepositoryStartStopTest extends TestCase
|
|||||||
// Close
|
// Close
|
||||||
ApplicationContextHelper.closeApplicationContext();
|
ApplicationContextHelper.closeApplicationContext();
|
||||||
assertNoCachedApplicationContext();
|
assertNoCachedApplicationContext();
|
||||||
|
assertAllCachesShutdown();
|
||||||
|
|
||||||
|
|
||||||
// Now open the full one
|
// Now open the full one
|
||||||
@@ -217,6 +240,7 @@ public class RepositoryStartStopTest extends TestCase
|
|||||||
// Close it
|
// Close it
|
||||||
ApplicationContextHelper.closeApplicationContext();
|
ApplicationContextHelper.closeApplicationContext();
|
||||||
assertNoCachedApplicationContext();
|
assertNoCachedApplicationContext();
|
||||||
|
assertAllCachesShutdown();
|
||||||
|
|
||||||
|
|
||||||
// Back to the minimal one
|
// Back to the minimal one
|
||||||
@@ -227,6 +251,7 @@ public class RepositoryStartStopTest extends TestCase
|
|||||||
// Close
|
// Close
|
||||||
ApplicationContextHelper.closeApplicationContext();
|
ApplicationContextHelper.closeApplicationContext();
|
||||||
assertNoCachedApplicationContext();
|
assertNoCachedApplicationContext();
|
||||||
|
assertAllCachesShutdown();
|
||||||
|
|
||||||
|
|
||||||
// And finally we want the full one again
|
// And finally we want the full one again
|
||||||
@@ -237,6 +262,7 @@ public class RepositoryStartStopTest extends TestCase
|
|||||||
// Close and we're done
|
// Close and we're done
|
||||||
ApplicationContextHelper.closeApplicationContext();
|
ApplicationContextHelper.closeApplicationContext();
|
||||||
assertNoCachedApplicationContext();
|
assertNoCachedApplicationContext();
|
||||||
|
assertAllCachesShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doTestBasicWriteOperations(ApplicationContext ctx) throws Exception
|
public void doTestBasicWriteOperations(ApplicationContext ctx) throws Exception
|
||||||
|
@@ -93,6 +93,12 @@ public class EhCacheManagerFactoryBean implements FactoryBean, InitializingBean,
|
|||||||
public void destroy()
|
public void destroy()
|
||||||
{
|
{
|
||||||
logger.info("Shutting down EHCache CacheManager");
|
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();
|
this.cacheManager.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -61,7 +61,7 @@ import org.springframework.util.ResourceUtils;
|
|||||||
*
|
*
|
||||||
* @author Derek Hulley
|
* @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 CUSTOM_CONFIGURATION_FILE = "classpath:alfresco/extension/ehcache-custom.xml";
|
||||||
public static final String DEFAULT_CONFIGURATION_FILE = "classpath:alfresco/ehcache-default.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())
|
synchronized (getClass())
|
||||||
{
|
{
|
||||||
|
if(logger.isDebugEnabled()) {
|
||||||
|
String[] caches = InternalEhCacheManagerFactoryBean.getInstance().getCacheNames();
|
||||||
|
for(String regionName : caches) {
|
||||||
|
logger.debug("Stopped EHCache region: " + regionName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
InternalEhCacheManagerFactoryBean.getInstance().shutdown();
|
InternalEhCacheManagerFactoryBean.getInstance().shutdown();
|
||||||
initialized = false;
|
initialized = false;
|
||||||
}
|
}
|
||||||
@@ -202,7 +209,7 @@ public class InternalEhCacheManagerFactoryBean implements FactoryBean, CacheProv
|
|||||||
*
|
*
|
||||||
* @see #initCacheManager()
|
* @see #initCacheManager()
|
||||||
*/
|
*/
|
||||||
public Object getObject() throws Exception
|
public CacheManager getObject() throws Exception
|
||||||
{
|
{
|
||||||
return InternalEhCacheManagerFactoryBean.getInstance();
|
return InternalEhCacheManagerFactoryBean.getInstance();
|
||||||
}
|
}
|
||||||
@@ -210,7 +217,7 @@ public class InternalEhCacheManagerFactoryBean implements FactoryBean, CacheProv
|
|||||||
/**
|
/**
|
||||||
* @return Returns the singleton cache manager type
|
* @return Returns the singleton cache manager type
|
||||||
*/
|
*/
|
||||||
public Class getObjectType()
|
public Class<CacheManager> getObjectType()
|
||||||
{
|
{
|
||||||
return CacheManager.class;
|
return CacheManager.class;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user