use of org.hibernate.cache.infinispan.InfinispanRegionFactory in project hibernate-orm by hibernate.
the class InfinispanRegionFactoryTestCase method testEnableStatistics.
@Test
public void testEnableStatistics() {
Properties p = createProperties();
p.setProperty("hibernate.cache.infinispan.statistics", "true");
p.setProperty("hibernate.cache.infinispan.com.acme.Person.expiration.lifespan", "60000");
p.setProperty("hibernate.cache.infinispan.com.acme.Person.expiration.max_idle", "30000");
p.setProperty("hibernate.cache.infinispan.entity.cfg", "myentity-cache");
p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy", "FIFO");
p.setProperty("hibernate.cache.infinispan.entity.expiration.wake_up_interval", "3000");
p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries", "10000");
InfinispanRegionFactory factory = createRegionFactory(p);
try {
EmbeddedCacheManager manager = factory.getCacheManager();
assertTrue(manager.getCacheManagerConfiguration().globalJmxStatistics().enabled());
EntityRegionImpl region = (EntityRegionImpl) factory.buildEntityRegion("com.acme.Address", p, MUTABLE_NON_VERSIONED);
AdvancedCache cache = region.getCache();
assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
region = (EntityRegionImpl) factory.buildEntityRegion("com.acme.Person", p, MUTABLE_NON_VERSIONED);
cache = region.getCache();
assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
final String query = "org.hibernate.cache.internal.StandardQueryCache";
QueryResultsRegionImpl queryRegion = (QueryResultsRegionImpl) factory.buildQueryResultsRegion(query, p);
cache = queryRegion.getCache();
assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.clustering().stateTransfer().fetchInMemoryState(true);
manager.defineConfiguration("timestamps", builder.build());
TimestampsRegionImpl timestampsRegion = (TimestampsRegionImpl) factory.buildTimestampsRegion(timestamps, p);
cache = timestampsRegion.getCache();
assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
CollectionRegionImpl collectionRegion = (CollectionRegionImpl) factory.buildCollectionRegion("com.acme.Person.addresses", p, MUTABLE_NON_VERSIONED);
cache = collectionRegion.getCache();
assertTrue(cache.getCacheConfiguration().jmxStatistics().enabled());
} finally {
factory.stop();
}
}
use of org.hibernate.cache.infinispan.InfinispanRegionFactory in project hibernate-orm by hibernate.
the class InfinispanRegionFactoryTestCase method testBuildQueryRegion.
@Test
public void testBuildQueryRegion() {
final String query = "org.hibernate.cache.internal.StandardQueryCache";
Properties p = createProperties();
InfinispanRegionFactory factory = createRegionFactory(p);
try {
assertTrue(isDefinedCache(factory, "local-query"));
QueryResultsRegionImpl region = (QueryResultsRegionImpl) factory.buildQueryResultsRegion(query, p);
AdvancedCache cache = region.getCache();
Configuration cacheCfg = cache.getCacheConfiguration();
assertEquals(CacheMode.LOCAL, cacheCfg.clustering().cacheMode());
assertFalse(cacheCfg.jmxStatistics().enabled());
} finally {
factory.stop();
}
}
use of org.hibernate.cache.infinispan.InfinispanRegionFactory in project hibernate-orm by hibernate.
the class InfinispanRegionFactoryTestCase method testBuildTimestampsRegionWithFifoEvictionOverride.
@Test(expected = CacheException.class)
public void testBuildTimestampsRegionWithFifoEvictionOverride() {
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
final String myTimestampsCache = "mytimestamps-cache";
Properties p = createProperties();
p.setProperty(TIMESTAMPS_CACHE_RESOURCE_PROP, myTimestampsCache);
p.setProperty("hibernate.cache.infinispan.timestamps.eviction.strategy", "FIFO");
p.setProperty("hibernate.cache.infinispan.timestamps.eviction.max_entries", "10000");
p.setProperty("hibernate.cache.infinispan.timestamps.expiration.wake_up_interval", "3000");
InfinispanRegionFactory factory = null;
try {
factory = createRegionFactory(p);
factory.buildTimestampsRegion(timestamps, p);
} finally {
if (factory != null)
factory.stop();
}
}
use of org.hibernate.cache.infinispan.InfinispanRegionFactory in project hibernate-orm by hibernate.
the class InfinispanRegionFactoryTestCase method testBuildDefaultTimestampsRegion.
@Test
public void testBuildDefaultTimestampsRegion() {
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
Properties p = createProperties();
InfinispanRegionFactory factory = createRegionFactory(p);
try {
assertTrue(isDefinedCache(factory, DEF_TIMESTAMPS_RESOURCE));
TimestampsRegionImpl region = (TimestampsRegionImpl) factory.buildTimestampsRegion(timestamps, p);
AdvancedCache cache = region.getCache();
assertEquals(timestamps, cache.getName());
Configuration cacheCfg = cache.getCacheConfiguration();
assertEquals(EvictionStrategy.NONE, cacheCfg.eviction().strategy());
assertEquals(CacheMode.REPL_ASYNC, cacheCfg.clustering().cacheMode());
assertFalse(cacheCfg.jmxStatistics().enabled());
} finally {
factory.stop();
}
}
use of org.hibernate.cache.infinispan.InfinispanRegionFactory in project hibernate-orm by hibernate.
the class InfinispanRegionFactoryTestCase method testTimestampValidation.
@Test(expected = CacheException.class)
public void testTimestampValidation() {
final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
Properties p = createProperties();
InputStream configStream = FileLookupFactory.newInstance().lookupFile(InfinispanRegionFactory.DEF_INFINISPAN_CONFIG_RESOURCE, getClass().getClassLoader());
ConfigurationBuilderHolder cbh = new ParserRegistry().parse(configStream);
DefaultCacheManager manager = new DefaultCacheManager(cbh, true);
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.clustering().cacheMode(CacheMode.INVALIDATION_SYNC);
manager.defineConfiguration(DEF_TIMESTAMPS_RESOURCE, builder.build());
try {
InfinispanRegionFactory factory = createRegionFactory(manager, p, null);
factory.start(CacheTestUtil.sfOptionsForStart(), p);
TimestampsRegionImpl region = (TimestampsRegionImpl) factory.buildTimestampsRegion(timestamps, p);
fail("Should have failed saying that invalidation is not allowed for timestamp caches.");
} finally {
TestingUtil.killCacheManagers(manager);
}
}
Aggregations