Add workaround to avoid delays from concurrent FLUSH calls in JGroups 2.6.1

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@14252 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Brian Stansberry 2007-12-21 19:47:30 +00:00
parent 856b9dd3b4
commit ad856661ab
7 changed files with 57 additions and 2 deletions

View File

@ -95,6 +95,9 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
Cache localCache = getJBossCache(regionFactory); Cache localCache = getJBossCache(regionFactory);
boolean invalidation = CacheHelper.isClusteredInvalidation(localCache); boolean invalidation = CacheHelper.isClusteredInvalidation(localCache);
// Sleep a bit to avoid concurrent FLUSH problem
avoidConcurrentFlush();
GeneralDataRegion localRegion = (GeneralDataRegion) createRegion(regionFactory, getStandardRegionName(REGION_PREFIX), cfg.getProperties(), null); GeneralDataRegion localRegion = (GeneralDataRegion) createRegion(regionFactory, getStandardRegionName(REGION_PREFIX), cfg.getProperties(), null);
cfg = createConfiguration(configName); cfg = createConfiguration(configName);
@ -149,12 +152,18 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
Cache localCache = getJBossCache(regionFactory); Cache localCache = getJBossCache(regionFactory);
boolean optimistic = "OPTIMISTIC".equals(localCache.getConfiguration().getNodeLockingSchemeString()); boolean optimistic = "OPTIMISTIC".equals(localCache.getConfiguration().getNodeLockingSchemeString());
boolean invalidation = CacheHelper.isClusteredInvalidation(localCache); boolean invalidation = CacheHelper.isClusteredInvalidation(localCache);
// Sleep a bit to avoid concurrent FLUSH problem
avoidConcurrentFlush();
GeneralDataRegion localRegion = (GeneralDataRegion) createRegion(regionFactory, getStandardRegionName(REGION_PREFIX), cfg.getProperties(), null); GeneralDataRegion localRegion = (GeneralDataRegion) createRegion(regionFactory, getStandardRegionName(REGION_PREFIX), cfg.getProperties(), null);
cfg = createConfiguration(configName); cfg = createConfiguration(configName);
regionFactory = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport()); regionFactory = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());
Cache remoteCache = getJBossCache(regionFactory); Cache remoteCache = getJBossCache(regionFactory);
// Sleep a bit to avoid concurrent FLUSH problem
avoidConcurrentFlush();
GeneralDataRegion remoteRegion = (GeneralDataRegion) createRegion(regionFactory, getStandardRegionName(REGION_PREFIX), cfg.getProperties(), null); GeneralDataRegion remoteRegion = (GeneralDataRegion) createRegion(regionFactory, getStandardRegionName(REGION_PREFIX), cfg.getProperties(), null);
Fqn regionFqn = getRegionFqn(getStandardRegionName(REGION_PREFIX), REGION_PREFIX); Fqn regionFqn = getRegionFqn(getStandardRegionName(REGION_PREFIX), REGION_PREFIX);

View File

@ -48,11 +48,12 @@ public abstract class AbstractJBossCacheTestCase extends UnitTestCase {
public static final String REGION_PREFIX = "test"; public static final String REGION_PREFIX = "test";
private CacheTestSupport testSupport = new CacheTestSupport(); private CacheTestSupport testSupport;
protected final Logger log = LoggerFactory.getLogger(getClass()); protected final Logger log = LoggerFactory.getLogger(getClass());
public AbstractJBossCacheTestCase(String name) { public AbstractJBossCacheTestCase(String name) {
super(name); super(name);
testSupport = new CacheTestSupport(log);
} }
@Override @Override
@ -97,6 +98,10 @@ public abstract class AbstractJBossCacheTestCase extends UnitTestCase {
log.warn("Interrupted during sleep", e); log.warn("Interrupted during sleep", e);
} }
} }
protected void avoidConcurrentFlush() {
testSupport.avoidConcurrentFlush();
}
/** /**

View File

@ -39,6 +39,8 @@ import org.jboss.cache.Fqn;
import org.jboss.cache.config.Option; import org.jboss.cache.config.Option;
import org.jboss.cache.optimistic.DataVersion; import org.jboss.cache.optimistic.DataVersion;
import org.jboss.cache.transaction.BatchModeTransactionManager; import org.jboss.cache.transaction.BatchModeTransactionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* Tests that JBC itself functions as expected in certain areas where there * Tests that JBC itself functions as expected in certain areas where there
@ -51,11 +53,13 @@ import org.jboss.cache.transaction.BatchModeTransactionManager;
*/ */
public class JBossCacheComplianceTest extends TestCase { public class JBossCacheComplianceTest extends TestCase {
private CacheTestSupport testSupport = new CacheTestSupport(); private CacheTestSupport testSupport;
protected final Logger log = LoggerFactory.getLogger(getClass());
public JBossCacheComplianceTest(String x) { public JBossCacheComplianceTest(String x) {
super(x); super(x);
testSupport = new CacheTestSupport(log);
} }
protected String getConfigResourceKey() { protected String getConfigResourceKey() {

View File

@ -75,6 +75,10 @@ public class OptimisticTransactionalExtraAPITestCase extends AbstractJBossCacheT
JBossCacheRegionFactory rf = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport()); JBossCacheRegionFactory rf = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());
Cache localCache = rf.getCacheInstanceManager().getEntityCacheInstance(); Cache localCache = rf.getCacheInstanceManager().getEntityCacheInstance();
optimistic = localCache.getConfiguration().getNodeLockingScheme() == org.jboss.cache.config.Configuration.NodeLockingScheme.OPTIMISTIC; optimistic = localCache.getConfiguration().getNodeLockingScheme() == org.jboss.cache.config.Configuration.NodeLockingScheme.OPTIMISTIC;
// Sleep a bit to avoid concurrent FLUSH problem
avoidConcurrentFlush();
CollectionRegion localCollectionRegion = rf.buildCollectionRegion(REGION_NAME, cfg.getProperties(), null); CollectionRegion localCollectionRegion = rf.buildCollectionRegion(REGION_NAME, cfg.getProperties(), null);
setCollectionAccessStrategy(localCollectionRegion.buildAccessStrategy(getAccessType())); setCollectionAccessStrategy(localCollectionRegion.buildAccessStrategy(getAccessType()));
} }

View File

@ -75,6 +75,10 @@ public class OptimisticTransactionalExtraAPITestCase extends AbstractJBossCacheT
JBossCacheRegionFactory rf = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport()); JBossCacheRegionFactory rf = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());
Cache localCache = rf.getCacheInstanceManager().getEntityCacheInstance(); Cache localCache = rf.getCacheInstanceManager().getEntityCacheInstance();
optimistic = localCache.getConfiguration().getNodeLockingScheme() == org.jboss.cache.config.Configuration.NodeLockingScheme.OPTIMISTIC; optimistic = localCache.getConfiguration().getNodeLockingScheme() == org.jboss.cache.config.Configuration.NodeLockingScheme.OPTIMISTIC;
// Sleep a bit to avoid concurrent FLUSH problem
avoidConcurrentFlush();
EntityRegion localEntityRegion = rf.buildEntityRegion(REGION_NAME, cfg.getProperties(), null); EntityRegion localEntityRegion = rf.buildEntityRegion(REGION_NAME, cfg.getProperties(), null);
setEntityRegionAccessStrategy(localEntityRegion.buildAccessStrategy(getAccessType())); setEntityRegionAccessStrategy(localEntityRegion.buildAccessStrategy(getAccessType()));
} }

View File

@ -99,6 +99,9 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase {
Configuration cfg = createConfiguration(configName); Configuration cfg = createConfiguration(configName);
JBossCacheRegionFactory regionFactory = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport()); JBossCacheRegionFactory regionFactory = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());
// Sleep a bit to avoid concurrent FLUSH problem
avoidConcurrentFlush();
final QueryResultsRegion region = regionFactory.buildQueryResultsRegion(getStandardRegionName(REGION_PREFIX), cfg.getProperties()); final QueryResultsRegion region = regionFactory.buildQueryResultsRegion(getStandardRegionName(REGION_PREFIX), cfg.getProperties());
region.put(KEY, VALUE1); region.put(KEY, VALUE1);
@ -187,6 +190,9 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase {
Configuration cfg = createConfiguration(configName); Configuration cfg = createConfiguration(configName);
JBossCacheRegionFactory regionFactory = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport()); JBossCacheRegionFactory regionFactory = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());
// Sleep a bit to avoid concurrent FLUSH problem
avoidConcurrentFlush();
final QueryResultsRegion region = regionFactory.buildQueryResultsRegion(getStandardRegionName(REGION_PREFIX), cfg.getProperties()); final QueryResultsRegion region = regionFactory.buildQueryResultsRegion(getStandardRegionName(REGION_PREFIX), cfg.getProperties());
region.put(KEY, VALUE1); region.put(KEY, VALUE1);

View File

@ -28,6 +28,7 @@ import java.util.Iterator;
import java.util.Set; import java.util.Set;
import org.jboss.cache.Cache; import org.jboss.cache.Cache;
import org.slf4j.Logger;
import org.hibernate.cache.RegionFactory; import org.hibernate.cache.RegionFactory;
@ -41,11 +42,17 @@ public class CacheTestSupport {
private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack"; private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack";
private Logger log;
private Set<Cache> caches = new HashSet(); private Set<Cache> caches = new HashSet();
private Set<RegionFactory> factories = new HashSet(); private Set<RegionFactory> factories = new HashSet();
private Exception exception; private Exception exception;
private String preferIPv4Stack; private String preferIPv4Stack;
public CacheTestSupport(Logger log) {
this.log = log;
}
public void registerCache(Cache cache) { public void registerCache(Cache cache) {
caches.add(cache); caches.add(cache);
} }
@ -82,6 +89,21 @@ public class CacheTestSupport {
cleanUp(); cleanUp();
throwStoredException(); throwStoredException();
} }
public void avoidConcurrentFlush() {
// JG 2.6.1 has a problem where calling flush more than once too quickly
// can result in several second delays
sleep(100);
}
private void sleep(long ms) {
try {
Thread.sleep(ms);
}
catch (InterruptedException e) {
log.warn("Interrupted during sleep", e);
}
}
private void cleanUp() { private void cleanUp() {
for (Iterator it = factories.iterator(); it.hasNext(); ) { for (Iterator it = factories.iterator(); it.hasNext(); ) {
@ -109,6 +131,7 @@ public class CacheTestSupport {
finally { finally {
it.remove(); it.remove();
} }
avoidConcurrentFlush();
} }
caches.clear(); caches.clear();
} }