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
This commit is contained in:
Brian Stansberry 2007-11-13 20:55:50 +00:00
parent 369ec6da34
commit 252123d96e
5 changed files with 84 additions and 7 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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();

View File

@ -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);
}
}
}

View File

@ -31,9 +31,12 @@ import org.jboss.cache.Cache;
*/
public class CacheTestSupport {
private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack";
private Set<Cache> caches = new HashSet();
private Set<RegionFactory> 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();
}