Search in sources :

Example 1 with ParserRegistry

use of org.infinispan.configuration.parsing.ParserRegistry 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)

Example 2 with ParserRegistry

use of org.infinispan.configuration.parsing.ParserRegistry in project hibernate-orm by hibernate.

the class InfinispanRegionFactory method loadConfiguration.

private ConfigurationBuilderHolder loadConfiguration(ServiceRegistry serviceRegistry, String configFile) {
    final FileLookup fileLookup = FileLookupFactory.newInstance();
    final ClassLoader infinispanClassLoader = InfinispanRegionFactory.class.getClassLoader();
    return serviceRegistry.getService(ClassLoaderService.class).workWithClassLoader(new ClassLoaderService.Work<ConfigurationBuilderHolder>() {

        @Override
        public ConfigurationBuilderHolder doWork(ClassLoader classLoader) {
            InputStream is = null;
            try {
                is = fileLookup.lookupFile(configFile, classLoader);
                if (is == null) {
                    // when it's not a user-provided configuration file, it might be a default configuration file,
                    // and if that's included in [this] module might not be visible to the ClassLoaderService:
                    classLoader = infinispanClassLoader;
                    // This time use lookupFile*Strict* so to provide an exception if we can't find it yet:
                    is = FileLookupFactory.newInstance().lookupFileStrict(configFile, classLoader);
                }
                final ParserRegistry parserRegistry = new ParserRegistry(infinispanClassLoader);
                final ConfigurationBuilderHolder holder = parseWithOverridenClassLoader(parserRegistry, is, infinispanClassLoader);
                return holder;
            } catch (IOException e) {
                throw log.unableToCreateCacheManager(e);
            } finally {
                Util.close(is);
            }
        }
    });
}
Also used : ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) InputStream(java.io.InputStream) ParserRegistry(org.infinispan.configuration.parsing.ParserRegistry) IOException(java.io.IOException) FileLookup(org.infinispan.commons.util.FileLookup) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Aggregations

InputStream (java.io.InputStream)2 ConfigurationBuilderHolder (org.infinispan.configuration.parsing.ConfigurationBuilderHolder)2 ParserRegistry (org.infinispan.configuration.parsing.ParserRegistry)2 IOException (java.io.IOException)1 Properties (java.util.Properties)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1 InfinispanRegionFactory (org.hibernate.cache.infinispan.InfinispanRegionFactory)1 TimestampsRegionImpl (org.hibernate.cache.infinispan.timestamp.TimestampsRegionImpl)1 FileLookup (org.infinispan.commons.util.FileLookup)1 ClusteringConfigurationBuilder (org.infinispan.configuration.cache.ClusteringConfigurationBuilder)1 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)1 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)1 DefaultCacheManager (org.infinispan.manager.DefaultCacheManager)1 Test (org.junit.Test)1