Search in sources :

Example 6 with Configuration

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

the class InfinispanRegionFactoryTestCase method testBuildEntityCollectionRegionOverridesOnly.

@Test
public void testBuildEntityCollectionRegionOverridesOnly() {
    final String address = "com.acme.Address";
    final String personAddressses = "com.acme.Person.addresses";
    AdvancedCache cache;
    Properties p = createProperties();
    p.setProperty("hibernate.cache.infinispan.entity.eviction.strategy", "LIRS");
    p.setProperty("hibernate.cache.infinispan.entity.eviction.max_entries", "30000");
    p.setProperty("hibernate.cache.infinispan.entity.expiration.wake_up_interval", "3000");
    p.setProperty("hibernate.cache.infinispan.collection.eviction.strategy", "LRU");
    p.setProperty("hibernate.cache.infinispan.collection.eviction.max_entries", "35000");
    p.setProperty("hibernate.cache.infinispan.collection.expiration.wake_up_interval", "3500");
    TestInfinispanRegionFactory factory = createRegionFactory(p);
    try {
        factory.getCacheManager();
        EntityRegionImpl region = (EntityRegionImpl) factory.buildEntityRegion(address, p, MUTABLE_NON_VERSIONED);
        assertNull(factory.getBaseConfiguration(address));
        cache = region.getCache();
        Configuration cacheCfg = cache.getCacheConfiguration();
        assertEquals(EvictionStrategy.LIRS, cacheCfg.eviction().strategy());
        assertEquals(3000, cacheCfg.expiration().wakeUpInterval());
        assertEquals(30000, cacheCfg.eviction().maxEntries());
        // Max idle value comes from base XML configuration
        assertEquals(100000, cacheCfg.expiration().maxIdle());
        CollectionRegionImpl collectionRegion = (CollectionRegionImpl) factory.buildCollectionRegion(personAddressses, p, MUTABLE_NON_VERSIONED);
        assertNull(factory.getBaseConfiguration(personAddressses));
        cache = collectionRegion.getCache();
        cacheCfg = cache.getCacheConfiguration();
        assertEquals(EvictionStrategy.LRU, cacheCfg.eviction().strategy());
        assertEquals(3500, cacheCfg.expiration().wakeUpInterval());
        assertEquals(35000, cacheCfg.eviction().maxEntries());
        assertEquals(100000, cacheCfg.expiration().maxIdle());
    } 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) Test(org.junit.Test)

Example 7 with Configuration

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

the class InfinispanRegionFactoryTestCase method testBuildImmutableEntityRegion.

@Test
public void testBuildImmutableEntityRegion() {
    AdvancedCache cache;
    Properties p = new Properties();
    TestInfinispanRegionFactory factory = createRegionFactory(p);
    try {
        factory.getCacheManager();
        EntityRegionImpl region = (EntityRegionImpl) factory.buildEntityRegion("com.acme.Address", p, IMMUTABLE_NON_VERSIONED);
        assertNull(factory.getBaseConfiguration("com.acme.Address"));
        cache = region.getCache();
        Configuration cacheCfg = cache.getCacheConfiguration();
        assertEquals("Immutable entity should get non-transactional cache", TransactionMode.NON_TRANSACTIONAL, cacheCfg.transaction().transactionMode());
    } finally {
        factory.stop();
    }
}
Also used : EntityRegionImpl(org.hibernate.cache.infinispan.entity.EntityRegionImpl) Configuration(org.infinispan.configuration.cache.Configuration) AdvancedCache(org.infinispan.AdvancedCache) Properties(java.util.Properties) Test(org.junit.Test)

Example 8 with Configuration

use of org.infinispan.configuration.cache.Configuration 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();
    }
}
Also used : TimestampsRegionImpl(org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl) InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) Configuration(org.infinispan.configuration.cache.Configuration) AdvancedCache(org.infinispan.AdvancedCache) Properties(java.util.Properties) Test(org.junit.Test)

Example 9 with Configuration

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

the class InfinispanRegionFactoryTestCase method testConfigurationProcessing.

@Test
public void testConfigurationProcessing() {
    final String person = "com.acme.Person";
    final String addresses = "com.acme.Person.addresses";
    Properties p = createProperties();
    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.com.acme.Person.addresses.cfg", "person-addresses-cache");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.expiration.lifespan", "120000");
    p.setProperty("hibernate.cache.infinispan.com.acme.Person.addresses.expiration.max_idle", "60000");
    p.setProperty("hibernate.cache.infinispan.query.cfg", "my-query-cache");
    p.setProperty("hibernate.cache.infinispan.query.eviction.strategy", "LIRS");
    p.setProperty("hibernate.cache.infinispan.query.expiration.wake_up_interval", "3000");
    p.setProperty("hibernate.cache.infinispan.query.eviction.max_entries", "10000");
    TestInfinispanRegionFactory factory = createRegionFactory(p);
    try {
        assertEquals("person-cache", factory.getBaseConfiguration(person));
        Configuration personOverride = factory.getConfigurationOverride(person);
        assertEquals(EvictionStrategy.LRU, personOverride.eviction().strategy());
        assertEquals(5000, personOverride.eviction().maxEntries());
        assertEquals(2000, personOverride.expiration().wakeUpInterval());
        assertEquals(60000, personOverride.expiration().lifespan());
        assertEquals(30000, personOverride.expiration().maxIdle());
        assertEquals("person-addresses-cache", factory.getBaseConfiguration(addresses));
        Configuration addressesOverride = factory.getConfigurationOverride(addresses);
        assertEquals(120000, addressesOverride.expiration().lifespan());
        assertEquals(60000, addressesOverride.expiration().maxIdle());
        assertEquals("my-query-cache", factory.getBaseConfiguration(DataType.QUERY));
        Configuration queryOverride = factory.getConfigurationOverride(DataType.QUERY);
        assertEquals(EvictionStrategy.LIRS, queryOverride.eviction().strategy());
        assertEquals(10000, queryOverride.eviction().maxEntries());
        assertEquals(3000, queryOverride.expiration().wakeUpInterval());
    } finally {
        factory.stop();
    }
}
Also used : Configuration(org.infinispan.configuration.cache.Configuration) Properties(java.util.Properties) Test(org.junit.Test)

Example 10 with Configuration

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

the class PutFromLoadValidatorUnitTest method testGetForNullReleasePuts.

@Test
@TestForIssue(jiraKey = "HHH-9928")
public void testGetForNullReleasePuts() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.simpleCache(true).expiration().maxIdle(500);
    Configuration ppCfg = cb.build();
    InfinispanRegionFactory regionFactory = mock(InfinispanRegionFactory.class);
    doReturn(ppCfg).when(regionFactory).getPendingPutsCacheConfiguration();
    doAnswer(invocation -> TIME_SERVICE.wallClockTime()).when(regionFactory).nextTimestamp();
    PutFromLoadValidator testee = new PutFromLoadValidator(cache, regionFactory, cm);
    for (int i = 0; i < 100; ++i) {
        try {
            withTx(tm, () -> {
                SharedSessionContractImplementor session = mock(SharedSessionContractImplementor.class);
                testee.registerPendingPut(session, KEY1, 0);
                return null;
            });
            TIME_SERVICE.advance(10);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    String ppName = cm.getCache().getName() + "-" + InfinispanRegionFactory.DEF_PENDING_PUTS_RESOURCE;
    Map ppCache = cm.getCache(ppName, false);
    assertNotNull(ppCache);
    Object pendingPutMap = ppCache.get(KEY1);
    assertNotNull(pendingPutMap);
    int size;
    try {
        Method sizeMethod = pendingPutMap.getClass().getMethod("size");
        sizeMethod.setAccessible(true);
        size = (Integer) sizeMethod.invoke(pendingPutMap);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    // some of the pending puts need to be expired by now
    assertTrue(size < 100);
    // but some are still registered
    assertTrue(size > 0);
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) TestInfinispanRegionFactory(org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory) Configuration(org.infinispan.configuration.cache.Configuration) PutFromLoadValidator(org.hibernate.cache.infinispan.access.PutFromLoadValidator) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) Method(java.lang.reflect.Method) Map(java.util.Map) TimeoutException(java.util.concurrent.TimeoutException) Exceptions.expectException(org.infinispan.test.Exceptions.expectException) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

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