Search in sources :

Example 11 with EntityRegionImpl

use of org.hibernate.cache.infinispan.entity.EntityRegionImpl in project hibernate-orm by hibernate.

the class InfinispanRegionFactoryTestCase method testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides.

@Test
public void testBuildEntityCollectionRegionsPersonPlusEntityCollectionOverrides() {
    final String person = "com.acme.Person";
    final String address = "com.acme.Address";
    final String car = "com.acme.Car";
    final String addresses = "com.acme.Person.addresses";
    final String parts = "com.acme.Car.parts";
    Properties p = createProperties();
    // First option, cache defined for entity and overrides for generic entity data type and entity itself.
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.cfg", "person-cache");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.strategy", "LRU");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.eviction.max_entries", "5000");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.expiration.wake_up_interval", "2000");
    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", "LIRS");
    p.setProperty("hibernate.cache.infinispan.entity.expiration.wake_up_interval", "3000");
    p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries", "20000");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.cfg", "addresses-cache");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.eviction.strategy", "LIRS");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.eviction.max_entries", "5500");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.expiration.wake_up_interval", "2500");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.expiration.lifespan", "65000");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.expiration.max_idle", "35000");
    p.setProperty("hibernate.cache.infinispan.collection.cfg", "mycollection-cache");
    p.setProperty("hibernate.cache.infinispan.collection.eviction.strategy", "LRU");
    p.setProperty("hibernate.cache.infinispan.collection.expiration.wake_up_interval", "3500");
    p.setProperty("hibernate.cache.infinispan.collection.eviction.max_entries", "25000");
    TestInfinispanRegionFactory factory = createRegionFactory(p);
    try {
        EmbeddedCacheManager manager = factory.getCacheManager();
        assertFalse(manager.getCacheManagerConfiguration().globalJmxStatistics().enabled());
        assertNotNull(factory.getBaseConfiguration(person));
        assertFalse(isDefinedCache(factory, person));
        assertNotNull(factory.getBaseConfiguration(addresses));
        assertFalse(isDefinedCache(factory, addresses));
        assertNull(factory.getBaseConfiguration(address));
        assertNull(factory.getBaseConfiguration(parts));
        AdvancedCache cache;
        EntityRegionImpl region = (EntityRegionImpl) factory.buildEntityRegion(person, p, MUTABLE_NON_VERSIONED);
        assertTrue(isDefinedCache(factory, person));
        cache = region.getCache();
        Configuration cacheCfg = cache.getCacheConfiguration();
        assertEquals(EvictionStrategy.LRU, cacheCfg.eviction().strategy());
        assertEquals(2000, cacheCfg.expiration().wakeUpInterval());
        assertEquals(5000, cacheCfg.eviction().maxEntries());
        assertEquals(60000, cacheCfg.expiration().lifespan());
        assertEquals(30000, cacheCfg.expiration().maxIdle());
        assertFalse(cacheCfg.jmxStatistics().enabled());
        region = (EntityRegionImpl) factory.buildEntityRegion(address, p, MUTABLE_NON_VERSIONED);
        assertTrue(isDefinedCache(factory, person));
        cache = region.getCache();
        cacheCfg = cache.getCacheConfiguration();
        assertEquals(EvictionStrategy.LIRS, cacheCfg.eviction().strategy());
        assertEquals(3000, cacheCfg.expiration().wakeUpInterval());
        assertEquals(20000, cacheCfg.eviction().maxEntries());
        assertFalse(cacheCfg.jmxStatistics().enabled());
        region = (EntityRegionImpl) factory.buildEntityRegion(car, p, MUTABLE_NON_VERSIONED);
        assertTrue(isDefinedCache(factory, person));
        cache = region.getCache();
        cacheCfg = cache.getCacheConfiguration();
        assertEquals(EvictionStrategy.LIRS, cacheCfg.eviction().strategy());
        assertEquals(3000, cacheCfg.expiration().wakeUpInterval());
        assertEquals(20000, cacheCfg.eviction().maxEntries());
        assertFalse(cacheCfg.jmxStatistics().enabled());
        CollectionRegionImpl collectionRegion = (CollectionRegionImpl) factory.buildCollectionRegion(addresses, p, MUTABLE_NON_VERSIONED);
        assertTrue(isDefinedCache(factory, person));
        cache = collectionRegion.getCache();
        cacheCfg = cache.getCacheConfiguration();
        assertEquals(EvictionStrategy.LIRS, cacheCfg.eviction().strategy());
        assertEquals(2500, cacheCfg.expiration().wakeUpInterval());
        assertEquals(5500, cacheCfg.eviction().maxEntries());
        assertEquals(65000, cacheCfg.expiration().lifespan());
        assertEquals(35000, cacheCfg.expiration().maxIdle());
        assertFalse(cacheCfg.jmxStatistics().enabled());
        collectionRegion = (CollectionRegionImpl) factory.buildCollectionRegion(parts, p, MUTABLE_NON_VERSIONED);
        assertTrue(isDefinedCache(factory, addresses));
        cache = collectionRegion.getCache();
        cacheCfg = cache.getCacheConfiguration();
        assertEquals(EvictionStrategy.LRU, cacheCfg.eviction().strategy());
        assertEquals(3500, cacheCfg.expiration().wakeUpInterval());
        assertEquals(25000, cacheCfg.eviction().maxEntries());
        assertFalse(cacheCfg.jmxStatistics().enabled());
        collectionRegion = (CollectionRegionImpl) factory.buildCollectionRegion(parts, p, MUTABLE_NON_VERSIONED);
        assertTrue(isDefinedCache(factory, addresses));
        cache = collectionRegion.getCache();
        cacheCfg = cache.getCacheConfiguration();
        assertEquals(EvictionStrategy.LRU, cacheCfg.eviction().strategy());
        assertEquals(3500, cacheCfg.expiration().wakeUpInterval());
        assertEquals(25000, cacheCfg.eviction().maxEntries());
        assertFalse(cacheCfg.jmxStatistics().enabled());
    } finally {
        factory.stop();
    }
}
Also used : EntityRegionImpl(org.hibernate.cache.infinispan.entity.EntityRegionImpl) Configuration(org.infinispan.configuration.cache.Configuration) CollectionRegionImpl(org.hibernate.cache.infinispan.collection.CollectionRegionImpl) AdvancedCache(org.infinispan.AdvancedCache) Properties(java.util.Properties) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) Test(org.junit.Test)

Example 12 with EntityRegionImpl

use of org.hibernate.cache.infinispan.entity.EntityRegionImpl in project hibernate-orm by hibernate.

the class InfinispanRegionFactoryTestCase method testDisableStatistics.

@Test
public void testDisableStatistics() {
    Properties p = createProperties();
    p.setProperty("hibernate.cache.infinispan.statistics", "false");
    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 {
        EntityRegionImpl region = (EntityRegionImpl) factory.buildEntityRegion("com.acme.Address", p, MUTABLE_NON_VERSIONED);
        AdvancedCache cache = region.getCache();
        assertFalse(cache.getCacheConfiguration().jmxStatistics().enabled());
        region = (EntityRegionImpl) factory.buildEntityRegion("com.acme.Person", p, MUTABLE_NON_VERSIONED);
        cache = region.getCache();
        assertFalse(cache.getCacheConfiguration().jmxStatistics().enabled());
        final String query = "org.hibernate.cache.internal.StandardQueryCache";
        QueryResultsRegionImpl queryRegion = (QueryResultsRegionImpl) factory.buildQueryResultsRegion(query, p);
        cache = queryRegion.getCache();
        assertFalse(cache.getCacheConfiguration().jmxStatistics().enabled());
        final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.clustering().stateTransfer().fetchInMemoryState(true);
        factory.getCacheManager().defineConfiguration("timestamps", builder.build());
        TimestampsRegionImpl timestampsRegion = (TimestampsRegionImpl) factory.buildTimestampsRegion(timestamps, p);
        cache = timestampsRegion.getCache();
        assertFalse(cache.getCacheConfiguration().jmxStatistics().enabled());
        CollectionRegionImpl collectionRegion = (CollectionRegionImpl) factory.buildCollectionRegion("com.acme.Person.addresses", p, MUTABLE_NON_VERSIONED);
        cache = collectionRegion.getCache();
        assertFalse(cache.getCacheConfiguration().jmxStatistics().enabled());
    } finally {
        factory.stop();
    }
}
Also used : QueryResultsRegionImpl(org.hibernate.cache.infinispan.query.QueryResultsRegionImpl) TimestampsRegionImpl(org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) ClusteringConfigurationBuilder(org.infinispan.configuration.cache.ClusteringConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) EntityRegionImpl(org.hibernate.cache.infinispan.entity.EntityRegionImpl) CollectionRegionImpl(org.hibernate.cache.infinispan.collection.CollectionRegionImpl) AdvancedCache(org.infinispan.AdvancedCache) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

EntityRegionImpl (org.hibernate.cache.infinispan.entity.EntityRegionImpl)12 AdvancedCache (org.infinispan.AdvancedCache)10 Test (org.junit.Test)8 Properties (java.util.Properties)6 CollectionRegionImpl (org.hibernate.cache.infinispan.collection.CollectionRegionImpl)4 Configuration (org.infinispan.configuration.cache.Configuration)4 Item (org.hibernate.test.cache.infinispan.functional.entities.Item)3 InfinispanRegionFactory (org.hibernate.cache.infinispan.InfinispanRegionFactory)2 QueryResultsRegionImpl (org.hibernate.cache.infinispan.query.QueryResultsRegionImpl)2 TimestampsRegionImpl (org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl)2 CloseableIterator (org.infinispan.commons.util.CloseableIterator)2 ClusteringConfigurationBuilder (org.infinispan.configuration.cache.ClusteringConfigurationBuilder)2 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)2 Before (org.junit.Before)1