40
40
import org .hibernate .cache .infinispan .query .QueryResultsRegionImpl ;
41
41
import org .hibernate .cache .infinispan .timestamp .TimestampsRegionImpl ;
42
42
import org .hibernate .cache .infinispan .tm .HibernateTransactionManagerLookup ;
43
+ import org .hibernate .cache .internal .RegionFactoryInitiator ;
43
44
import org .hibernate .cache .spi .RegionFactory ;
45
+ import org .hibernate .cfg .AvailableSettings ;
44
46
import org .hibernate .cfg .Settings ;
45
47
import org .hibernate .engine .spi .SessionFactoryImplementor ;
46
48
import org .hibernate .engine .transaction .jta .platform .internal .AbstractJtaPlatform ;
@@ -83,11 +85,12 @@ public void testConfigurationProcessing() {
83
85
p .setProperty ("hibernate.cache.infinispan.query.eviction.strategy" , "LIRS" );
84
86
p .setProperty ("hibernate.cache.infinispan.query.eviction.wake_up_interval" , "3000" );
85
87
p .setProperty ("hibernate.cache.infinispan.query.eviction.max_entries" , "10000" );
86
-
87
- InfinispanRegionFactory factory = createRegionFactory (p );
88
+ SessionFactoryImplementor sf = createSessionFactory ( null , p );
88
89
89
90
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 ());
91
94
assertEquals ("entity" , factory .getTypeOverrides ().get ("collection" ).getCacheName ());
92
95
assertEquals ("timestamps" , factory .getTypeOverrides ().get ("timestamps" ).getCacheName ());
93
96
@@ -107,7 +110,7 @@ public void testConfigurationProcessing() {
107
110
assertEquals (3000 , factory .getTypeOverrides ().get ("query" ).getEvictionWakeUpInterval ());
108
111
assertEquals (10000 , factory .getTypeOverrides ().get ("query" ).getEvictionMaxEntries ());
109
112
} finally {
110
- factory . stop ();
113
+ sf . close ();
111
114
}
112
115
}
113
116
@@ -140,8 +143,9 @@ public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides(
140
143
p .setProperty ("hibernate.cache.infinispan.collection.eviction.strategy" , "LRU" );
141
144
p .setProperty ("hibernate.cache.infinispan.collection.eviction.wake_up_interval" , "3500" );
142
145
p .setProperty ("hibernate.cache.infinispan.collection.eviction.max_entries" , "25000" );
143
- InfinispanRegionFactory factory = createRegionFactory ( p );
146
+ SessionFactoryImplementor sf = createSessionFactory ( null , p );
144
147
try {
148
+ InfinispanRegionFactory factory = (InfinispanRegionFactory ) sf .getServiceRegistry ().getService ( RegionFactory .class );
145
149
EmbeddedCacheManager manager = factory .getCacheManager ();
146
150
assertFalse (manager .getCacheManagerConfiguration ()
147
151
.globalJmxStatistics ().enabled ());
@@ -222,7 +226,7 @@ public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides(
222
226
assertEquals (25000 , cacheCfg .eviction ().maxEntries ());
223
227
assertFalse (cacheCfg .jmxStatistics ().enabled ());
224
228
} finally {
225
- factory . stop ();
229
+ sf . close ();
226
230
}
227
231
}
228
232
@@ -236,7 +240,8 @@ public void testBuildEntityCollectionRegionOverridesOnly() {
236
240
p .setProperty ("hibernate.cache.infinispan.collection.eviction.strategy" , "LRU" );
237
241
p .setProperty ("hibernate.cache.infinispan.collection.eviction.wake_up_interval" , "3500" );
238
242
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 );
240
245
try {
241
246
factory .getCacheManager ();
242
247
EntityRegionImpl region = (EntityRegionImpl ) factory .buildEntityRegion ("com.acme.Address" , p , null );
@@ -259,7 +264,7 @@ public void testBuildEntityCollectionRegionOverridesOnly() {
259
264
assertEquals (35000 , cacheCfg .eviction ().maxEntries ());
260
265
assertEquals (100000 , cacheCfg .expiration ().maxIdle ());
261
266
} finally {
262
- factory . stop ();
267
+ sf . close ();
263
268
}
264
269
}
265
270
@ Test
@@ -274,7 +279,8 @@ public void testBuildEntityRegionPersonPlusEntityOverridesWithoutCfg() {
274
279
p .setProperty ("hibernate.cache.infinispan.entity.eviction.strategy" , "FIFO" );
275
280
p .setProperty ("hibernate.cache.infinispan.entity.eviction.wake_up_interval" , "3000" );
276
281
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 );
278
284
try {
279
285
factory .getCacheManager ();
280
286
assertNotNull (factory .getTypeOverrides ().get (person ));
@@ -290,30 +296,40 @@ public void testBuildEntityRegionPersonPlusEntityOverridesWithoutCfg() {
290
296
assertEquals (60000 , cacheCfg .expiration ().lifespan ());
291
297
assertEquals (30000 , cacheCfg .expiration ().maxIdle ());
292
298
} finally {
293
- factory . stop ();
299
+ sf . close ();
294
300
}
295
301
}
296
302
297
303
@ Test
298
304
public void testTimestampValidation () {
299
305
Properties p = new Properties ();
300
306
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
+ }
310
324
}
311
325
312
326
@ Test
313
327
public void testBuildDefaultTimestampsRegion () {
314
328
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache" ;
315
329
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 ();
317
333
try {
318
334
assertTrue (factory .getDefinedConfigurations ().contains ("timestamps" ));
319
335
assertTrue (factory .getTypeOverrides ().get ("timestamps" )
@@ -336,7 +352,8 @@ public void testBuildDiffCacheNameTimestampsRegion() {
336
352
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache" ;
337
353
Properties p = new Properties ();
338
354
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 );
340
357
try {
341
358
EmbeddedCacheManager manager = factory .getCacheManager ();
342
359
assertFalse (factory .getDefinedConfigurations ().contains ("timestamp" ));
@@ -354,7 +371,7 @@ public void testBuildDiffCacheNameTimestampsRegion() {
354
371
assertFalse (cacheCfg .storeAsBinary ().enabled ());
355
372
assertFalse (cacheCfg .jmxStatistics ().enabled ());
356
373
} finally {
357
- factory . stop ();
374
+ sf . close ();
358
375
}
359
376
}
360
377
@@ -363,12 +380,13 @@ public void testBuildTimestamRegionWithCacheNameOverride() {
363
380
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache" ;
364
381
Properties p = new Properties ();
365
382
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 );
367
385
try {
368
386
factory .buildTimestampsRegion (timestamps , p );
369
387
assertTrue (factory .getDefinedConfigurations ().contains ("mytimestamps-cache" ));
370
388
} finally {
371
- factory . stop ();
389
+ sf . close ();
372
390
}
373
391
}
374
392
@@ -380,15 +398,16 @@ public void testBuildTimestamRegionWithFifoEvictionOverride() {
380
398
p .setProperty ("hibernate.cache.infinispan.timestamps.eviction.strategy" , "FIFO" );
381
399
p .setProperty ("hibernate.cache.infinispan.timestamps.eviction.wake_up_interval" , "3000" );
382
400
p .setProperty ("hibernate.cache.infinispan.timestamps.eviction.max_entries" , "10000" );
383
- InfinispanRegionFactory factory = null ;
401
+ SessionFactoryImplementor sf = null ;
384
402
try {
385
- factory = createRegionFactory (p );
403
+ sf = createSessionFactory ( null , p );
404
+ InfinispanRegionFactory factory = (InfinispanRegionFactory )sf .getServiceRegistry ().getService ( RegionFactory .class );
386
405
factory .buildTimestampsRegion (timestamps , p );
387
406
assertTrue (factory .getDefinedConfigurations ().contains ("mytimestamps-cache" ));
388
407
fail ("Should fail cos no eviction configurations are allowed for timestamp caches" );
389
408
} catch (CacheException ce ) {
390
409
} finally {
391
- if (factory != null ) factory . stop ();
410
+ if (sf != null ) sf . close ();
392
411
}
393
412
}
394
413
@@ -400,20 +419,22 @@ public void testBuildTimestamRegionWithNoneEvictionOverride() {
400
419
p .setProperty ("hibernate.cache.infinispan.timestamps.eviction.strategy" , "NONE" );
401
420
p .setProperty ("hibernate.cache.infinispan.timestamps.eviction.wake_up_interval" , "3000" );
402
421
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 );
404
424
try {
405
425
factory .buildTimestampsRegion (timestamps , p );
406
426
assertTrue (factory .getDefinedConfigurations ().contains ("timestamps-none-eviction" ));
407
427
} finally {
408
- factory . stop ();
428
+ sf . close ();
409
429
}
410
430
}
411
431
412
432
@ Test
413
433
public void testBuildQueryRegion () {
414
434
final String query = "org.hibernate.cache.internal.StandardQueryCache" ;
415
435
Properties p = new Properties ();
416
- InfinispanRegionFactory factory = createRegionFactory (p );
436
+ SessionFactoryImplementor sf = createSessionFactory ( null , p );
437
+ InfinispanRegionFactory factory = (InfinispanRegionFactory )sf .getServiceRegistry ().getService ( RegionFactory .class );
417
438
try {
418
439
assertTrue (factory .getDefinedConfigurations ().contains ("local-query" ));
419
440
QueryResultsRegionImpl region = (QueryResultsRegionImpl ) factory .buildQueryResultsRegion (query , p );
@@ -422,7 +443,7 @@ public void testBuildQueryRegion() {
422
443
assertEquals (CacheMode .LOCAL , cacheCfg .clustering ().cacheMode ());
423
444
assertFalse (cacheCfg .jmxStatistics ().enabled ());
424
445
} finally {
425
- factory . stop ();
446
+ sf . close ();
426
447
}
427
448
}
428
449
@@ -434,7 +455,8 @@ public void testBuildQueryRegionWithCustomRegionName() {
434
455
p .setProperty ("hibernate.cache.infinispan.myquery.eviction.strategy" , "LIRS" );
435
456
p .setProperty ("hibernate.cache.infinispan.myquery.eviction.wake_up_interval" , "2222" );
436
457
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 );
438
460
try {
439
461
assertTrue (factory .getDefinedConfigurations ().contains ("local-query" ));
440
462
QueryResultsRegionImpl region = (QueryResultsRegionImpl ) factory .buildQueryResultsRegion (queryRegionName , p );
@@ -446,7 +468,7 @@ public void testBuildQueryRegionWithCustomRegionName() {
446
468
assertEquals (2222 , cacheCfg .expiration ().wakeUpInterval ());
447
469
assertEquals (11111 , cacheCfg .eviction ().maxEntries ());
448
470
} finally {
449
- factory . stop ();
471
+ sf . close ();
450
472
}
451
473
}
452
474
@ Test
@@ -459,7 +481,8 @@ public void testEnableStatistics() {
459
481
p .setProperty ("hibernate.cache.infinispan.entity.eviction.strategy" , "FIFO" );
460
482
p .setProperty ("hibernate.cache.infinispan.entity.eviction.wake_up_interval" , "3000" );
461
483
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 );
463
486
try {
464
487
EmbeddedCacheManager manager = factory .getCacheManager ();
465
488
assertTrue (manager .getCacheManagerConfiguration ().globalJmxStatistics ().enabled ());
@@ -496,7 +519,7 @@ public void testEnableStatistics() {
496
519
assertTrue (factory .getTypeOverrides ().get ("collection" ).isExposeStatistics ());
497
520
assertTrue (cache .getCacheConfiguration ().jmxStatistics ().enabled ());
498
521
} finally {
499
- factory . stop ();
522
+ sf . close ();
500
523
}
501
524
}
502
525
@@ -510,7 +533,8 @@ public void testDisableStatistics() {
510
533
p .setProperty ("hibernate.cache.infinispan.entity.eviction.strategy" , "FIFO" );
511
534
p .setProperty ("hibernate.cache.infinispan.entity.eviction.wake_up_interval" , "3000" );
512
535
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 );
514
538
try {
515
539
EntityRegionImpl region = (EntityRegionImpl ) factory .buildEntityRegion ("com.acme.Address" , p , null );
516
540
AdvancedCache cache = region .getCache ();
@@ -544,12 +568,23 @@ public void testDisableStatistics() {
544
568
assertFalse (factory .getTypeOverrides ().get ("collection" ).isExposeStatistics ());
545
569
assertFalse (cache .getCacheConfiguration ().jmxStatistics ().enabled ());
546
570
} finally {
547
- factory . stop ();
571
+ sf . close ();
548
572
}
549
573
}
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
+ }
553
588
554
589
private InfinispanRegionFactory createRegionFactory (final EmbeddedCacheManager manager , Properties p ) {
555
590
final InfinispanRegionFactory factory = new SingleNodeTestCase .TestInfinispanRegionFactory () {
@@ -576,7 +611,6 @@ protected EmbeddedCacheManager createCacheManager(Map properties) throws CacheEx
576
611
577
612
};
578
613
579
- factory .start (null , p );
580
614
return factory ;
581
615
}
582
616
0 commit comments