HHH-6955 Use Infinispan's test JGroups stack that uses TEST_PING

By doing this, discovery of nodes is not timed and instead is done
in-memory which is much more reliable from a testing perspective.
Due to timing issues, some tests would randomly fail because the
cluster did not form in time, so changing to this JGroups stack for
testing solves random test failures due to invalidation messages
not being sent around.
This commit is contained in:
Galder Zamarreño 2012-01-10 19:09:01 +01:00
parent cc9fbf42a9
commit 81c505c70c
3 changed files with 60 additions and 50 deletions

View File

@ -35,6 +35,8 @@ test {
systemProperties['jgroups.ping.num_initial_members'] = 1
systemProperties['jgroups.udp.enable_bundling'] = false
systemProperties['jgroups.bind_addr'] = 'localhost'
// Use Infinispan's test JGroups stack that uses TEST_PING
systemProperties['hibernate.cache.infinispan.jgroups_cfg'] = 'stacks/tcp.xml'
// systemProperties['log4j.configuration'] = 'file:/log4j/log4j-infinispan.xml'
enabled = true
}

View File

@ -11,7 +11,8 @@
<!-- Note that the JGroups transport uses sensible defaults if no configuration property is defined. -->
<properties>
<!--<property name="configurationFile" value="jgroups-tcp.xml"/>-->
<property name="configurationFile" value="tcp.xml"/>
<property name="configurationFile"
value="${hibernate.cache.infinispan.jgroups_cfg:tcp.xml}"/>
</properties>
<!-- See the JGroupsTransport javadocs for more flags -->
</transport>

View File

@ -42,70 +42,77 @@ import org.hibernate.test.cache.infinispan.util.CacheTestSupport;
* @since 3.5
*/
public abstract class AbstractNonFunctionalTestCase extends org.hibernate.testing.junit4.BaseUnitTestCase {
private static final Logger log = Logger.getLogger( AbstractNonFunctionalTestCase.class );
private static final Logger log = Logger.getLogger(AbstractNonFunctionalTestCase.class);
public static final String REGION_PREFIX = "test";
public static final String REGION_PREFIX = "test";
private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack";
private String preferIPv4Stack;
private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack";
private String preferIPv4Stack;
private static final String JGROUPS_CFG_FILE = "hibernate.cache.infinispan.jgroups_cfg";
private String jgroupsCfgFile;
private CacheTestSupport testSupport = new CacheTestSupport();
private CacheTestSupport testSupport = new CacheTestSupport();
@Before
public void prepareCacheSupport() throws Exception {
preferIPv4Stack = System.getProperty( PREFER_IPV4STACK );
System.setProperty( PREFER_IPV4STACK, "true" );
@Before
public void prepareCacheSupport() throws Exception {
preferIPv4Stack = System.getProperty(PREFER_IPV4STACK);
System.setProperty(PREFER_IPV4STACK, "true");
jgroupsCfgFile = System.getProperty(JGROUPS_CFG_FILE);
System.setProperty(JGROUPS_CFG_FILE, "stacks/tcp.xml");
testSupport.setUp();
}
testSupport.setUp();
}
@After
public void releaseCachSupport() throws Exception {
testSupport.tearDown();
@After
public void releaseCachSupport() throws Exception {
testSupport.tearDown();
if ( preferIPv4Stack == null ) {
System.clearProperty( PREFER_IPV4STACK );
}
else {
System.setProperty( PREFER_IPV4STACK, preferIPv4Stack );
}
}
if (preferIPv4Stack == null) {
System.clearProperty(PREFER_IPV4STACK);
} else {
System.setProperty(PREFER_IPV4STACK, preferIPv4Stack);
}
if (jgroupsCfgFile == null)
System.clearProperty(JGROUPS_CFG_FILE);
else
System.setProperty(JGROUPS_CFG_FILE, jgroupsCfgFile);
}
protected void registerCache(Cache cache) {
testSupport.registerCache(cache);
}
protected void registerCache(Cache cache) {
testSupport.registerCache(cache);
}
protected void unregisterCache(Cache cache) {
testSupport.unregisterCache(cache);
}
protected void unregisterCache(Cache cache) {
testSupport.unregisterCache(cache);
}
protected void registerFactory(RegionFactory factory) {
testSupport.registerFactory(factory);
}
protected void registerFactory(RegionFactory factory) {
testSupport.registerFactory(factory);
}
protected void unregisterFactory(RegionFactory factory) {
testSupport.unregisterFactory(factory);
}
protected void unregisterFactory(RegionFactory factory) {
testSupport.unregisterFactory(factory);
}
protected CacheTestSupport getCacheTestSupport() {
return testSupport;
}
protected CacheTestSupport getCacheTestSupport() {
return testSupport;
}
protected void sleep(long ms) {
try {
Thread.sleep(ms);
}
catch (InterruptedException e) {
log.warn("Interrupted during sleep", e);
}
}
protected void sleep(long ms) {
try {
Thread.sleep(ms);
} catch (InterruptedException e) {
log.warn("Interrupted during sleep", e);
}
}
protected void avoidConcurrentFlush() {
testSupport.avoidConcurrentFlush();
}
protected void avoidConcurrentFlush() {
testSupport.avoidConcurrentFlush();
}
protected int getValidKeyCount(Set keys) {
return keys.size();
protected int getValidKeyCount(Set keys) {
return keys.size();
}
}