Skip to content

Commit

Permalink
fixing test failures after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
stliu committed Nov 16, 2012
1 parent 09e5bfe commit b859388
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 106 deletions.
Expand Up @@ -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
Expand All @@ -77,63 +82,71 @@ public void testEvict() throws Exception {

private void evictOrRemoveTest() throws Exception {
Configuration cfg = createConfiguration();
InfinispanRegionFactory regionFactory = CacheTestUtil.startRegionFactory(
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
cfg,
getCacheTestSupport()
);
boolean invalidation = false;

// Sleep a bit to avoid concurrent FLUSH problem
avoidConcurrentFlush();

GeneralDataRegion localRegion = (GeneralDataRegion) createRegion(
regionFactory,
getStandardRegionName( REGION_PREFIX ), cfg.getProperties(), null
);

cfg = createConfiguration();
regionFactory = CacheTestUtil.startRegionFactory(
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
cfg,
getCacheTestSupport()
);

GeneralDataRegion remoteRegion = (GeneralDataRegion) createRegion(
regionFactory,
getStandardRegionName( REGION_PREFIX ),
cfg.getProperties(),
null
);

assertNull( "local is clean", localRegion.get( KEY ) );
assertNull( "remote is clean", remoteRegion.get( KEY ) );

regionPut(localRegion);
assertEquals( VALUE1, localRegion.get( KEY ) );

// allow async propagation
sleep( 250 );
Object expected = invalidation ? null : VALUE1;
assertEquals( expected, remoteRegion.get( KEY ) );

regionEvict(localRegion);

// allow async propagation
sleep( 250 );
assertEquals( null, localRegion.get( KEY ) );
assertEquals( null, remoteRegion.get( KEY ) );
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();

GeneralDataRegion localRegion = (GeneralDataRegion) createRegion(
regionFactory,
getStandardRegionName( REGION_PREFIX ), cfg.getProperties(), null
);

cfg = createConfiguration();
remoteRegionFactory = CacheTestUtil.startRegionFactory(
new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() ).build(),
cfg,
getCacheTestSupport()
);

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

regionPut( localRegion );
assertEquals( VALUE1, localRegion.get( KEY ) );

// allow async propagation
sleep( 250 );
Object expected = invalidation ? null : VALUE1;
assertEquals( expected, remoteRegion.get( KEY ) );

regionEvict( localRegion );

// 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()}.
Expand Down Expand Up @@ -170,7 +183,7 @@ private void evictOrRemoveAllTest(String configName) throws Exception {
cfg,
getCacheTestSupport()
);
AdvancedCache remoteCache = getInfinispanCache( regionFactory );
AdvancedCache remoteCache = getInfinispanCache( regionFactory );

// Sleep a bit to avoid concurrent FLUSH problem
avoidConcurrentFlush();
Expand All @@ -191,14 +204,14 @@ private void evictOrRemoveAllTest(String configName) throws Exception {
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 );
Expand All @@ -225,7 +238,7 @@ protected void rollback() {
try {
BatchModeTransactionManager.getInstance().rollback();
}
catch (Exception e) {
catch ( Exception e ) {
log.error( e.getMessage(), e );
}
}
Expand Down
Expand Up @@ -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;
}
Expand Down Expand Up @@ -113,7 +113,6 @@ public void prepare() throws Exception {
.applySettings(configuration.getProperties())
.build();
sessionFactory = (SessionFactoryImplementor)configuration.buildSessionFactory( serviceRegistry );
// regionFactory = CacheTestUtil.startRegionFactory(serviceRegistry, configuration);
regionFactory = (InfinispanRegionFactory)sessionFactory.getServiceRegistry().getService( RegionFactory.class );
}

Expand Down Expand Up @@ -142,11 +141,6 @@ public void release() throws Exception {
}
} 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();
}
Expand Down
Expand Up @@ -123,7 +123,7 @@ public void prepareResources() throws Exception {

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;
Expand Down
Expand Up @@ -123,7 +123,7 @@ protected void waitForClusterToForm(Cache... caches) {
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
);
Expand Down
Expand Up @@ -136,6 +136,7 @@ protected void standardConfigure(Configuration cfg) {
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 {
Expand Down Expand Up @@ -173,13 +174,15 @@ public void shutDown() {
if ( sessionFactory != null ) {
try {
sessionFactory.close();
sessionFactory = null;
}
catch (Exception ignore) {
}
}
if ( serviceRegistry != null ) {
try {
serviceRegistry.destroy();
serviceRegistry = null;
}
catch (Exception ignore) {
}
Expand Down
Expand Up @@ -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[] {
Expand Down
Expand Up @@ -106,7 +106,11 @@ protected AdvancedCache getInfinispanCache(InfinispanRegionFactory regionFactory

@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 {
Expand Down
Expand Up @@ -57,34 +57,6 @@ public static Configuration buildConfiguration(String regionPrefix,
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 );
Expand All @@ -93,12 +65,14 @@ public static InfinispanRegionFactory startRegionFactory(ServiceRegistry service
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() {
Expand Down

0 comments on commit b859388

Please sign in to comment.