fixing test failures after merge

This commit is contained in:
Strong Liu 2012-11-16 18:45:59 +08:00
parent 09e5bfe4d5
commit b859388f57
8 changed files with 88 additions and 97 deletions

View File

@ -57,17 +57,22 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
protected static final String VALUE2 = "value2";
protected Configuration createConfiguration() {
return CacheTestUtil.buildConfiguration( "test", InfinispanRegionFactory.class, false, true );
return CacheTestUtil.buildConfiguration(
"test",
org.hibernate.test.cache.infinispan.functional.SingleNodeTestCase.TestInfinispanRegionFactory.class,
false,
true
);
}
@Override
protected void putInRegion(Region region, Object key, Object value) {
((GeneralDataRegion) region).put( key, value );
( (GeneralDataRegion) region ).put( key, value );
}
@Override
protected void removeFromRegion(Region region, Object key) {
((GeneralDataRegion) region).evict( key );
( (GeneralDataRegion) region ).evict( key );
}
@Test
@ -77,63 +82,71 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
private void evictOrRemoveTest() throws Exception {
Configuration cfg = createConfiguration();
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
cfg,
getCacheTestSupport()
);
boolean invalidation = false;
InfinispanRegionFactory regionFactory = null;
InfinispanRegionFactory remoteRegionFactory = null;
try {
regionFactory = CacheTestUtil.startRegionFactory(
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
cfg,
getCacheTestSupport()
);
boolean invalidation = false;
// Sleep a bit to avoid concurrent FLUSH problem
avoidConcurrentFlush();
// Sleep a bit to avoid concurrent FLUSH problem
avoidConcurrentFlush();
GeneralDataRegion localRegion = (GeneralDataRegion) createRegion(
regionFactory,
getStandardRegionName( REGION_PREFIX ), cfg.getProperties(), null
);
GeneralDataRegion localRegion = (GeneralDataRegion) createRegion(
regionFactory,
getStandardRegionName( REGION_PREFIX ), cfg.getProperties(), null
);
cfg = createConfiguration();
regionFactory = CacheTestUtil.startRegionFactory(
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
cfg,
getCacheTestSupport()
);
cfg = createConfiguration();
remoteRegionFactory = CacheTestUtil.startRegionFactory(
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
cfg,
getCacheTestSupport()
);
GeneralDataRegion remoteRegion = (GeneralDataRegion) createRegion(
regionFactory,
getStandardRegionName( REGION_PREFIX ),
cfg.getProperties(),
null
);
GeneralDataRegion remoteRegion = (GeneralDataRegion) createRegion(
remoteRegionFactory,
getStandardRegionName( REGION_PREFIX ),
cfg.getProperties(),
null
);
assertNull( "local is clean", localRegion.get( KEY ) );
assertNull( "remote is clean", remoteRegion.get( KEY ) );
assertNull( "local is clean", localRegion.get( KEY ) );
assertNull( "remote is clean", remoteRegion.get( KEY ) );
regionPut(localRegion);
assertEquals( VALUE1, localRegion.get( KEY ) );
regionPut( localRegion );
assertEquals( VALUE1, localRegion.get( KEY ) );
// allow async propagation
sleep( 250 );
Object expected = invalidation ? null : VALUE1;
assertEquals( expected, remoteRegion.get( KEY ) );
// allow async propagation
sleep( 250 );
Object expected = invalidation ? null : VALUE1;
assertEquals( expected, remoteRegion.get( KEY ) );
regionEvict(localRegion);
regionEvict( localRegion );
// allow async propagation
sleep( 250 );
assertEquals( null, localRegion.get( KEY ) );
assertEquals( null, remoteRegion.get( KEY ) );
// allow async propagation
sleep( 250 );
assertEquals( null, localRegion.get( KEY ) );
assertEquals( null, remoteRegion.get( KEY ) );
}
finally {
CacheTestUtil.stopRegionFactory( regionFactory, getCacheTestSupport() );
CacheTestUtil.stopRegionFactory( remoteRegionFactory, getCacheTestSupport() );
}
}
protected void regionEvict(GeneralDataRegion region) throws Exception {
region.evict(KEY);
}
protected void regionEvict(GeneralDataRegion region) throws Exception {
region.evict( KEY );
}
protected void regionPut(GeneralDataRegion region) throws Exception {
region.put(KEY, VALUE1);
}
protected void regionPut(GeneralDataRegion region) throws Exception {
region.put( KEY, VALUE1 );
}
protected abstract String getStandardRegionName(String regionPrefix);
protected abstract String getStandardRegionName(String regionPrefix);
/**
* Test method for {@link QueryResultsRegion#evictAll()}.
@ -170,7 +183,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
cfg,
getCacheTestSupport()
);
AdvancedCache remoteCache = getInfinispanCache( regionFactory );
AdvancedCache remoteCache = getInfinispanCache( regionFactory );
// Sleep a bit to avoid concurrent FLUSH problem
avoidConcurrentFlush();
@ -191,14 +204,14 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
assertNull( "local is clean", localRegion.get( KEY ) );
assertNull( "remote is clean", remoteRegion.get( KEY ) );
regionPut(localRegion);
assertEquals( VALUE1, localRegion.get( KEY ) );
regionPut( localRegion );
assertEquals( VALUE1, localRegion.get( KEY ) );
// Allow async propagation
sleep( 250 );
regionPut(remoteRegion);
assertEquals( VALUE1, remoteRegion.get( KEY ) );
regionPut( remoteRegion );
assertEquals( VALUE1, remoteRegion.get( KEY ) );
// Allow async propagation
sleep( 250 );
@ -225,7 +238,7 @@ public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionIm
try {
BatchModeTransactionManager.getInstance().rollback();
}
catch (Exception e) {
catch ( Exception e ) {
log.error( e.getMessage(), e );
}
}

View File

@ -50,7 +50,7 @@ public class NodeEnvironment {
private Map<String, EntityRegionImpl> entityRegionMap;
private Map<String, CollectionRegionImpl> collectionRegionMap;
private SessionFactoryImplementor sessionFactory;
private SessionFactoryImplementor sessionFactory;
public NodeEnvironment(Configuration configuration) {
this.configuration = configuration;
}
@ -113,7 +113,6 @@ public class NodeEnvironment {
.applySettings(configuration.getProperties())
.build();
sessionFactory = (SessionFactoryImplementor)configuration.buildSessionFactory( serviceRegistry );
// regionFactory = CacheTestUtil.startRegionFactory(serviceRegistry, configuration);
regionFactory = (InfinispanRegionFactory)sessionFactory.getServiceRegistry().getService( RegionFactory.class );
}
@ -142,11 +141,6 @@ public class NodeEnvironment {
}
} finally {
try {
// if (regionFactory != null) {
// // Currently the RegionFactory is shutdown by its registration
// // with the CacheTestSetup from CacheTestUtil when built
// regionFactory.stop();
// }
if(sessionFactory!=null){
sessionFactory.close();
}

View File

@ -123,7 +123,7 @@ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends Abs
protected static Configuration createConfiguration(String configName) {
Configuration cfg = CacheTestUtil.buildConfiguration(
REGION_PREFIX, InfinispanRegionFactory.class, true, false
REGION_PREFIX, org.hibernate.test.cache.infinispan.functional.SingleNodeTestCase.TestInfinispanRegionFactory.class, true, false
);
cfg.setProperty( InfinispanRegionFactory.ENTITY_CACHE_RESOURCE_PROP, configName );
return cfg;

View File

@ -123,7 +123,7 @@ public abstract class AbstractEntityRegionAccessStrategyTestCase extends Abstrac
protected static Configuration createConfiguration(String configName) {
Configuration cfg = CacheTestUtil.buildConfiguration(
REGION_PREFIX,
InfinispanRegionFactory.class,
org.hibernate.test.cache.infinispan.functional.SingleNodeTestCase.TestInfinispanRegionFactory.class,
true,
false
);

View File

@ -136,6 +136,7 @@ public abstract class DualNodeTestCase extends BaseCoreFunctionalTestCase {
cfg.setProperty( Environment.TRANSACTION_STRATEGY, getTransactionFactoryClass().getName() );
cfg.setProperty( Environment.CACHE_REGION_FACTORY, getCacheRegionFactory().getName() );
cfg.setProperty( Environment.USE_QUERY_CACHE, String.valueOf( getUseQueryCache() ) );
cfg.setProperty( USE_NEW_METADATA_MAPPINGS, "false" );
}
public class SecondNodeEnvironment {
@ -173,6 +174,7 @@ public abstract class DualNodeTestCase extends BaseCoreFunctionalTestCase {
if ( sessionFactory != null ) {
try {
sessionFactory.close();
sessionFactory = null;
}
catch (Exception ignore) {
}
@ -180,6 +182,7 @@ public abstract class DualNodeTestCase extends BaseCoreFunctionalTestCase {
if ( serviceRegistry != null ) {
try {
serviceRegistry.destroy();
serviceRegistry = null;
}
catch (Exception ignore) {
}

View File

@ -44,7 +44,10 @@ public class NaturalIdInvalidationTestCase extends DualNodeTestCase {
private static final long SLEEP_TIME = 50l;
private static final Integer CUSTOMER_ID = new Integer( 1 );
private static int test = 0;
@Override
public String[] getMappings() {
return new String[]{};
}
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] {

View File

@ -106,7 +106,11 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase {
@Override
protected Configuration createConfiguration() {
return CacheTestUtil.buildCustomQueryCacheConfiguration( "test", "replicated-query" );
Configuration cfg = super.createConfiguration();
cfg.setProperty(InfinispanRegionFactory.QUERY_CACHE_RESOURCE_PROP, "replicated-query");
// return CacheTestUtil.buildCustomQueryCacheConfiguration( "test", "replicated-query" );
return cfg;
}
private void putDoesNotBlockGetTest() throws Exception {

View File

@ -57,34 +57,6 @@ public class CacheTestUtil {
return cfg;
}
public static Configuration buildCustomQueryCacheConfiguration(String regionPrefix, String queryCacheName) {
Configuration cfg = buildConfiguration(regionPrefix, InfinispanRegionFactory.class, true, true);
cfg.setProperty(InfinispanRegionFactory.QUERY_CACHE_RESOURCE_PROP, queryCacheName);
return cfg;
}
public static InfinispanRegionFactory startRegionFactory(ServiceRegistry reg,
Configuration cfg){
try {
Settings settings = cfg.buildSettings(reg);
Properties properties = cfg.getProperties();
String factoryType = cfg.getProperty(Environment.CACHE_REGION_FACTORY);
Class clazz = Thread.currentThread()
.getContextClassLoader().loadClass(factoryType);
InfinispanRegionFactory regionFactory;
if (clazz == InfinispanRegionFactory.class) {
regionFactory = new SingleNodeTestCase.TestInfinispanRegionFactory();
} else {
regionFactory = (InfinispanRegionFactory) clazz.newInstance();
}
regionFactory.start(settings, properties);
return regionFactory;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static InfinispanRegionFactory startRegionFactory(ServiceRegistry serviceRegistry,
Configuration cfg, CacheTestSupport testSupport) {
SessionFactoryImplementor sessionFactory =(SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
@ -93,12 +65,14 @@ public class CacheTestUtil {
return factory;
}
public static void stopRegionFactory(InfinispanRegionFactory factory,
CacheTestSupport testSupport) {
testSupport.unregisterFactory(factory).close();
}
public static void stopRegionFactory(InfinispanRegionFactory factory,
CacheTestSupport testSupport) {
if ( factory != null ) {
testSupport.unregisterFactory( factory ).close();
}
}
/**
/**
* Prevent instantiation.
*/
private CacheTestUtil() {