private InfinispanRegionFactory createRegionFactory( final EmbeddedCacheManager manager, Properties p) { final InfinispanRegionFactory factory = new SingleNodeTestCase.TestInfinispanRegionFactory() { @Override protected org.infinispan.transaction.lookup.TransactionManagerLookup createTransactionManagerLookup( SessionFactoryOptions settings, Properties properties) { return new HibernateTransactionManagerLookup(null, null) { @Override public TransactionManager getTransactionManager() throws Exception { AbstractJtaPlatform jta = new JBossStandAloneJtaPlatform(); jta.injectServices(ServiceRegistryBuilder.buildServiceRegistry()); return jta.getTransactionManager(); } }; } @Override protected EmbeddedCacheManager createCacheManager( Properties properties, ServiceRegistry serviceRegistry) throws CacheException { if (manager != null) return manager; else return super.createCacheManager(properties, serviceRegistry); } }; factory.start(sfOptionsForStart(), p); return factory; }
public static InfinispanRegionFactory startRegionFactory(ServiceRegistry serviceRegistry) { try { final ConfigurationService cfgService = serviceRegistry.getService(ConfigurationService.class); 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 SingleNodeTestCase.TestInfinispanRegionFactory(); } else { regionFactory = (InfinispanRegionFactory) clazz.newInstance(); } final SessionFactoryOptionsImpl sessionFactoryOptions = new SessionFactoryOptionsImpl( new SessionFactoryBuilderImpl.SessionFactoryOptionsStateStandardImpl( (StandardServiceRegistry) serviceRegistry)); final Properties properties = toProperties(cfgService.getSettings()); regionFactory.start(sessionFactoryOptions, properties); return regionFactory; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
@Test(expected = CacheException.class) public void testTimestampValidation() { Properties p = createProperties(); final DefaultCacheManager manager = new DefaultCacheManager(GlobalConfigurationBuilder.defaultClusteredBuilder().build()); try { InfinispanRegionFactory factory = createRegionFactory(manager, p); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.clustering().cacheMode(CacheMode.INVALIDATION_SYNC); manager.defineConfiguration("timestamps", builder.build()); factory.start(null, p); fail("Should have failed saying that invalidation is not allowed for timestamp caches."); } finally { TestingUtil.killCacheManagers(manager); } }