Search in sources :

Example 11 with InfinispanRegionFactory

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

the class CacheTestUtil method startRegionFactory.

public static InfinispanRegionFactory startRegionFactory(ServiceRegistry serviceRegistry, CacheTestSupport testSupport) {
    InfinispanRegionFactory factory = startRegionFactory(serviceRegistry);
    testSupport.registerFactory(factory);
    return factory;
}
Also used : InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory)

Example 12 with InfinispanRegionFactory

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

the class CacheTestUtil method startRegionFactory.

public static InfinispanRegionFactory startRegionFactory(ServiceRegistry serviceRegistry) {
    try {
        final ConfigurationService cfgService = serviceRegistry.getService(ConfigurationService.class);
        final Properties properties = toProperties(cfgService.getSettings());
        String factoryType = cfgService.getSetting(AvailableSettings.CACHE_REGION_FACTORY, StandardConverters.STRING);
        Class clazz = Thread.currentThread().getContextClassLoader().loadClass(factoryType);
        InfinispanRegionFactory regionFactory;
        if (clazz == InfinispanRegionFactory.class) {
            regionFactory = new TestInfinispanRegionFactory(properties);
        } else {
            if (InfinispanRegionFactory.class.isAssignableFrom(clazz)) {
                regionFactory = createRegionFactory(clazz, properties);
            } else {
                throw new IllegalArgumentException(clazz + " is not InfinispanRegionFactory");
            }
        }
        final SessionFactoryOptionsImpl sessionFactoryOptions = new SessionFactoryOptionsImpl(new SessionFactoryBuilderImpl.SessionFactoryOptionsStateStandardImpl((StandardServiceRegistry) serviceRegistry));
        regionFactory.start(sessionFactoryOptions, properties);
        return regionFactory;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) SessionFactoryOptionsImpl(org.hibernate.boot.internal.SessionFactoryOptionsImpl) Properties(java.util.Properties) TimeoutException(java.util.concurrent.TimeoutException) ConfigurationService(org.hibernate.engine.config.spi.ConfigurationService) SessionFactoryBuilderImpl(org.hibernate.boot.internal.SessionFactoryBuilderImpl) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 13 with InfinispanRegionFactory

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

the class AbstractGeneralDataRegionTest method withSessionFactoriesAndRegions.

protected void withSessionFactoriesAndRegions(int num, SFRConsumer consumer) throws Exception {
    StandardServiceRegistryBuilder ssrb = createStandardServiceRegistryBuilder().applySetting(AvailableSettings.CACHE_REGION_FACTORY, TestInfinispanRegionFactory.class.getName());
    Properties properties = CacheTestUtil.toProperties(ssrb.getSettings());
    List<StandardServiceRegistry> registries = new ArrayList<>();
    List<SessionFactory> sessionFactories = new ArrayList<>();
    List<GeneralDataRegion> regions = new ArrayList<>();
    for (int i = 0; i < num; ++i) {
        StandardServiceRegistry registry = ssrb.build();
        registries.add(registry);
        SessionFactory sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
        sessionFactories.add(sessionFactory);
        InfinispanRegionFactory regionFactory = (InfinispanRegionFactory) registry.getService(RegionFactory.class);
        GeneralDataRegion region = (GeneralDataRegion) createRegion(regionFactory, getStandardRegionName(REGION_PREFIX), properties, null);
        regions.add(region);
    }
    try {
        consumer.accept(sessionFactories, regions);
    } finally {
        for (SessionFactory sessionFactory : sessionFactories) {
            sessionFactory.close();
        }
        for (StandardServiceRegistry registry : registries) {
            StandardServiceRegistryBuilder.destroy(registry);
        }
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) TestInfinispanRegionFactory(org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ArrayList(java.util.ArrayList) MetadataSources(org.hibernate.boot.MetadataSources) Properties(java.util.Properties) BaseGeneralDataRegion(org.hibernate.cache.infinispan.impl.BaseGeneralDataRegion) GeneralDataRegion(org.hibernate.cache.spi.GeneralDataRegion) InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) RegionFactory(org.hibernate.cache.spi.RegionFactory) TestInfinispanRegionFactory(org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory) TestInfinispanRegionFactory(org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 14 with InfinispanRegionFactory

use of org.hibernate.cache.infinispan.InfinispanRegionFactory 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 15 with InfinispanRegionFactory

use of org.hibernate.cache.infinispan.InfinispanRegionFactory 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)

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