Search in sources :

Example 26 with Configuration

use of org.infinispan.configuration.cache.Configuration in project hibernate-orm by hibernate.

the class InfinispanRegionFactoryTestCase method testBuildDiffCacheNameTimestampsRegion.

@Test
public void testBuildDiffCacheNameTimestampsRegion() {
    final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
    final String unrecommendedTimestamps = "unrecommended-timestamps";
    Properties p = createProperties();
    p.setProperty(TIMESTAMPS_CACHE_RESOURCE_PROP, unrecommendedTimestamps);
    TestInfinispanRegionFactory factory = createRegionFactory(p, (f, m) -> {
        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.clustering().stateTransfer().fetchInMemoryState(true);
        builder.clustering().cacheMode(CacheMode.REPL_SYNC);
        m.defineConfiguration(unrecommendedTimestamps, builder.build());
    });
    try {
        assertEquals(unrecommendedTimestamps, factory.getBaseConfiguration(DataType.TIMESTAMPS));
        TimestampsRegionImpl region = (TimestampsRegionImpl) factory.buildTimestampsRegion(timestamps, p);
        AdvancedCache cache = region.getCache();
        Configuration cacheCfg = cache.getCacheConfiguration();
        assertEquals(EvictionStrategy.NONE, cacheCfg.eviction().strategy());
        assertEquals(CacheMode.REPL_SYNC, cacheCfg.clustering().cacheMode());
        assertFalse(cacheCfg.storeAsBinary().enabled());
        assertFalse(cacheCfg.jmxStatistics().enabled());
    } finally {
        factory.stop();
    }
}
Also used : 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) Configuration(org.infinispan.configuration.cache.Configuration) AdvancedCache(org.infinispan.AdvancedCache) Properties(java.util.Properties) Test(org.junit.Test)

Example 27 with Configuration

use of org.infinispan.configuration.cache.Configuration in project hibernate-orm by hibernate.

the class InfinispanRegionFactoryTestCase method testCustomPendingPutsCache.

@Test
public void testCustomPendingPutsCache() {
    Properties p = createProperties();
    p.setProperty(INFINISPAN_CONFIG_RESOURCE_PROP, "alternative-infinispan-configs.xml");
    InfinispanRegionFactory factory = createRegionFactory(p);
    try {
        Configuration ppConfig = factory.getCacheManager().getCacheConfiguration(DEF_PENDING_PUTS_RESOURCE);
        assertEquals(120000, ppConfig.expiration().maxIdle());
    } finally {
        factory.stop();
    }
}
Also used : InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) Configuration(org.infinispan.configuration.cache.Configuration) Properties(java.util.Properties) Test(org.junit.Test)

Example 28 with Configuration

use of org.infinispan.configuration.cache.Configuration 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 29 with Configuration

use of org.infinispan.configuration.cache.Configuration in project hibernate-orm by hibernate.

the class InfinispanRegionFactoryTestCase method testDefaultPendingPutsCache.

@Test
public void testDefaultPendingPutsCache() {
    Properties p = createProperties();
    InfinispanRegionFactory factory = createRegionFactory(p);
    try {
        Configuration ppConfig = factory.getCacheManager().getCacheConfiguration(DEF_PENDING_PUTS_RESOURCE);
        assertTrue(ppConfig.isTemplate());
        assertFalse(ppConfig.clustering().cacheMode().isClustered());
        assertTrue(ppConfig.simpleCache());
        assertEquals(TransactionMode.NON_TRANSACTIONAL, ppConfig.transaction().transactionMode());
        assertEquals(60000, ppConfig.expiration().maxIdle());
        assertFalse(ppConfig.jmxStatistics().enabled());
        assertFalse(ppConfig.jmxStatistics().available());
    } finally {
        factory.stop();
    }
}
Also used : InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) Configuration(org.infinispan.configuration.cache.Configuration) Properties(java.util.Properties) Test(org.junit.Test)

Example 30 with Configuration

use of org.infinispan.configuration.cache.Configuration in project hibernate-orm by hibernate.

the class InfinispanRegionFactory method defineDataTypeCacheConfigurations.

private void defineDataTypeCacheConfigurations() {
    for (DataType type : DataType.values()) {
        String cacheName = baseConfigurations.get(type.key);
        if (cacheName == null) {
            cacheName = type.defaultCacheName;
        }
        Configuration configuration = manager.getCacheConfiguration(cacheName);
        ConfigurationBuilder builder;
        if (configuration == null) {
            log.debugf("Cache configuration not found for %s", type);
            if (!cacheName.equals(type.defaultCacheName)) {
                log.customConfigForTypeNotFound(cacheName, type.key);
            }
            builder = defaultConfiguration.getNamedConfigurationBuilders().get(type.defaultCacheName);
            if (builder == null) {
                throw new IllegalStateException("Generic data types must have default configuration, none found for " + type);
            }
        } else {
            builder = new ConfigurationBuilder().read(configuration);
        }
        ConfigurationBuilder override = configOverrides.get(type.key);
        if (override != null) {
            builder.read(override.build(false));
        }
        builder.template(true);
        configureTransactionManager(builder);
        dataTypeConfigurations.put(type, builder.build());
    }
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) TransactionConfiguration(org.infinispan.configuration.cache.TransactionConfiguration) Configuration(org.infinispan.configuration.cache.Configuration)

Aggregations

Configuration (org.infinispan.configuration.cache.Configuration)37 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)24 Test (org.junit.Test)24 Properties (java.util.Properties)12 AdvancedCache (org.infinispan.AdvancedCache)9 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)6 InfinispanRegionFactory (org.hibernate.cache.infinispan.InfinispanRegionFactory)5 EntityRegionImpl (org.hibernate.cache.infinispan.entity.EntityRegionImpl)4 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)4 CacheMode (org.infinispan.configuration.cache.CacheMode)3 TransactionConfiguration (org.infinispan.configuration.cache.TransactionConfiguration)3 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)3 CollectionRegionImpl (org.hibernate.cache.infinispan.collection.CollectionRegionImpl)2 QueryResultsRegionImpl (org.hibernate.cache.infinispan.query.QueryResultsRegionImpl)2 TimestampsRegionImpl (org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl)2 DefaultCacheManager (org.infinispan.manager.DefaultCacheManager)2 CacheProperties (org.wildfly.clustering.ee.cache.CacheProperties)2 TransactionBatch (org.wildfly.clustering.ee.infinispan.TransactionBatch)2 Method (java.lang.reflect.Method)1 Map (java.util.Map)1