Search in sources :

Example 6 with JCacheManager

use of org.infinispan.jcache.embedded.JCacheManager in project infinispan by infinispan.

the class JCacheConfigurationTest method testProgrammaticCacheConfiguration.

public void testProgrammaticCacheConfiguration() throws Exception {
    URI uri = JCacheConfigurationTest.class.getClassLoader().getResource("infinispan_uri.xml").toURI();
    Properties properties = getProperties();
    Function<String, Configuration> f = (s) -> new ConfigurationBuilder().memory().maxCount(1234l).build();
    properties.put(JCacheManager.CACHE_CONFIGURATION_FUNCTION, f);
    withCachingProvider(provider -> {
        try (JCacheManager jCacheManager = new JCacheManager(uri, provider.getClass().getClassLoader(), provider, properties)) {
            Cache<Object, Object> cache = jCacheManager.createCache("cache", new MutableConfiguration<>());
            org.infinispan.Cache unwrap = cache.unwrap(org.infinispan.Cache.class);
            Configuration configuration = unwrap.getCacheConfiguration();
            assertEquals(1234l, configuration.memory().maxCount());
        }
    });
}
Also used : Manifest(java.util.jar.Manifest) JCacheTestingUtil.withCachingProvider(org.infinispan.jcache.util.JCacheTestingUtil.withCachingProvider) BufferedInputStream(java.io.BufferedInputStream) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) PrivateGlobalConfiguration(org.infinispan.configuration.internal.PrivateGlobalConfiguration) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) PrivateGlobalConfigurationBuilder(org.infinispan.configuration.internal.PrivateGlobalConfigurationBuilder) Test(org.testng.annotations.Test) Function(java.util.function.Function) JarEntry(java.util.jar.JarEntry) URLClassLoader(java.net.URLClassLoader) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) AdvancedCache(org.infinispan.AdvancedCache) AbstractInfinispanTest(org.infinispan.test.AbstractInfinispanTest) ConfigurationBuilderHolder(org.infinispan.configuration.parsing.ConfigurationBuilderHolder) Cache(javax.cache.Cache) MutableConfiguration(javax.cache.configuration.MutableConfiguration) URI(java.net.URI) JarOutputStream(java.util.jar.JarOutputStream) Properties(java.util.Properties) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Attributes(java.util.jar.Attributes) File(java.io.File) Objects(java.util.Objects) TestingUtil.withCacheManager(org.infinispan.test.TestingUtil.withCacheManager) Paths(java.nio.file.Paths) CommonsTestingUtil(org.infinispan.commons.test.CommonsTestingUtil) Configuration(org.infinispan.configuration.cache.Configuration) TestCacheManagerFactory(org.infinispan.test.fwk.TestCacheManagerFactory) AssertJUnit.assertNotNull(org.testng.AssertJUnit.assertNotNull) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) JCacheManager(org.infinispan.jcache.embedded.JCacheManager) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) PrivateGlobalConfigurationBuilder(org.infinispan.configuration.internal.PrivateGlobalConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) PrivateGlobalConfiguration(org.infinispan.configuration.internal.PrivateGlobalConfiguration) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Configuration(org.infinispan.configuration.cache.Configuration) JCacheManager(org.infinispan.jcache.embedded.JCacheManager) Properties(java.util.Properties) URI(java.net.URI)

Example 7 with JCacheManager

use of org.infinispan.jcache.embedded.JCacheManager in project infinispan by infinispan.

the class InjectedCacheResolver method toJCacheManager.

private JCacheManager toJCacheManager(final EmbeddedCacheManager cacheManager) {
    final GlobalConfiguration globalCfg = cacheManager.getCacheManagerConfiguration();
    final String name = globalCfg.cacheManagerName();
    return new JCacheManager(URI.create(name), cacheManager, Caching.getCachingProvider());
}
Also used : GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) JCacheManager(org.infinispan.jcache.embedded.JCacheManager)

Example 8 with JCacheManager

use of org.infinispan.jcache.embedded.JCacheManager in project infinispan by infinispan.

the class JCacheConfigurationTest method testJCacheManagerWherePathContainsFileSchemaAndAbsolutePath.

public void testJCacheManagerWherePathContainsFileSchemaAndAbsolutePath() throws Exception {
    URI uri = JCacheConfigurationTest.class.getClassLoader().getResource("infinispan_uri.xml").toURI();
    withCachingProvider(provider -> {
        Properties properties = getProperties();
        try (JCacheManager jCacheManager = new JCacheManager(uri, provider.getClass().getClassLoader(), provider, properties)) {
            Cache<Object, Object> cache = jCacheManager.getCache("foo");
            assertNotNull(cache);
            assertEquals(10000, cache.unwrap(AdvancedCache.class).getCacheConfiguration().memory().maxCount());
        }
    });
}
Also used : JCacheManager(org.infinispan.jcache.embedded.JCacheManager) Properties(java.util.Properties) URI(java.net.URI)

Example 9 with JCacheManager

use of org.infinispan.jcache.embedded.JCacheManager in project infinispan by infinispan.

the class JCacheConfigurationTest method testJCacheManagerWithWildcardCacheConfigurations.

public void testJCacheManagerWithWildcardCacheConfigurations() throws Exception {
    URI uri = JCacheConfigurationTest.class.getClassLoader().getResource("infinispan_uri.xml").toURI();
    withCachingProvider(provider -> {
        try (JCacheManager jCacheManager = new JCacheManager(uri, provider.getClass().getClassLoader(), provider, getProperties())) {
            Cache<Object, Object> wildcache1 = jCacheManager.createCache("wildcache1", new MutableConfiguration<>());
            org.infinispan.Cache unwrap = wildcache1.unwrap(org.infinispan.Cache.class);
            Configuration configuration = unwrap.getCacheConfiguration();
            assertEquals(10500, configuration.expiration().wakeUpInterval());
            assertEquals(11, configuration.expiration().lifespan());
            assertEquals(11, configuration.expiration().maxIdle());
        }
    });
}
Also used : PrivateGlobalConfiguration(org.infinispan.configuration.internal.PrivateGlobalConfiguration) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Configuration(org.infinispan.configuration.cache.Configuration) JCacheManager(org.infinispan.jcache.embedded.JCacheManager) URI(java.net.URI)

Example 10 with JCacheManager

use of org.infinispan.jcache.embedded.JCacheManager in project infinispan by infinispan.

the class JCacheLoaderTest method testLoadUnmarshallableValue.

public void testLoadUnmarshallableValue(Method m) {
    final String cacheName = m.getName();
    NonMarshallablePojo v1 = new NonMarshallablePojo("v1");
    NonMarshallablePojo v2 = new NonMarshallablePojo("v2");
    withCacheManager(new CacheManagerCallable(TestCacheManagerFactory.createCacheManager(false)) {

        @Override
        public void call() {
            JCacheManager jCacheManager = createJCacheManager(cm, this);
            InMemoryJCacheLoader<Integer, NonMarshallablePojo> cacheLoader = new InMemoryJCacheLoader<>();
            cacheLoader.store(1, v1).store(2, v2);
            MutableConfiguration<Integer, NonMarshallablePojo> cfg = new MutableConfiguration<>();
            cfg.setStoreByValue(false);
            cfg.setReadThrough(true);
            cfg.setCacheLoaderFactory(FactoryBuilder.factoryOf(cacheLoader));
            Cache<Integer, NonMarshallablePojo> cache = jCacheManager.createCache(cacheName, cfg);
            assertEquals(v2, cache.get(2));
            assertEquals(v1, cache.get(1));
            DataContainer<Integer, String> dc = cache.unwrap(AdvancedCache.class).getDataContainer();
            assertEquals(v2, dc.peek(2).getValue());
            assertEquals(v1, dc.peek(1).getValue());
        }
    });
}
Also used : DataContainer(org.infinispan.container.DataContainer) CacheManagerCallable(org.infinispan.test.CacheManagerCallable) JCacheManager(org.infinispan.jcache.embedded.JCacheManager) InMemoryJCacheLoader(org.infinispan.jcache.util.InMemoryJCacheLoader) MutableConfiguration(javax.cache.configuration.MutableConfiguration) AdvancedCache(org.infinispan.AdvancedCache) Cache(javax.cache.Cache)

Aggregations

JCacheManager (org.infinispan.jcache.embedded.JCacheManager)14 URI (java.net.URI)6 MutableConfiguration (javax.cache.configuration.MutableConfiguration)5 Properties (java.util.Properties)4 Cache (javax.cache.Cache)4 AdvancedCache (org.infinispan.AdvancedCache)4 PrivateGlobalConfiguration (org.infinispan.configuration.internal.PrivateGlobalConfiguration)4 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)3 PrivateGlobalConfigurationBuilder (org.infinispan.configuration.internal.PrivateGlobalConfigurationBuilder)3 InMemoryJCacheLoader (org.infinispan.jcache.util.InMemoryJCacheLoader)3 DefaultCacheManager (org.infinispan.manager.DefaultCacheManager)3 CacheManagerCallable (org.infinispan.test.CacheManagerCallable)3 File (java.io.File)2 URLClassLoader (java.net.URLClassLoader)2 ArrayList (java.util.ArrayList)2 CacheManager (javax.cache.CacheManager)2 MutableEntry (javax.cache.processor.MutableEntry)2 Configuration (org.infinispan.configuration.cache.Configuration)2 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)2 ConfigurationBuilderHolder (org.infinispan.configuration.parsing.ConfigurationBuilderHolder)2