Search in sources :

Example 31 with ConfigurationBuilder

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

the class TestInfinispanRegionFactory method amendConfiguration.

protected void amendConfiguration(ConfigurationBuilderHolder holder) {
    holder.getGlobalConfigurationBuilder().globalJmxStatistics().allowDuplicateDomains(true);
    TransportConfigurationBuilder transport = holder.getGlobalConfigurationBuilder().transport();
    transport.nodeName(TestResourceTracker.getNextNodeName());
    transport.clusterName(TestResourceTracker.getCurrentTestName());
    // minimize number of threads using unlimited cached thread pool
    transport.remoteCommandThreadPool().threadPoolFactory(CachedThreadPoolExecutorFactory.create());
    transport.transportThreadPool().threadPoolFactory(CachedThreadPoolExecutorFactory.create());
    for (Map.Entry<String, ConfigurationBuilder> cfg : holder.getNamedConfigurationBuilders().entrySet()) {
        amendCacheConfiguration(cfg.getKey(), cfg.getValue());
    }
    // disable simple cache for testing as we need to insert interceptors
    if (!pendingPutsSimple) {
        holder.getNamedConfigurationBuilders().get(InfinispanRegionFactory.DEF_PENDING_PUTS_RESOURCE).simpleCache(false);
    }
}
Also used : TransportConfigurationBuilder(org.infinispan.configuration.global.TransportConfigurationBuilder) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) TransportConfigurationBuilder(org.infinispan.configuration.global.TransportConfigurationBuilder) Map(java.util.Map)

Example 32 with ConfigurationBuilder

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

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

the class InfinispanRegionFactoryTestCase method testBuildTimestampsRegionWithCacheNameOverride.

@Test
public void testBuildTimestampsRegionWithCacheNameOverride() {
    final String timestamps = "org.hibernate.cache.spi.UpdateTimestampsCache";
    final String myTimestampsCache = "mytimestamps-cache";
    Properties p = createProperties();
    p.setProperty(TIMESTAMPS_CACHE_RESOURCE_PROP, myTimestampsCache);
    InfinispanRegionFactory factory = createRegionFactory(p, (f, m) -> {
        ClusteringConfigurationBuilder builder = new ConfigurationBuilder().clustering().cacheMode(CacheMode.LOCAL);
        m.defineConfiguration(myTimestampsCache, builder.build());
    });
    try {
        TimestampsRegionImpl region = (TimestampsRegionImpl) factory.buildTimestampsRegion(timestamps, p);
        assertTrue(isDefinedCache(factory, timestamps));
        // default timestamps cache is async replicated
        assertEquals(CacheMode.LOCAL, region.getCache().getCacheConfiguration().clustering().cacheMode());
    } 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) InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) ClusteringConfigurationBuilder(org.infinispan.configuration.cache.ClusteringConfigurationBuilder) Properties(java.util.Properties) Test(org.junit.Test)

Example 34 with ConfigurationBuilder

use of org.infinispan.configuration.cache.ConfigurationBuilder 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)

Example 35 with ConfigurationBuilder

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

the class InfinispanRegionFactory method parseProperty.

private void parseProperty(int prefixLoc, String key, String value) {
    final ConfigurationBuilder builder;
    int suffixLoc;
    if ((suffixLoc = key.indexOf(CONFIG_SUFFIX)) != -1 && !key.equals(INFINISPAN_CONFIG_RESOURCE_PROP)) {
        String regionName = key.substring(prefixLoc + PREFIX.length(), suffixLoc);
        baseConfigurations.put(regionName, value);
    } else if ((suffixLoc = key.indexOf(STRATEGY_SUFFIX)) != -1) {
        builder = getOrCreateConfig(prefixLoc, key, suffixLoc);
        builder.eviction().strategy(EvictionStrategy.valueOf(value));
    } else if ((suffixLoc = key.indexOf(WAKE_UP_INTERVAL_SUFFIX)) != -1 || (suffixLoc = key.indexOf(DEPRECATED_WAKE_UP_INTERVAL_SUFFIX)) != -1) {
        builder = getOrCreateConfig(prefixLoc, key, suffixLoc);
        builder.expiration().wakeUpInterval(Long.parseLong(value));
    } else if ((suffixLoc = key.indexOf(MAX_ENTRIES_SUFFIX)) != -1) {
        builder = getOrCreateConfig(prefixLoc, key, suffixLoc);
        builder.eviction().size(Long.parseLong(value));
    } else if ((suffixLoc = key.indexOf(LIFESPAN_SUFFIX)) != -1) {
        builder = getOrCreateConfig(prefixLoc, key, suffixLoc);
        builder.expiration().lifespan(Long.parseLong(value));
    } else if ((suffixLoc = key.indexOf(MAX_IDLE_SUFFIX)) != -1) {
        builder = getOrCreateConfig(prefixLoc, key, suffixLoc);
        builder.expiration().maxIdle(Long.parseLong(value));
    }
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder)

Aggregations

ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)53 Configuration (org.infinispan.configuration.cache.Configuration)24 Test (org.junit.Test)19 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)14 DefaultCacheManager (org.infinispan.manager.DefaultCacheManager)12 ClusteringConfigurationBuilder (org.infinispan.configuration.cache.ClusteringConfigurationBuilder)7 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)7 Properties (java.util.Properties)6 Map (java.util.Map)5 InfinispanRegionFactory (org.hibernate.cache.infinispan.InfinispanRegionFactory)5 TimestampsRegionImpl (org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl)5 BeforeClass (org.junit.BeforeClass)5 AdvancedCache (org.infinispan.AdvancedCache)4 BackupConfigurationBuilder (org.infinispan.configuration.cache.BackupConfigurationBuilder)4 CacheMode (org.infinispan.configuration.cache.CacheMode)4 SitesConfigurationBuilder (org.infinispan.configuration.cache.SitesConfigurationBuilder)3 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)3 HashMap (java.util.HashMap)2 Consumer (java.util.function.Consumer)2 CacheProducer (org.commonjava.indy.subsys.infinispan.CacheProducer)2