Search in sources :

Example 41 with CacheManager

use of javax.cache.CacheManager in project cache2k by cache2k.

the class CacheManagerTest method create_config_cache2k_types.

@Test
@Ignore("not yet")
public void create_config_cache2k_types() {
    CachingProvider p = Caching.getCachingProvider();
    CacheManager cm = p.getCacheManager();
    ExtendedMutableConfiguration<String, BigDecimal> mc = new ExtendedMutableConfiguration<String, BigDecimal>();
    mc.setCache2kConfiguration(new Cache2kBuilder<String, BigDecimal>() {
    }.toConfiguration());
    Cache<String, BigDecimal> c = cm.createCache("aCache", mc);
    assertEquals("aCache", c.getName());
    assertEquals(String.class, c.getConfiguration(Configuration.class).getKeyType());
    assertEquals(BigDecimal.class, c.getConfiguration(Configuration.class).getValueType());
    c.close();
}
Also used : ExtendedMutableConfiguration(org.cache2k.jcache.ExtendedMutableConfiguration) CacheManager(javax.cache.CacheManager) BigDecimal(java.math.BigDecimal) Cache2kBuilder(org.cache2k.Cache2kBuilder) CachingProvider(javax.cache.spi.CachingProvider) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 42 with CacheManager

use of javax.cache.CacheManager in project cache2k by cache2k.

the class CacheManagerTest method create_empty_config.

@Test
public void create_empty_config() {
    CachingProvider p = Caching.getCachingProvider();
    CacheManager cm = p.getCacheManager();
    MutableConfiguration<String, BigDecimal> mc = new ExtendedMutableConfiguration<String, BigDecimal>();
    mc.setTypes(String.class, BigDecimal.class);
    Cache<String, BigDecimal> c = cm.createCache("aCache", mc);
    assertEquals("aCache", c.getName());
    assertEquals(String.class, c.getConfiguration(Configuration.class).getKeyType());
    assertEquals(BigDecimal.class, c.getConfiguration(Configuration.class).getValueType());
    c.close();
}
Also used : ExtendedMutableConfiguration(org.cache2k.jcache.ExtendedMutableConfiguration) CacheManager(javax.cache.CacheManager) BigDecimal(java.math.BigDecimal) CachingProvider(javax.cache.spi.CachingProvider) Test(org.junit.Test)

Example 43 with CacheManager

use of javax.cache.CacheManager in project cache2k by cache2k.

the class CacheManagerTest method create_cache2k_config_nowrap.

@Test
public void create_cache2k_config_nowrap() {
    CachingProvider p = Caching.getCachingProvider();
    CacheManager cm = p.getCacheManager();
    Cache<Long, Double> cache = cm.createCache("aCache", ExtendedMutableConfiguration.of(new Cache2kBuilder<Long, Double>() {
    }.entryCapacity(10000).expireAfterWrite(5, TimeUnit.MINUTES)));
    assertFalse(cache instanceof CopyCacheProxy);
    cache.close();
}
Also used : CopyCacheProxy(org.cache2k.jcache.provider.generic.storeByValueSimulation.CopyCacheProxy) CacheManager(javax.cache.CacheManager) Cache2kBuilder(org.cache2k.Cache2kBuilder) CachingProvider(javax.cache.spi.CachingProvider) Test(org.junit.Test)

Example 44 with CacheManager

use of javax.cache.CacheManager in project cache2k by cache2k.

the class CachingProviderClassLoaderTest method getCacheManagerSingleton.

/**
 * Multiple invocations of {@link javax.cache.spi.CachingProvider#getCacheManager()}
 * will return the same instance.
 */
@Test
public void getCacheManagerSingleton() {
    // obtain the default caching provider
    CachingProvider provider = Caching.getCachingProvider();
    // obtain the default class loader
    ClassLoader classLoader = Caching.getDefaultClassLoader();
    // obtain the default cache manager
    CacheManager manager = provider.getCacheManager();
    assertNotNull(classLoader);
    assertNotNull(manager);
    // ensure the default manager is the same as asking the provider
    // for a cache manager using the default URI and classloader
    assertSame(manager, provider.getCacheManager());
    assertSame(manager, provider.getCacheManager(provider.getDefaultURI(), provider.getDefaultClassLoader()));
    // using a different ClassLoader
    ClassLoader otherLoader = new MyClassLoader(classLoader);
    CachingProvider otherProvider = Caching.getCachingProvider(otherLoader);
    CacheManager otherManager = otherProvider.getCacheManager();
    assertSame(otherManager, otherProvider.getCacheManager());
    assertSame(otherManager, otherProvider.getCacheManager(otherProvider.getDefaultURI(), otherProvider.getDefaultClassLoader()));
}
Also used : URLClassLoader(java.net.URLClassLoader) CacheManager(javax.cache.CacheManager) CachingProvider(javax.cache.spi.CachingProvider) Test(org.junit.Test)

Example 45 with CacheManager

use of javax.cache.CacheManager in project cache2k by cache2k.

the class CachingProviderClassLoaderTest method closeClassLoader.

/**
 * Attempt to close CacheManagers using URIs and/or ClassLoaders that don't
 * have associated CacheManagers.
 */
@Test
public void closeClassLoader() throws Exception {
    ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
    CachingProvider provider = Caching.getCachingProvider(contextLoader);
    URI uri = provider.getDefaultURI();
    ClassLoader loader1 = new MyClassLoader(contextLoader);
    CacheManager manager1 = provider.getCacheManager(uri, loader1);
    ClassLoader loader2 = new MyClassLoader(contextLoader);
    CacheManager manager2 = provider.getCacheManager(uri, loader2);
    ClassLoader loader3 = new MyClassLoader(contextLoader);
    CacheManager manager3 = provider.getCacheManager(uri, loader3);
    provider.close(contextLoader);
    provider.close(provider.getDefaultURI(), contextLoader);
    provider.close(provider.getDefaultURI(), contextLoader);
    provider.close(provider.getDefaultURI(), contextLoader);
    assertSame(manager1, provider.getCacheManager(uri, loader1));
    assertSame(manager2, provider.getCacheManager(uri, loader2));
    assertSame(manager3, provider.getCacheManager(uri, loader3));
}
Also used : URLClassLoader(java.net.URLClassLoader) CacheManager(javax.cache.CacheManager) URI(java.net.URI) CachingProvider(javax.cache.spi.CachingProvider) Test(org.junit.Test)

Aggregations

CacheManager (javax.cache.CacheManager)284 Test (org.junit.Test)182 CachingProvider (javax.cache.spi.CachingProvider)113 QuickTest (com.hazelcast.test.annotation.QuickTest)78 HazelcastInstance (com.hazelcast.core.HazelcastInstance)69 MutableConfiguration (javax.cache.configuration.MutableConfiguration)56 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)55 CacheConfig (com.hazelcast.config.CacheConfig)54 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)50 Cache (javax.cache.Cache)41 URI (java.net.URI)31 AssertTask (com.hazelcast.test.AssertTask)26 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)25 Config (com.hazelcast.config.Config)20 ClientConfig (com.hazelcast.client.config.ClientConfig)17 SlowTest (com.hazelcast.test.annotation.SlowTest)17 Before (org.junit.Before)17 CacheTestSupport.createClientCachingProvider (com.hazelcast.cache.CacheTestSupport.createClientCachingProvider)16 HazelcastCacheManager (com.hazelcast.cache.HazelcastCacheManager)16 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)16