Search in sources :

Example 6 with InfinispanRegionFactory

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();
    }
}
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) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) Test(org.junit.Test)

Example 7 with InfinispanRegionFactory

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();
    }
}
Also used : QueryResultsRegionImpl(org.hibernate.cache.infinispan.query.QueryResultsRegionImpl) 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 8 with InfinispanRegionFactory

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();
    }
}
Also used : InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) Properties(java.util.Properties) Test(org.junit.Test)

Example 9 with InfinispanRegionFactory

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();
    }
}
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 10 with InfinispanRegionFactory

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);
    }
}
Also used : TimestampsRegionImpl(org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) ClusteringConfigurationBuilder(org.infinispan.configuration.cache.ClusteringConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) InputStream(java.io.InputStream) ParserRegistry(org.infinispan.configuration.parsing.ParserRegistry) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

InfinispanRegionFactory (org.hibernate.cache.infinispan.InfinispanRegionFactory)20 Properties (java.util.Properties)16 Test (org.junit.Test)13 TimestampsRegionImpl (org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl)7 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)6 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)5 TestInfinispanRegionFactory (org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory)5 Configuration (org.infinispan.configuration.cache.Configuration)5 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)5 AdvancedCache (org.infinispan.AdvancedCache)4 ClusteringConfigurationBuilder (org.infinispan.configuration.cache.ClusteringConfigurationBuilder)4 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)4 QueryResultsRegionImpl (org.hibernate.cache.infinispan.query.QueryResultsRegionImpl)3 TimeoutException (java.util.concurrent.TimeoutException)2 CollectionRegionImpl (org.hibernate.cache.infinispan.collection.CollectionRegionImpl)2 EntityRegionImpl (org.hibernate.cache.infinispan.entity.EntityRegionImpl)2 TransactionalDataRegion (org.hibernate.cache.spi.TransactionalDataRegion)2 InputStream (java.io.InputStream)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1