From 252123d96ee2f35dfe5d0525a144fed8ef4cf34f Mon Sep 17 00:00:00 2001 From: Brian Stansberry Date: Tue, 13 Nov 2007 20:55:50 +0000 Subject: [PATCH] Run tests w/ java.net.preferIPv4Stack=true; cluster formation is very slow otherwise on some systems git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@14198 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../jbc2/AbstractJBossCacheTestCase.java | 1 - ...ollectionRegionAccessStrategyTestCase.java | 22 ++++++++++-- ...actEntityRegionAccessStrategyTestCase.java | 18 +++++++++- .../jbc2/functional/CacheTestCaseBase.java | 34 ++++++++++++++++++- .../hibernate/test/util/CacheTestSupport.java | 16 ++++++++- 5 files changed, 84 insertions(+), 7 deletions(-) diff --git a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractJBossCacheTestCase.java b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractJBossCacheTestCase.java index cbe4b7c1bf..33a6ddd144 100644 --- a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractJBossCacheTestCase.java +++ b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/AbstractJBossCacheTestCase.java @@ -27,7 +27,6 @@ public abstract class AbstractJBossCacheTestCase extends UnitTestCase { private CacheTestSupport testSupport = new CacheTestSupport(); protected final Logger log = LoggerFactory.getLogger(getClass()); - public AbstractJBossCacheTestCase(String name) { super(name); diff --git a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/AbstractCollectionRegionAccessStrategyTestCase.java b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/AbstractCollectionRegionAccessStrategyTestCase.java index 3fc5d78b12..c967647505 100644 --- a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/AbstractCollectionRegionAccessStrategyTestCase.java +++ b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/collection/AbstractCollectionRegionAccessStrategyTestCase.java @@ -503,7 +503,10 @@ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends Abs private static class AccessStrategyTestSetup extends TestSetup { + private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack"; + private String configName; + private String preferIPv4Stack; public AccessStrategyTestSetup(Test test, String configName) { super(test); @@ -512,7 +515,12 @@ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends Abs @Override protected void setUp() throws Exception { - super.setUp(); + super.setUp(); + + // Try to ensure we use IPv4; otherwise cluster formation is very slow + preferIPv4Stack = System.getProperty(PREFER_IPV4STACK); + System.setProperty(PREFER_IPV4STACK, "true"); + localCfg = createConfiguration(configName); localRegionFactory = CacheTestUtil.startRegionFactory(localCfg); localCache = localRegionFactory.getCacheInstanceManager().getCollectionCacheInstance(); @@ -523,8 +531,16 @@ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends Abs } @Override - protected void tearDown() throws Exception { - super.tearDown(); + protected void tearDown() throws Exception { + try { + super.tearDown(); + } + finally { + if (preferIPv4Stack == null) + System.clearProperty(PREFER_IPV4STACK); + else + System.setProperty(PREFER_IPV4STACK, preferIPv4Stack); + } if (localRegionFactory != null) localRegionFactory.stop(); diff --git a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractEntityRegionAccessStrategyTestCase.java b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractEntityRegionAccessStrategyTestCase.java index 80cfb1e6ad..3c09c739d2 100644 --- a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractEntityRegionAccessStrategyTestCase.java +++ b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/entity/AbstractEntityRegionAccessStrategyTestCase.java @@ -696,7 +696,10 @@ public abstract class AbstractEntityRegionAccessStrategyTestCase extends Abstrac private static class AccessStrategyTestSetup extends TestSetup { + private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack"; + private String configName; + private String preferIPv4Stack; public AccessStrategyTestSetup(Test test, String configName) { super(test); @@ -705,7 +708,20 @@ public abstract class AbstractEntityRegionAccessStrategyTestCase extends Abstrac @Override protected void setUp() throws Exception { - super.setUp(); + try { + super.tearDown(); + } + finally { + if (preferIPv4Stack == null) + System.clearProperty(PREFER_IPV4STACK); + else + System.setProperty(PREFER_IPV4STACK, preferIPv4Stack); + } + + // Try to ensure we use IPv4; otherwise cluster formation is very slow + preferIPv4Stack = System.getProperty(PREFER_IPV4STACK); + System.setProperty(PREFER_IPV4STACK, "true"); + localCfg = createConfiguration(configName); localRegionFactory = CacheTestUtil.startRegionFactory(localCfg); localCache = localRegionFactory.getCacheInstanceManager().getEntityCacheInstance(); diff --git a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/CacheTestCaseBase.java b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/CacheTestCaseBase.java index f8097bc6e3..b092c942c6 100755 --- a/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/CacheTestCaseBase.java +++ b/cache-jbosscache2/src/test/java/org/hibernate/test/cache/jbc2/functional/CacheTestCaseBase.java @@ -3,6 +3,8 @@ package org.hibernate.test.cache.jbc2.functional; import org.hibernate.cache.RegionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; +import org.hibernate.cfg.Mappings; +import org.hibernate.dialect.Dialect; import org.hibernate.junit.functional.FunctionalTestCase; import org.hibernate.test.tm.DummyConnectionProvider; import org.hibernate.test.tm.DummyTransactionManagerLookup; @@ -14,6 +16,10 @@ import org.hibernate.test.tm.DummyTransactionManagerLookup; */ public abstract class CacheTestCaseBase extends FunctionalTestCase { + private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack"; + + private String preferIPv4Stack; + // note that a lot of the functionality here is intended to be used // in creating specific tests for each CacheProvider that would extend // from a base test case (this) for common requirement testing... @@ -44,7 +50,7 @@ public abstract class CacheTestCaseBase extends FunctionalTestCase { public String getCacheConcurrencyStrategy() { return "transactional"; - } + } /** * The cache provider to be tested. @@ -78,4 +84,30 @@ public abstract class CacheTestCaseBase extends FunctionalTestCase { * @return The config resource location. */ protected abstract String getConfigResourceLocation(); + + @Override + public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) { + + super.afterConfigurationBuilt(mappings, dialect); + + // Try to ensure we use IPv4; otherwise cluster formation is very slow + preferIPv4Stack = System.getProperty(PREFER_IPV4STACK); + System.setProperty(PREFER_IPV4STACK, "true"); + } + + @Override + protected void cleanupTest() throws Exception { + try { + super.cleanupTest(); + } + finally { + if (preferIPv4Stack == null) + System.clearProperty(PREFER_IPV4STACK); + else + System.setProperty(PREFER_IPV4STACK, preferIPv4Stack); + } + + } + + } diff --git a/cache-jbosscache2/src/test/java/org/hibernate/test/util/CacheTestSupport.java b/cache-jbosscache2/src/test/java/org/hibernate/test/util/CacheTestSupport.java index 0bfa42b8f0..26fd53865a 100644 --- a/cache-jbosscache2/src/test/java/org/hibernate/test/util/CacheTestSupport.java +++ b/cache-jbosscache2/src/test/java/org/hibernate/test/util/CacheTestSupport.java @@ -31,9 +31,12 @@ import org.jboss.cache.Cache; */ public class CacheTestSupport { + private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack"; + private Set caches = new HashSet(); private Set factories = new HashSet(); private Exception exception; + private String preferIPv4Stack; public void registerCache(Cache cache) { caches.add(cache); @@ -51,12 +54,23 @@ public class CacheTestSupport { factories.remove(factory); } - public void setUp() throws Exception { + public void setUp() throws Exception { + + // Try to ensure we use IPv4; otherwise cluster formation is very slow + preferIPv4Stack = System.getProperty(PREFER_IPV4STACK); + System.setProperty(PREFER_IPV4STACK, "true"); + cleanUp(); throwStoredException(); } public void tearDown() throws Exception { + + if (preferIPv4Stack == null) + System.clearProperty(PREFER_IPV4STACK); + else + System.setProperty(PREFER_IPV4STACK, preferIPv4Stack); + cleanUp(); throwStoredException(); }