66 */
77package org .hibernate .test .cache .infinispan ;
88
9- import java .util .Properties ;
10- import javax .transaction .TransactionManager ;
11-
129import org .hibernate .boot .spi .SessionFactoryOptions ;
1310import org .hibernate .cache .CacheException ;
1411import org .hibernate .cache .infinispan .InfinispanRegionFactory ;
1714import org .hibernate .cache .infinispan .query .QueryResultsRegionImpl ;
1815import org .hibernate .cache .infinispan .timestamp .TimestampsRegionImpl ;
1916import org .hibernate .cache .infinispan .tm .HibernateTransactionManagerLookup ;
17+ import org .hibernate .cache .internal .CacheDataDescriptionImpl ;
18+ import org .hibernate .cache .spi .CacheDataDescription ;
2019import org .hibernate .cfg .Environment ;
2120import org .hibernate .engine .transaction .jta .platform .internal .AbstractJtaPlatform ;
2221import org .hibernate .engine .transaction .jta .platform .internal .JBossStandAloneJtaPlatform ;
23-
24- import org .hibernate .testing .ServiceRegistryBuilder ;
2522import org .hibernate .test .cache .infinispan .functional .SingleNodeTestCase ;
26- import org .junit .Test ;
27-
23+ import org .hibernate .testing .ServiceRegistryBuilder ;
2824import org .infinispan .AdvancedCache ;
2925import org .infinispan .configuration .cache .CacheMode ;
3026import org .infinispan .configuration .cache .Configuration ;
3430import org .infinispan .manager .DefaultCacheManager ;
3531import org .infinispan .manager .EmbeddedCacheManager ;
3632import org .infinispan .test .TestingUtil ;
33+ import org .infinispan .transaction .TransactionMode ;
34+ import org .junit .Test ;
35+
36+ import javax .transaction .TransactionManager ;
37+ import java .util .Properties ;
3738
38- import static org .junit .Assert .assertEquals ;
39- import static org .junit .Assert .assertFalse ;
40- import static org .junit .Assert .assertNotNull ;
41- import static org .junit .Assert .assertNull ;
42- import static org .junit .Assert .assertTrue ;
43- import static org .junit .Assert .fail ;
39+ import static org .junit .Assert .*;
4440
4541/**
4642 * InfinispanRegionFactoryTestCase.
4945 * @since 3.5
5046 */
5147public class InfinispanRegionFactoryTestCase {
48+ private static CacheDataDescription MUTABLE_NON_VERSIONED = new CacheDataDescriptionImpl (true , false , null );
49+ private static CacheDataDescription IMMUTABLE_NON_VERSIONED = new CacheDataDescriptionImpl (false , false , null );
5250
5351 @ Test
5452 public void testConfigurationProcessing () {
@@ -136,7 +134,7 @@ public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides(
136134 assertFalse (factory .getDefinedConfigurations ().contains (addresses ));
137135 AdvancedCache cache ;
138136
139- EntityRegionImpl region = (EntityRegionImpl ) factory .buildEntityRegion (person , p , null );
137+ EntityRegionImpl region = (EntityRegionImpl ) factory .buildEntityRegion (person , p , MUTABLE_NON_VERSIONED );
140138 assertNotNull (factory .getTypeOverrides ().get (person ));
141139 assertTrue (factory .getDefinedConfigurations ().contains (person ));
142140 assertNull (factory .getTypeOverrides ().get (address ));
@@ -149,7 +147,7 @@ public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides(
149147 assertEquals (30000 , cacheCfg .expiration ().maxIdle ());
150148 assertFalse (cacheCfg .jmxStatistics ().enabled ());
151149
152- region = (EntityRegionImpl ) factory .buildEntityRegion (address , p , null );
150+ region = (EntityRegionImpl ) factory .buildEntityRegion (address , p , MUTABLE_NON_VERSIONED );
153151 assertNotNull (factory .getTypeOverrides ().get (person ));
154152 assertTrue (factory .getDefinedConfigurations ().contains (person ));
155153 assertNull (factory .getTypeOverrides ().get (address ));
@@ -160,7 +158,7 @@ public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides(
160158 assertEquals (20000 , cacheCfg .eviction ().maxEntries ());
161159 assertFalse (cacheCfg .jmxStatistics ().enabled ());
162160
163- region = (EntityRegionImpl ) factory .buildEntityRegion (car , p , null );
161+ region = (EntityRegionImpl ) factory .buildEntityRegion (car , p , MUTABLE_NON_VERSIONED );
164162 assertNotNull (factory .getTypeOverrides ().get (person ));
165163 assertTrue (factory .getDefinedConfigurations ().contains (person ));
166164 assertNull (factory .getTypeOverrides ().get (address ));
@@ -172,7 +170,7 @@ public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides(
172170 assertFalse (cacheCfg .jmxStatistics ().enabled ());
173171
174172 CollectionRegionImpl collectionRegion = (CollectionRegionImpl )
175- factory .buildCollectionRegion (addresses , p , null );
173+ factory .buildCollectionRegion (addresses , p , MUTABLE_NON_VERSIONED );
176174 assertNotNull (factory .getTypeOverrides ().get (addresses ));
177175 assertTrue (factory .getDefinedConfigurations ().contains (person ));
178176 assertNull (factory .getTypeOverrides ().get (parts ));
@@ -185,7 +183,7 @@ public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides(
185183 assertEquals (35000 , cacheCfg .expiration ().maxIdle ());
186184 assertFalse (cacheCfg .jmxStatistics ().enabled ());
187185
188- collectionRegion = (CollectionRegionImpl ) factory .buildCollectionRegion (parts , p , null );
186+ collectionRegion = (CollectionRegionImpl ) factory .buildCollectionRegion (parts , p , MUTABLE_NON_VERSIONED );
189187 assertNotNull (factory .getTypeOverrides ().get (addresses ));
190188 assertTrue (factory .getDefinedConfigurations ().contains (addresses ));
191189 assertNull (factory .getTypeOverrides ().get (parts ));
@@ -196,7 +194,7 @@ public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides(
196194 assertEquals (25000 , cacheCfg .eviction ().maxEntries ());
197195 assertFalse (cacheCfg .jmxStatistics ().enabled ());
198196
199- collectionRegion = (CollectionRegionImpl ) factory .buildCollectionRegion (parts , p , null );
197+ collectionRegion = (CollectionRegionImpl ) factory .buildCollectionRegion (parts , p , MUTABLE_NON_VERSIONED );
200198 assertNotNull (factory .getTypeOverrides ().get (addresses ));
201199 assertTrue (factory .getDefinedConfigurations ().contains (addresses ));
202200 assertNull (factory .getTypeOverrides ().get (parts ));
@@ -224,7 +222,7 @@ public void testBuildEntityCollectionRegionOverridesOnly() {
224222 InfinispanRegionFactory factory = createRegionFactory (p );
225223 try {
226224 factory .getCacheManager ();
227- EntityRegionImpl region = (EntityRegionImpl ) factory .buildEntityRegion ("com.acme.Address" , p , null );
225+ EntityRegionImpl region = (EntityRegionImpl ) factory .buildEntityRegion ("com.acme.Address" , p , MUTABLE_NON_VERSIONED );
228226 assertNull (factory .getTypeOverrides ().get ("com.acme.Address" ));
229227 cache = region .getCache ();
230228 Configuration cacheCfg = cache .getCacheConfiguration ();
@@ -235,7 +233,7 @@ public void testBuildEntityCollectionRegionOverridesOnly() {
235233 assertEquals (100000 , cacheCfg .expiration ().maxIdle ());
236234
237235 CollectionRegionImpl collectionRegion = (CollectionRegionImpl )
238- factory .buildCollectionRegion ("com.acme.Person.addresses" , p , null );
236+ factory .buildCollectionRegion ("com.acme.Person.addresses" , p , MUTABLE_NON_VERSIONED );
239237 assertNull (factory .getTypeOverrides ().get ("com.acme.Person.addresses" ));
240238 cache = collectionRegion .getCache ();
241239 cacheCfg = cache .getCacheConfiguration ();
@@ -264,7 +262,7 @@ public void testBuildEntityRegionPersonPlusEntityOverridesWithoutCfg() {
264262 factory .getCacheManager ();
265263 assertNotNull (factory .getTypeOverrides ().get (person ));
266264 assertFalse (factory .getDefinedConfigurations ().contains (person ));
267- EntityRegionImpl region = (EntityRegionImpl ) factory .buildEntityRegion (person , p , null );
265+ EntityRegionImpl region = (EntityRegionImpl ) factory .buildEntityRegion (person , p , MUTABLE_NON_VERSIONED );
268266 assertNotNull (factory .getTypeOverrides ().get (person ));
269267 assertTrue (factory .getDefinedConfigurations ().contains (person ));
270268 AdvancedCache cache = region .getCache ();
@@ -279,6 +277,23 @@ public void testBuildEntityRegionPersonPlusEntityOverridesWithoutCfg() {
279277 }
280278 }
281279
280+ @ Test
281+ public void testBuildImmutableEntityRegion () {
282+ AdvancedCache cache ;
283+ Properties p = new Properties ();
284+ InfinispanRegionFactory factory = createRegionFactory (p );
285+ try {
286+ factory .getCacheManager ();
287+ EntityRegionImpl region = (EntityRegionImpl ) factory .buildEntityRegion ("com.acme.Address" , p , IMMUTABLE_NON_VERSIONED );
288+ assertNull (factory .getTypeOverrides ().get ("com.acme.Address" ));
289+ cache = region .getCache ();
290+ Configuration cacheCfg = cache .getCacheConfiguration ();
291+ assertEquals ("Immutable entity should get non-transactional cache" , TransactionMode .NON_TRANSACTIONAL , cacheCfg .transaction ().transactionMode ());
292+ } finally {
293+ factory .stop ();
294+ }
295+ }
296+
282297 @ Test (expected = CacheException .class )
283298 public void testTimestampValidation () {
284299 Properties p = createProperties ();
@@ -448,12 +463,12 @@ public void testEnableStatistics() {
448463 try {
449464 EmbeddedCacheManager manager = factory .getCacheManager ();
450465 assertTrue (manager .getCacheManagerConfiguration ().globalJmxStatistics ().enabled ());
451- EntityRegionImpl region = (EntityRegionImpl ) factory .buildEntityRegion ("com.acme.Address" , p , null );
466+ EntityRegionImpl region = (EntityRegionImpl ) factory .buildEntityRegion ("com.acme.Address" , p , MUTABLE_NON_VERSIONED );
452467 AdvancedCache cache = region .getCache ();
453468 assertTrue (factory .getTypeOverrides ().get ("entity" ).isExposeStatistics ());
454469 assertTrue (cache .getCacheConfiguration ().jmxStatistics ().enabled ());
455470
456- region = (EntityRegionImpl ) factory .buildEntityRegion ("com.acme.Person" , p , null );
471+ region = (EntityRegionImpl ) factory .buildEntityRegion ("com.acme.Person" , p , MUTABLE_NON_VERSIONED );
457472 cache = region .getCache ();
458473 assertTrue (factory .getTypeOverrides ().get ("com.acme.Person" ).isExposeStatistics ());
459474 assertTrue (cache .getCacheConfiguration ().jmxStatistics ().enabled ());
@@ -476,7 +491,7 @@ public void testEnableStatistics() {
476491 assertTrue (cache .getCacheConfiguration ().jmxStatistics ().enabled ());
477492
478493 CollectionRegionImpl collectionRegion = (CollectionRegionImpl )
479- factory .buildCollectionRegion ("com.acme.Person.addresses" , p , null );
494+ factory .buildCollectionRegion ("com.acme.Person.addresses" , p , MUTABLE_NON_VERSIONED );
480495 cache = collectionRegion .getCache ();
481496 assertTrue (factory .getTypeOverrides ().get ("collection" ).isExposeStatistics ());
482497 assertTrue (cache .getCacheConfiguration ().jmxStatistics ().enabled ());
@@ -497,12 +512,12 @@ public void testDisableStatistics() {
497512 p .setProperty ("hibernate.cache.infinispan.entity.eviction.max_entries" , "10000" );
498513 InfinispanRegionFactory factory = createRegionFactory (p );
499514 try {
500- EntityRegionImpl region = (EntityRegionImpl ) factory .buildEntityRegion ("com.acme.Address" , p , null );
515+ EntityRegionImpl region = (EntityRegionImpl ) factory .buildEntityRegion ("com.acme.Address" , p , MUTABLE_NON_VERSIONED );
501516 AdvancedCache cache = region .getCache ();
502517 assertFalse (factory .getTypeOverrides ().get ("entity" ).isExposeStatistics ());
503518 assertFalse (cache .getCacheConfiguration ().jmxStatistics ().enabled ());
504519
505- region = (EntityRegionImpl ) factory .buildEntityRegion ("com.acme.Person" , p , null );
520+ region = (EntityRegionImpl ) factory .buildEntityRegion ("com.acme.Person" , p , MUTABLE_NON_VERSIONED );
506521 cache = region .getCache ();
507522 assertFalse (factory .getTypeOverrides ().get ("com.acme.Person" ).isExposeStatistics ());
508523 assertFalse (cache .getCacheConfiguration ().jmxStatistics ().enabled ());
@@ -524,7 +539,7 @@ public void testDisableStatistics() {
524539 assertFalse (cache .getCacheConfiguration ().jmxStatistics ().enabled ());
525540
526541 CollectionRegionImpl collectionRegion = (CollectionRegionImpl )
527- factory .buildCollectionRegion ("com.acme.Person.addresses" , p , null );
542+ factory .buildCollectionRegion ("com.acme.Person.addresses" , p , MUTABLE_NON_VERSIONED );
528543 cache = collectionRegion .getCache ();
529544 assertFalse (factory .getTypeOverrides ().get ("collection" ).isExposeStatistics ());
530545 assertFalse (cache .getCacheConfiguration ().jmxStatistics ().enabled ());
0 commit comments