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;
}
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);
}
}
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);
}
}
}
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();
}
}
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();
}
}
Aggregations