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:
parent
856b9dd3b4
commit
ad856661ab
|
@ -95,6 +95,9 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
|
|||
Cache localCache = getJBossCache(regionFactory);
|
||||
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);
|
||||
|
||||
cfg = createConfiguration(configName);
|
||||
|
@ -149,12 +152,18 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
|
|||
Cache localCache = getJBossCache(regionFactory);
|
||||
boolean optimistic = "OPTIMISTIC".equals(localCache.getConfiguration().getNodeLockingSchemeString());
|
||||
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);
|
||||
|
||||
cfg = createConfiguration(configName);
|
||||
regionFactory = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());
|
||||
Cache remoteCache = getJBossCache(regionFactory);
|
||||
|
||||
// Sleep a bit to avoid concurrent FLUSH problem
|
||||
avoidConcurrentFlush();
|
||||
|
||||
GeneralDataRegion remoteRegion = (GeneralDataRegion) createRegion(regionFactory, getStandardRegionName(REGION_PREFIX), cfg.getProperties(), null);
|
||||
Fqn regionFqn = getRegionFqn(getStandardRegionName(REGION_PREFIX), REGION_PREFIX);
|
||||
|
|
|
@ -48,11 +48,12 @@ public abstract class AbstractJBossCacheTestCase extends UnitTestCase {
|
|||
|
||||
public static final String REGION_PREFIX = "test";
|
||||
|
||||
private CacheTestSupport testSupport = new CacheTestSupport();
|
||||
private CacheTestSupport testSupport;
|
||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
public AbstractJBossCacheTestCase(String name) {
|
||||
super(name);
|
||||
testSupport = new CacheTestSupport(log);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -97,6 +98,10 @@ public abstract class AbstractJBossCacheTestCase extends UnitTestCase {
|
|||
log.warn("Interrupted during sleep", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void avoidConcurrentFlush() {
|
||||
testSupport.avoidConcurrentFlush();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -39,6 +39,8 @@ import org.jboss.cache.Fqn;
|
|||
import org.jboss.cache.config.Option;
|
||||
import org.jboss.cache.optimistic.DataVersion;
|
||||
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
|
||||
|
@ -51,11 +53,13 @@ import org.jboss.cache.transaction.BatchModeTransactionManager;
|
|||
*/
|
||||
public class JBossCacheComplianceTest extends TestCase {
|
||||
|
||||
private CacheTestSupport testSupport = new CacheTestSupport();
|
||||
private CacheTestSupport testSupport;
|
||||
|
||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
public JBossCacheComplianceTest(String x) {
|
||||
super(x);
|
||||
testSupport = new CacheTestSupport(log);
|
||||
}
|
||||
|
||||
protected String getConfigResourceKey() {
|
||||
|
|
|
@ -75,6 +75,10 @@ public class OptimisticTransactionalExtraAPITestCase extends AbstractJBossCacheT
|
|||
JBossCacheRegionFactory rf = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());
|
||||
Cache localCache = rf.getCacheInstanceManager().getEntityCacheInstance();
|
||||
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);
|
||||
setCollectionAccessStrategy(localCollectionRegion.buildAccessStrategy(getAccessType()));
|
||||
}
|
||||
|
|
|
@ -75,6 +75,10 @@ public class OptimisticTransactionalExtraAPITestCase extends AbstractJBossCacheT
|
|||
JBossCacheRegionFactory rf = CacheTestUtil.startRegionFactory(cfg, getCacheTestSupport());
|
||||
Cache localCache = rf.getCacheInstanceManager().getEntityCacheInstance();
|
||||
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);
|
||||
setEntityRegionAccessStrategy(localEntityRegion.buildAccessStrategy(getAccessType()));
|
||||
}
|
||||
|
|
|
@ -99,6 +99,9 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase {
|
|||
Configuration cfg = createConfiguration(configName);
|
||||
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());
|
||||
|
||||
region.put(KEY, VALUE1);
|
||||
|
@ -187,6 +190,9 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase {
|
|||
Configuration cfg = createConfiguration(configName);
|
||||
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());
|
||||
|
||||
region.put(KEY, VALUE1);
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.util.Iterator;
|
|||
import java.util.Set;
|
||||
|
||||
import org.jboss.cache.Cache;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import org.hibernate.cache.RegionFactory;
|
||||
|
||||
|
@ -41,11 +42,17 @@ public class CacheTestSupport {
|
|||
|
||||
private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack";
|
||||
|
||||
private Logger log;
|
||||
|
||||
private Set<Cache> caches = new HashSet();
|
||||
private Set<RegionFactory> factories = new HashSet();
|
||||
private Exception exception;
|
||||
private String preferIPv4Stack;
|
||||
|
||||
public CacheTestSupport(Logger log) {
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
public void registerCache(Cache cache) {
|
||||
caches.add(cache);
|
||||
}
|
||||
|
@ -82,6 +89,21 @@ public class CacheTestSupport {
|
|||
cleanUp();
|
||||
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() {
|
||||
for (Iterator it = factories.iterator(); it.hasNext(); ) {
|
||||
|
@ -109,6 +131,7 @@ public class CacheTestSupport {
|
|||
finally {
|
||||
it.remove();
|
||||
}
|
||||
avoidConcurrentFlush();
|
||||
}
|
||||
caches.clear();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue