Author: bstansberry(a)jboss.com
Date: 2007-12-21 14:47:30 -0500 (Fri, 21 Dec 2007)
New Revision: 14252
Modified:
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractGeneralDataRegionTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractJBossCacheTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/JBossCacheComplianceTest.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/OptimisticTransactionalExtraAPITestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/OptimisticTransactionalExtraAPITestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/query/QueryRegionImplTestCase.java
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/util/CacheTestSupport.java
Log:
Add workaround to avoid delays from concurrent FLUSH calls in JGroups 2.6.1
Modified:
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractGeneralDataRegionTestCase.java
===================================================================
---
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractGeneralDataRegionTestCase.java 2007-12-21
16:34:30 UTC (rev 14251)
+++
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractGeneralDataRegionTestCase.java 2007-12-21
19:47:30 UTC (rev 14252)
@@ -95,6 +95,9 @@
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 @@
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);
Modified:
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractJBossCacheTestCase.java
===================================================================
---
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractJBossCacheTestCase.java 2007-12-21
16:34:30 UTC (rev 14251)
+++
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractJBossCacheTestCase.java 2007-12-21
19:47:30 UTC (rev 14252)
@@ -48,11 +48,12 @@
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 @@
log.warn("Interrupted during sleep", e);
}
}
+
+ protected void avoidConcurrentFlush() {
+ testSupport.avoidConcurrentFlush();
+ }
/**
Modified:
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/JBossCacheComplianceTest.java
===================================================================
---
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/JBossCacheComplianceTest.java 2007-12-21
16:34:30 UTC (rev 14251)
+++
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/JBossCacheComplianceTest.java 2007-12-21
19:47:30 UTC (rev 14252)
@@ -39,6 +39,8 @@
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 @@
*/
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() {
Modified:
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/OptimisticTransactionalExtraAPITestCase.java
===================================================================
---
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/OptimisticTransactionalExtraAPITestCase.java 2007-12-21
16:34:30 UTC (rev 14251)
+++
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/OptimisticTransactionalExtraAPITestCase.java 2007-12-21
19:47:30 UTC (rev 14252)
@@ -75,6 +75,10 @@
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()));
}
Modified:
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/OptimisticTransactionalExtraAPITestCase.java
===================================================================
---
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/OptimisticTransactionalExtraAPITestCase.java 2007-12-21
16:34:30 UTC (rev 14251)
+++
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/OptimisticTransactionalExtraAPITestCase.java 2007-12-21
19:47:30 UTC (rev 14252)
@@ -75,6 +75,10 @@
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()));
}
Modified:
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/query/QueryRegionImplTestCase.java
===================================================================
---
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/query/QueryRegionImplTestCase.java 2007-12-21
16:34:30 UTC (rev 14251)
+++
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/query/QueryRegionImplTestCase.java 2007-12-21
19:47:30 UTC (rev 14252)
@@ -99,6 +99,9 @@
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 @@
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);
Modified:
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/util/CacheTestSupport.java
===================================================================
---
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/util/CacheTestSupport.java 2007-12-21
16:34:30 UTC (rev 14251)
+++
core/trunk/cache-jbosscache2/src/test/java/org/hibernate/test/util/CacheTestSupport.java 2007-12-21
19:47:30 UTC (rev 14252)
@@ -28,6 +28,7 @@
import java.util.Set;
import org.jboss.cache.Cache;
+import org.slf4j.Logger;
import org.hibernate.cache.RegionFactory;
@@ -41,11 +42,17 @@
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 @@
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 @@
finally {
it.remove();
}
+ avoidConcurrentFlush();
}
caches.clear();
}