6
6
*/
7
7
package org .hibernate .test .cache .infinispan ;
8
8
9
- import java .util .Properties ;
10
- import javax .transaction .TransactionManager ;
11
-
12
9
import org .hibernate .boot .spi .SessionFactoryOptions ;
13
10
import org .hibernate .cache .CacheException ;
14
11
import org .hibernate .cache .infinispan .InfinispanRegionFactory ;
17
14
import org .hibernate .cache .infinispan .query .QueryResultsRegionImpl ;
18
15
import org .hibernate .cache .infinispan .timestamp .TimestampsRegionImpl ;
19
16
import org .hibernate .cache .infinispan .tm .HibernateTransactionManagerLookup ;
17
+ import org .hibernate .cache .internal .CacheDataDescriptionImpl ;
18
+ import org .hibernate .cache .spi .CacheDataDescription ;
20
19
import org .hibernate .cfg .Environment ;
21
20
import org .hibernate .engine .transaction .jta .platform .internal .AbstractJtaPlatform ;
22
21
import org .hibernate .engine .transaction .jta .platform .internal .JBossStandAloneJtaPlatform ;
23
-
24
- import org .hibernate .testing .ServiceRegistryBuilder ;
25
22
import org .hibernate .test .cache .infinispan .functional .SingleNodeTestCase ;
26
- import org .junit .Test ;
27
-
23
+ import org .hibernate .testing .ServiceRegistryBuilder ;
28
24
import org .infinispan .AdvancedCache ;
29
25
import org .infinispan .configuration .cache .CacheMode ;
30
26
import org .infinispan .configuration .cache .Configuration ;
34
30
import org .infinispan .manager .DefaultCacheManager ;
35
31
import org .infinispan .manager .EmbeddedCacheManager ;
36
32
import 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 ;
37
38
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 .*;
44
40
45
41
/**
46
42
* InfinispanRegionFactoryTestCase.
49
45
* @since 3.5
50
46
*/
51
47
public 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 );
52
50
53
51
@ Test
54
52
public void testConfigurationProcessing () {
@@ -136,7 +134,7 @@ public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides(
136
134
assertFalse (factory .getDefinedConfigurations ().contains (addresses ));
137
135
AdvancedCache cache ;
138
136
139
- EntityRegionImpl region = (EntityRegionImpl ) factory .buildEntityRegion (person , p , null );
137
+ EntityRegionImpl region = (EntityRegionImpl ) factory .buildEntityRegion (person , p , MUTABLE_NON_VERSIONED );
140
138
assertNotNull (factory .getTypeOverrides ().get (person ));
141
139
assertTrue (factory .getDefinedConfigurations ().contains (person ));
142
140
assertNull (factory .getTypeOverrides ().get (address ));
@@ -149,7 +147,7 @@ public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides(
149
147
assertEquals (30000 , cacheCfg .expiration ().maxIdle ());
150
148
assertFalse (cacheCfg .jmxStatistics ().enabled ());
151
149
152
- region = (EntityRegionImpl ) factory .buildEntityRegion (address , p , null );
150
+ region = (EntityRegionImpl ) factory .buildEntityRegion (address , p , MUTABLE_NON_VERSIONED );
153
151
assertNotNull (factory .getTypeOverrides ().get (person ));
154
152
assertTrue (factory .getDefinedConfigurations ().contains (person ));
155
153
assertNull (factory .getTypeOverrides ().get (address ));
@@ -160,7 +158,7 @@ public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides(
160
158
assertEquals (20000 , cacheCfg .eviction ().maxEntries ());
161
159
assertFalse (cacheCfg .jmxStatistics ().enabled ());
162
160
163
- region = (EntityRegionImpl ) factory .buildEntityRegion (car , p , null );
161
+ region = (EntityRegionImpl ) factory .buildEntityRegion (car , p , MUTABLE_NON_VERSIONED );
164
162
assertNotNull (factory .getTypeOverrides ().get (person ));
165
163
assertTrue (factory .getDefinedConfigurations ().contains (person ));
166
164
assertNull (factory .getTypeOverrides ().get (address ));
@@ -172,7 +170,7 @@ public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides(
172
170
assertFalse (cacheCfg .jmxStatistics ().enabled ());
173
171
174
172
CollectionRegionImpl collectionRegion = (CollectionRegionImpl )
175
- factory .buildCollectionRegion (addresses , p , null );
173
+ factory .buildCollectionRegion (addresses , p , MUTABLE_NON_VERSIONED );
176
174
assertNotNull (factory .getTypeOverrides ().get (addresses ));
177
175
assertTrue (factory .getDefinedConfigurations ().contains (person ));
178
176
assertNull (factory .getTypeOverrides ().get (parts ));
@@ -185,7 +183,7 @@ public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides(
185
183
assertEquals (35000 , cacheCfg .expiration ().maxIdle ());
186
184
assertFalse (cacheCfg .jmxStatistics ().enabled ());
187
185
188
- collectionRegion = (CollectionRegionImpl ) factory .buildCollectionRegion (parts , p , null );
186
+ collectionRegion = (CollectionRegionImpl ) factory .buildCollectionRegion (parts , p , MUTABLE_NON_VERSIONED );
189
187
assertNotNull (factory .getTypeOverrides ().get (addresses ));
190
188
assertTrue (factory .getDefinedConfigurations ().contains (addresses ));
191
189
assertNull (factory .getTypeOverrides ().get (parts ));
@@ -196,7 +194,7 @@ public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides(
196
194
assertEquals (25000 , cacheCfg .eviction ().maxEntries ());
197
195
assertFalse (cacheCfg .jmxStatistics ().enabled ());
198
196
199
- collectionRegion = (CollectionRegionImpl ) factory .buildCollectionRegion (parts , p , null );
197
+ collectionRegion = (CollectionRegionImpl ) factory .buildCollectionRegion (parts , p , MUTABLE_NON_VERSIONED );
200
198
assertNotNull (factory .getTypeOverrides ().get (addresses ));
201
199
assertTrue (factory .getDefinedConfigurations ().contains (addresses ));
202
200
assertNull (factory .getTypeOverrides ().get (parts ));
@@ -224,7 +222,7 @@ public void testBuildEntityCollectionRegionOverridesOnly() {
224
222
InfinispanRegionFactory factory = createRegionFactory (p );
225
223
try {
226
224
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 );
228
226
assertNull (factory .getTypeOverrides ().get ("com.acme.Address" ));
229
227
cache = region .getCache ();
230
228
Configuration cacheCfg = cache .getCacheConfiguration ();
@@ -235,7 +233,7 @@ public void testBuildEntityCollectionRegionOverridesOnly() {
235
233
assertEquals (100000 , cacheCfg .expiration ().maxIdle ());
236
234
237
235
CollectionRegionImpl collectionRegion = (CollectionRegionImpl )
238
- factory .buildCollectionRegion ("com.acme.Person.addresses" , p , null );
236
+ factory .buildCollectionRegion ("com.acme.Person.addresses" , p , MUTABLE_NON_VERSIONED );
239
237
assertNull (factory .getTypeOverrides ().get ("com.acme.Person.addresses" ));
240
238
cache = collectionRegion .getCache ();
241
239
cacheCfg = cache .getCacheConfiguration ();
@@ -264,7 +262,7 @@ public void testBuildEntityRegionPersonPlusEntityOverridesWithoutCfg() {
264
262
factory .getCacheManager ();
265
263
assertNotNull (factory .getTypeOverrides ().get (person ));
266
264
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 );
268
266
assertNotNull (factory .getTypeOverrides ().get (person ));
269
267
assertTrue (factory .getDefinedConfigurations ().contains (person ));
270
268
AdvancedCache cache = region .getCache ();
@@ -279,6 +277,23 @@ public void testBuildEntityRegionPersonPlusEntityOverridesWithoutCfg() {
279
277
}
280
278
}
281
279
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
+
282
297
@ Test (expected = CacheException .class )
283
298
public void testTimestampValidation () {
284
299
Properties p = createProperties ();
@@ -448,12 +463,12 @@ public void testEnableStatistics() {
448
463
try {
449
464
EmbeddedCacheManager manager = factory .getCacheManager ();
450
465
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 );
452
467
AdvancedCache cache = region .getCache ();
453
468
assertTrue (factory .getTypeOverrides ().get ("entity" ).isExposeStatistics ());
454
469
assertTrue (cache .getCacheConfiguration ().jmxStatistics ().enabled ());
455
470
456
- region = (EntityRegionImpl ) factory .buildEntityRegion ("com.acme.Person" , p , null );
471
+ region = (EntityRegionImpl ) factory .buildEntityRegion ("com.acme.Person" , p , MUTABLE_NON_VERSIONED );
457
472
cache = region .getCache ();
458
473
assertTrue (factory .getTypeOverrides ().get ("com.acme.Person" ).isExposeStatistics ());
459
474
assertTrue (cache .getCacheConfiguration ().jmxStatistics ().enabled ());
@@ -476,7 +491,7 @@ public void testEnableStatistics() {
476
491
assertTrue (cache .getCacheConfiguration ().jmxStatistics ().enabled ());
477
492
478
493
CollectionRegionImpl collectionRegion = (CollectionRegionImpl )
479
- factory .buildCollectionRegion ("com.acme.Person.addresses" , p , null );
494
+ factory .buildCollectionRegion ("com.acme.Person.addresses" , p , MUTABLE_NON_VERSIONED );
480
495
cache = collectionRegion .getCache ();
481
496
assertTrue (factory .getTypeOverrides ().get ("collection" ).isExposeStatistics ());
482
497
assertTrue (cache .getCacheConfiguration ().jmxStatistics ().enabled ());
@@ -497,12 +512,12 @@ public void testDisableStatistics() {
497
512
p .setProperty ("hibernate.cache.infinispan.entity.eviction.max_entries" , "10000" );
498
513
InfinispanRegionFactory factory = createRegionFactory (p );
499
514
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 );
501
516
AdvancedCache cache = region .getCache ();
502
517
assertFalse (factory .getTypeOverrides ().get ("entity" ).isExposeStatistics ());
503
518
assertFalse (cache .getCacheConfiguration ().jmxStatistics ().enabled ());
504
519
505
- region = (EntityRegionImpl ) factory .buildEntityRegion ("com.acme.Person" , p , null );
520
+ region = (EntityRegionImpl ) factory .buildEntityRegion ("com.acme.Person" , p , MUTABLE_NON_VERSIONED );
506
521
cache = region .getCache ();
507
522
assertFalse (factory .getTypeOverrides ().get ("com.acme.Person" ).isExposeStatistics ());
508
523
assertFalse (cache .getCacheConfiguration ().jmxStatistics ().enabled ());
@@ -524,7 +539,7 @@ public void testDisableStatistics() {
524
539
assertFalse (cache .getCacheConfiguration ().jmxStatistics ().enabled ());
525
540
526
541
CollectionRegionImpl collectionRegion = (CollectionRegionImpl )
527
- factory .buildCollectionRegion ("com.acme.Person.addresses" , p , null );
542
+ factory .buildCollectionRegion ("com.acme.Person.addresses" , p , MUTABLE_NON_VERSIONED );
528
543
cache = collectionRegion .getCache ();
529
544
assertFalse (factory .getTypeOverrides ().get ("collection" ).isExposeStatistics ());
530
545
assertFalse (cache .getCacheConfiguration ().jmxStatistics ().enabled ());
0 commit comments