Skip to content

Commit 09e5bfe

Browse files
committed
fix test failures after merge
1 parent bc71c7a commit 09e5bfe

File tree

4 files changed

+97
-56
lines changed

4 files changed

+97
-56
lines changed

hibernate-core/src/main/java/org/hibernate/cache/internal/RegionFactoryInitiator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class RegionFactoryInitiator implements SessionFactoryServiceInitiator<Re
5353
/**
5454
* Property name to use to configure the full qualified class name for the {@code RegionFactory}
5555
*/
56-
public static final String IMPL_NAME = "hibernate.cache.region.factory_class";
56+
public static final String IMPL_NAME = AvailableSettings.CACHE_REGION_FACTORY;
5757

5858
@Override
5959
public Class<RegionFactory> getServiceInitiated() {

hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java

Lines changed: 75 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
import org.hibernate.cache.infinispan.query.QueryResultsRegionImpl;
4141
import org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl;
4242
import org.hibernate.cache.infinispan.tm.HibernateTransactionManagerLookup;
43+
import org.hibernate.cache.internal.RegionFactoryInitiator;
4344
import org.hibernate.cache.spi.RegionFactory;
45+
import org.hibernate.cfg.AvailableSettings;
4446
import org.hibernate.cfg.Settings;
4547
import org.hibernate.engine.spi.SessionFactoryImplementor;
4648
import org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform;
@@ -83,11 +85,12 @@ public void testConfigurationProcessing() {
8385
p.setProperty("hibernate.cache.infinispan.query.eviction.strategy", "LIRS");
8486
p.setProperty("hibernate.cache.infinispan.query.eviction.wake_up_interval", "3000");
8587
p.setProperty("hibernate.cache.infinispan.query.eviction.max_entries", "10000");
86-
87-
InfinispanRegionFactory factory = createRegionFactory(p);
88+
SessionFactoryImplementor sf = createSessionFactory( null, p );
8889

8990
try {
90-
assertEquals("entity", factory.getTypeOverrides().get("entity").getCacheName());
91+
InfinispanRegionFactory factory = (InfinispanRegionFactory) sf.getServiceRegistry()
92+
.getService( RegionFactory.class );
93+
assertEquals("entity", factory.getTypeOverrides().get("entity").getCacheName());
9194
assertEquals("entity", factory.getTypeOverrides().get("collection").getCacheName());
9295
assertEquals("timestamps", factory.getTypeOverrides().get("timestamps").getCacheName());
9396

@@ -107,7 +110,7 @@ public void testConfigurationProcessing() {
107110
assertEquals(3000, factory.getTypeOverrides().get("query").getEvictionWakeUpInterval());
108111
assertEquals(10000, factory.getTypeOverrides().get("query").getEvictionMaxEntries());
109112
} finally {
110-
factory.stop();
113+
sf.close();
111114
}
112115
}
113116

@@ -140,8 +143,9 @@ public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides(
140143
p.setProperty("hibernate.cache.infinispan.collection.eviction.strategy", "LRU");
141144
p.setProperty("hibernate.cache.infinispan.collection.eviction.wake_up_interval", "3500");
142145
p.setProperty("hibernate.cache.infinispan.collection.eviction.max_entries", "25000");
143-
InfinispanRegionFactory factory = createRegionFactory(p);
146+
SessionFactoryImplementor sf = createSessionFactory( null, p );
144147
try {
148+
InfinispanRegionFactory factory = (InfinispanRegionFactory) sf.getServiceRegistry().getService( RegionFactory.class );
145149
EmbeddedCacheManager manager = factory.getCacheManager();
146150
assertFalse(manager.getCacheManagerConfiguration()
147151
.globalJmxStatistics().enabled());
@@ -222,7 +226,7 @@ public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides(
222226
assertEquals(25000, cacheCfg.eviction().maxEntries());
223227
assertFalse(cacheCfg.jmxStatistics().enabled());
224228
} finally {
225-
factory.stop();
229+
sf.close();
226230
}
227231
}
228232

@@ -236,7 +240,8 @@ public void testBuildEntityCollectionRegionOverridesOnly() {
236240
p.setProperty("hibernate.cache.infinispan.collection.eviction.strategy", "LRU");
237241
p.setProperty("hibernate.cache.infinispan.collection.eviction.wake_up_interval", "3500");
238242
p.setProperty("hibernate.cache.infinispan.collection.eviction.max_entries", "35000");
239-
InfinispanRegionFactory factory = createRegionFactory(p);
243+
SessionFactoryImplementor sf = createSessionFactory( null, p );
244+
InfinispanRegionFactory factory = (InfinispanRegionFactory)sf.getServiceRegistry().getService( RegionFactory.class );
240245
try {
241246
factory.getCacheManager();
242247
EntityRegionImpl region = (EntityRegionImpl) factory.buildEntityRegion("com.acme.Address", p, null);
@@ -259,7 +264,7 @@ public void testBuildEntityCollectionRegionOverridesOnly() {
259264
assertEquals(35000, cacheCfg.eviction().maxEntries());
260265
assertEquals(100000, cacheCfg.expiration().maxIdle());
261266
} finally {
262-
factory.stop();
267+
sf.close();
263268
}
264269
}
265270
@Test
@@ -274,7 +279,8 @@ public void testBuildEntityRegionPersonPlusEntityOverridesWithoutCfg() {
274279
p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy", "FIFO");
275280
p.setProperty("hibernate.cache.infinispan.entity.eviction.wake_up_interval", "3000");
276281
p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries", "10000");
277-
InfinispanRegionFactory factory = createRegionFactory(p);
282+
SessionFactoryImplementor sf = createSessionFactory( null, p );
283+
InfinispanRegionFactory factory = (InfinispanRegionFactory)sf.getServiceRegistry().getService( RegionFactory.class );
278284
try {
279285
factory.getCacheManager();
280286
assertNotNull(factory.getTypeOverrides().get(person));
@@ -290,30 +296,40 @@ public void testBuildEntityRegionPersonPlusEntityOverridesWithoutCfg() {
290296
assertEquals(60000, cacheCfg.expiration().lifespan());
291297
assertEquals(30000, cacheCfg.expiration().maxIdle());
292298
} finally {
293-
factory.stop();
299+
sf.close();
294300
}
295301
}
296302

297303
@Test
298304
public void testTimestampValidation() {
299305
Properties p = new Properties();
300306
final DefaultCacheManager manager = new DefaultCacheManager();
301-
InfinispanRegionFactory factory = createRegionFactory(manager, p);
302-
ConfigurationBuilder builder = new ConfigurationBuilder();
303-
builder.clustering().cacheMode(CacheMode.INVALIDATION_SYNC);
304-
manager.defineConfiguration("timestamps", builder.build());
305-
try {
306-
factory.start(null, p);
307-
fail("Should have failed saying that invalidation is not allowed for timestamp caches.");
308-
} catch(CacheException ce) {
309-
}
307+
SessionFactoryImplementor sf = null;
308+
try{
309+
sf = createSessionFactory(manager, p);
310+
InfinispanRegionFactory factory = (InfinispanRegionFactory) sf.getServiceRegistry().getService( RegionFactory.class );
311+
ConfigurationBuilder builder = new ConfigurationBuilder();
312+
builder.clustering().cacheMode(CacheMode.INVALIDATION_SYNC);
313+
manager.defineConfiguration("timestamps", builder.build());
314+
factory.start(null, p);
315+
fail("Should have failed saying that invalidation is not allowed for timestamp caches.");
316+
} catch ( CacheException e ){
317+
318+
319+
}finally {
320+
if(sf!=null){
321+
sf.close();
322+
}
323+
}
310324
}
311325

312326
@Test
313327
public void testBuildDefaultTimestampsRegion() {
314328
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
315329
Properties p = new Properties();
316-
InfinispanRegionFactory factory = createRegionFactory(p);
330+
SessionFactoryImplementor sf = createSessionFactory( null, p );
331+
InfinispanRegionFactory factory = (InfinispanRegionFactory)sf.getServiceRegistry().getService( RegionFactory.class );
332+
EmbeddedCacheManager manager = factory.getCacheManager();
317333
try {
318334
assertTrue(factory.getDefinedConfigurations().contains("timestamps"));
319335
assertTrue(factory.getTypeOverrides().get("timestamps")
@@ -336,7 +352,8 @@ public void testBuildDiffCacheNameTimestampsRegion() {
336352
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
337353
Properties p = new Properties();
338354
p.setProperty("hibernate.cache.infinispan.timestamps.cfg", "unrecommended-timestamps");
339-
InfinispanRegionFactory factory = createRegionFactory(p);
355+
SessionFactoryImplementor sf = createSessionFactory( null, p );
356+
InfinispanRegionFactory factory = (InfinispanRegionFactory)sf.getServiceRegistry().getService( RegionFactory.class );
340357
try {
341358
EmbeddedCacheManager manager = factory.getCacheManager();
342359
assertFalse(factory.getDefinedConfigurations().contains("timestamp"));
@@ -354,7 +371,7 @@ public void testBuildDiffCacheNameTimestampsRegion() {
354371
assertFalse(cacheCfg.storeAsBinary().enabled());
355372
assertFalse(cacheCfg.jmxStatistics().enabled());
356373
} finally {
357-
factory.stop();
374+
sf.close();
358375
}
359376
}
360377

@@ -363,12 +380,13 @@ public void testBuildTimestamRegionWithCacheNameOverride() {
363380
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
364381
Properties p = new Properties();
365382
p.setProperty("hibernate.cache.infinispan.timestamps.cfg", "mytimestamps-cache");
366-
InfinispanRegionFactory factory = createRegionFactory(p);
383+
SessionFactoryImplementor sf = createSessionFactory( null, p );
384+
InfinispanRegionFactory factory = (InfinispanRegionFactory)sf.getServiceRegistry().getService( RegionFactory.class );
367385
try {
368386
factory.buildTimestampsRegion(timestamps, p);
369387
assertTrue(factory.getDefinedConfigurations().contains("mytimestamps-cache"));
370388
} finally {
371-
factory.stop();
389+
sf.close();
372390
}
373391
}
374392

@@ -380,15 +398,16 @@ public void testBuildTimestamRegionWithFifoEvictionOverride() {
380398
p.setProperty("hibernate.cache.infinispan.timestamps.eviction.strategy", "FIFO");
381399
p.setProperty("hibernate.cache.infinispan.timestamps.eviction.wake_up_interval", "3000");
382400
p.setProperty("hibernate.cache.infinispan.timestamps.eviction.max_entries", "10000");
383-
InfinispanRegionFactory factory = null;
401+
SessionFactoryImplementor sf = null;
384402
try {
385-
factory = createRegionFactory(p);
403+
sf = createSessionFactory( null, p );
404+
InfinispanRegionFactory factory = (InfinispanRegionFactory)sf.getServiceRegistry().getService( RegionFactory.class );
386405
factory.buildTimestampsRegion(timestamps, p);
387406
assertTrue(factory.getDefinedConfigurations().contains("mytimestamps-cache"));
388407
fail("Should fail cos no eviction configurations are allowed for timestamp caches");
389408
} catch(CacheException ce) {
390409
} finally {
391-
if (factory != null) factory.stop();
410+
if (sf != null) sf.close();
392411
}
393412
}
394413

@@ -400,20 +419,22 @@ public void testBuildTimestamRegionWithNoneEvictionOverride() {
400419
p.setProperty("hibernate.cache.infinispan.timestamps.eviction.strategy", "NONE");
401420
p.setProperty("hibernate.cache.infinispan.timestamps.eviction.wake_up_interval", "3000");
402421
p.setProperty("hibernate.cache.infinispan.timestamps.eviction.max_entries", "0");
403-
InfinispanRegionFactory factory = createRegionFactory(p);
422+
SessionFactoryImplementor sf = createSessionFactory( null, p );
423+
InfinispanRegionFactory factory = (InfinispanRegionFactory)sf.getServiceRegistry().getService( RegionFactory.class );
404424
try {
405425
factory.buildTimestampsRegion(timestamps, p);
406426
assertTrue(factory.getDefinedConfigurations().contains("timestamps-none-eviction"));
407427
} finally {
408-
factory.stop();
428+
sf.close();
409429
}
410430
}
411431

412432
@Test
413433
public void testBuildQueryRegion() {
414434
final String query = "org.hibernate.cache.internal.StandardQueryCache";
415435
Properties p = new Properties();
416-
InfinispanRegionFactory factory = createRegionFactory(p);
436+
SessionFactoryImplementor sf = createSessionFactory( null, p );
437+
InfinispanRegionFactory factory = (InfinispanRegionFactory)sf.getServiceRegistry().getService( RegionFactory.class );
417438
try {
418439
assertTrue(factory.getDefinedConfigurations().contains("local-query"));
419440
QueryResultsRegionImpl region = (QueryResultsRegionImpl) factory.buildQueryResultsRegion(query, p);
@@ -422,7 +443,7 @@ public void testBuildQueryRegion() {
422443
assertEquals(CacheMode.LOCAL, cacheCfg.clustering().cacheMode());
423444
assertFalse(cacheCfg.jmxStatistics().enabled());
424445
} finally {
425-
factory.stop();
446+
sf.close();
426447
}
427448
}
428449

@@ -434,7 +455,8 @@ public void testBuildQueryRegionWithCustomRegionName() {
434455
p.setProperty("hibernate.cache.infinispan.myquery.eviction.strategy", "LIRS");
435456
p.setProperty("hibernate.cache.infinispan.myquery.eviction.wake_up_interval", "2222");
436457
p.setProperty("hibernate.cache.infinispan.myquery.eviction.max_entries", "11111");
437-
InfinispanRegionFactory factory = createRegionFactory(p);
458+
SessionFactoryImplementor sf = createSessionFactory( null, p );
459+
InfinispanRegionFactory factory = (InfinispanRegionFactory)sf.getServiceRegistry().getService( RegionFactory.class );
438460
try {
439461
assertTrue(factory.getDefinedConfigurations().contains("local-query"));
440462
QueryResultsRegionImpl region = (QueryResultsRegionImpl) factory.buildQueryResultsRegion(queryRegionName, p);
@@ -446,7 +468,7 @@ public void testBuildQueryRegionWithCustomRegionName() {
446468
assertEquals(2222, cacheCfg.expiration().wakeUpInterval());
447469
assertEquals(11111, cacheCfg.eviction().maxEntries());
448470
} finally {
449-
factory.stop();
471+
sf.close();
450472
}
451473
}
452474
@Test
@@ -459,7 +481,8 @@ public void testEnableStatistics() {
459481
p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy", "FIFO");
460482
p.setProperty("hibernate.cache.infinispan.entity.eviction.wake_up_interval", "3000");
461483
p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries", "10000");
462-
InfinispanRegionFactory factory = createRegionFactory(p);
484+
SessionFactoryImplementor sf = createSessionFactory( null, p );
485+
InfinispanRegionFactory factory = (InfinispanRegionFactory)sf.getServiceRegistry().getService( RegionFactory.class );
463486
try {
464487
EmbeddedCacheManager manager = factory.getCacheManager();
465488
assertTrue(manager.getCacheManagerConfiguration().globalJmxStatistics().enabled());
@@ -496,7 +519,7 @@ public void testEnableStatistics() {
496519
assertTrue(factory.getTypeOverrides().get("collection").isExposeStatistics());
497520
assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
498521
} finally {
499-
factory.stop();
522+
sf.close();
500523
}
501524
}
502525

@@ -510,7 +533,8 @@ public void testDisableStatistics() {
510533
p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy", "FIFO");
511534
p.setProperty("hibernate.cache.infinispan.entity.eviction.wake_up_interval", "3000");
512535
p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries", "10000");
513-
InfinispanRegionFactory factory = createRegionFactory(p);
536+
SessionFactoryImplementor sf = createSessionFactory( null, p );
537+
InfinispanRegionFactory factory = (InfinispanRegionFactory)sf.getServiceRegistry().getService( RegionFactory.class );
514538
try {
515539
EntityRegionImpl region = (EntityRegionImpl) factory.buildEntityRegion("com.acme.Address", p, null);
516540
AdvancedCache cache = region.getCache();
@@ -544,12 +568,23 @@ public void testDisableStatistics() {
544568
assertFalse(factory.getTypeOverrides().get("collection").isExposeStatistics());
545569
assertFalse(cache.getCacheConfiguration().jmxStatistics().enabled());
546570
} finally {
547-
factory.stop();
571+
sf.close();
548572
}
549573
}
550-
private InfinispanRegionFactory createRegionFactory(Properties p) {
551-
return createRegionFactory(null, p);
552-
}
574+
575+
private SessionFactoryImplementor createSessionFactory(final EmbeddedCacheManager manager, Properties p) {
576+
Properties properties = new Properties();
577+
properties.putAll( p );
578+
properties.put(
579+
RegionFactoryInitiator.IMPL_NAME,
580+
createRegionFactory( manager, p )
581+
);
582+
properties.put( AvailableSettings.JTA_PLATFORM, JBossStandAloneJtaPlatform.class.getName() );
583+
org.hibernate.cfg.Configuration cfg = new org.hibernate.cfg.Configuration();
584+
cfg.setProperties( properties );
585+
ServiceRegistry serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( properties );
586+
return (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry );
587+
}
553588

554589
private InfinispanRegionFactory createRegionFactory(final EmbeddedCacheManager manager, Properties p) {
555590
final InfinispanRegionFactory factory = new SingleNodeTestCase.TestInfinispanRegionFactory() {
@@ -576,7 +611,6 @@ protected EmbeddedCacheManager createCacheManager(Map properties) throws CacheEx
576611

577612
};
578613

579-
factory.start(null, p);
580614
return factory;
581615
}
582616

hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/NodeEnvironment.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
import org.hibernate.cache.infinispan.collection.CollectionRegionImpl;
3333
import org.hibernate.cache.infinispan.entity.EntityRegionImpl;
3434
import org.hibernate.cache.spi.CacheDataDescription;
35+
import org.hibernate.cache.spi.RegionFactory;
3536
import org.hibernate.cfg.Configuration;
37+
import org.hibernate.engine.spi.SessionFactoryImplementor;
3638
import org.hibernate.test.cache.infinispan.util.CacheTestUtil;
3739

3840
/**
@@ -48,7 +50,7 @@ public class NodeEnvironment {
4850

4951
private Map<String, EntityRegionImpl> entityRegionMap;
5052
private Map<String, CollectionRegionImpl> collectionRegionMap;
51-
53+
private SessionFactoryImplementor sessionFactory;
5254
public NodeEnvironment(Configuration configuration) {
5355
this.configuration = configuration;
5456
}
@@ -110,7 +112,9 @@ public void prepare() throws Exception {
110112
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
111113
.applySettings(configuration.getProperties())
112114
.build();
113-
regionFactory = CacheTestUtil.startRegionFactory(serviceRegistry, configuration);
115+
sessionFactory = (SessionFactoryImplementor)configuration.buildSessionFactory( serviceRegistry );
116+
// regionFactory = CacheTestUtil.startRegionFactory(serviceRegistry, configuration);
117+
regionFactory = (InfinispanRegionFactory)sessionFactory.getServiceRegistry().getService( RegionFactory.class );
114118
}
115119

116120
public void release() throws Exception {
@@ -138,11 +142,14 @@ public void release() throws Exception {
138142
}
139143
} finally {
140144
try {
141-
if (regionFactory != null) {
142-
// Currently the RegionFactory is shutdown by its registration
143-
// with the CacheTestSetup from CacheTestUtil when built
144-
regionFactory.stop();
145-
}
145+
// if (regionFactory != null) {
146+
// // Currently the RegionFactory is shutdown by its registration
147+
// // with the CacheTestSetup from CacheTestUtil when built
148+
// regionFactory.stop();
149+
// }
150+
if(sessionFactory!=null){
151+
sessionFactory.close();
152+
}
146153
} finally {
147154
if (serviceRegistry != null) {
148155
serviceRegistry.destroy();

0 commit comments

Comments
 (0)