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

View File

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

View File

@ -123,7 +123,7 @@ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends Abs
protected static Configuration createConfiguration(String configName) { protected static Configuration createConfiguration(String configName) {
Configuration cfg = CacheTestUtil.buildConfiguration( 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 ); cfg.setProperty( InfinispanRegionFactory.ENTITY_CACHE_RESOURCE_PROP, configName );
return cfg; return cfg;

View File

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

View File

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

View File

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

View File

@ -106,7 +106,11 @@ public class QueryRegionImplTestCase extends AbstractGeneralDataRegionTestCase {
@Override @Override
protected Configuration createConfiguration() { 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 { private void putDoesNotBlockGetTest() throws Exception {

View File

@ -57,34 +57,6 @@ public class CacheTestUtil {
return cfg; 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, public static InfinispanRegionFactory startRegionFactory(ServiceRegistry serviceRegistry,
Configuration cfg, CacheTestSupport testSupport) { Configuration cfg, CacheTestSupport testSupport) {
SessionFactoryImplementor sessionFactory =(SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); SessionFactoryImplementor sessionFactory =(SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
@ -93,12 +65,14 @@ public class CacheTestUtil {
return factory; return factory;
} }
public static void stopRegionFactory(InfinispanRegionFactory factory, public static void stopRegionFactory(InfinispanRegionFactory factory,
CacheTestSupport testSupport) { CacheTestSupport testSupport) {
testSupport.unregisterFactory(factory).close(); if ( factory != null ) {
} testSupport.unregisterFactory( factory ).close();
}
}
/** /**
* Prevent instantiation. * Prevent instantiation.
*/ */
private CacheTestUtil() { private CacheTestUtil() {