Search in sources :

Example 86 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project tutorials by eugenp.

the class EventListenerTest method setup.

@Before
public void setup() {
    CachingProvider cachingProvider = Caching.getCachingProvider();
    CacheManager cacheManager = cachingProvider.getCacheManager();
    MutableConfiguration<String, String> config = new MutableConfiguration<String, String>();
    this.cache = cacheManager.createCache("MyCache", config);
    this.listener = new SimpleCacheEntryListener();
}
Also used : CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CachingProvider(javax.cache.spi.CachingProvider) Before(org.junit.Before)

Example 87 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project cache2k by cache2k.

the class CacheManagerTest method create_cache2k_config_value_type_mismatch.

@Test(expected = IllegalArgumentException.class)
public void create_cache2k_config_value_type_mismatch() {
    CachingProvider p = Caching.getCachingProvider();
    CacheManager cm = p.getCacheManager();
    MutableConfiguration cfg = ExtendedMutableConfiguration.of(new Cache2kBuilder<Long, Double>() {
    });
    Cache<Integer, Double> cache = cm.createCache("aCache", cfg.setTypes(Long.class, Float.class));
    cache.close();
}
Also used : CacheManager(javax.cache.CacheManager) ExtendedMutableConfiguration(org.cache2k.jcache.ExtendedMutableConfiguration) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CachingProvider(javax.cache.spi.CachingProvider) Test(org.junit.Test)

Example 88 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project cache2k by cache2k.

the class CacheTest method testGetCacheManager.

@Test
public void testGetCacheManager() throws Exception {
    String cacheName = "SampleCache";
    URI uri = Caching.getCachingProvider().getDefaultURI();
    ClassLoader cl1 = Thread.currentThread().getContextClassLoader();
    ClassLoader cl2 = URLClassLoader.newInstance(new URL[] {}, cl1);
    CacheManager cacheManager1 = Caching.getCachingProvider().getCacheManager(uri, cl1);
    CacheManager cacheManager2 = Caching.getCachingProvider().getCacheManager(uri, cl2);
    assertNotSame(cacheManager1, cacheManager2);
    cacheManager1.createCache(cacheName, new MutableConfiguration());
    Cache cache1 = cacheManager1.getCache(cacheName);
    cacheManager2.createCache(cacheName, new MutableConfiguration());
    Cache cache2 = cacheManager2.getCache(cacheName);
    assertSame(cacheManager1, cache1.getCacheManager());
    assertSame(cacheManager2, cache2.getCacheManager());
}
Also used : URLClassLoader(java.net.URLClassLoader) CacheManager(javax.cache.CacheManager) URI(java.net.URI) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Cache(javax.cache.Cache) Test(org.junit.Test)

Example 89 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project cache2k by cache2k.

the class CachingTest method cachingProviderGetCache.

@Test
public void cachingProviderGetCache() {
    String name = "c1";
    Caching.getCachingProvider().getCacheManager().createCache(name, new MutableConfiguration().setTypes(Long.class, String.class));
    Cache cache = Caching.getCache(name, Long.class, String.class);
    assertEquals(name, cache.getName());
    Caching.getCachingProvider().getCacheManager().destroyCache(name);
}
Also used : MutableConfiguration(javax.cache.configuration.MutableConfiguration) Cache(javax.cache.Cache) Test(org.junit.Test)

Example 90 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project cache2k by cache2k.

the class CachingTest method getCacheNullValueClass.

@Test(expected = NullPointerException.class)
public void getCacheNullValueClass() {
    String name = "c1";
    CacheManager manager = Caching.getCachingProvider().getCacheManager();
    manager.createCache(name, new MutableConfiguration().setTypes(Long.class, String.class));
    try {
        Caching.getCache(name, Long.class, null);
    } finally {
        manager.destroyCache(name);
    }
}
Also used : CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Test(org.junit.Test)

Aggregations

MutableConfiguration (javax.cache.configuration.MutableConfiguration)146 Test (org.junit.Test)97 CacheManager (javax.cache.CacheManager)76 CachingProvider (javax.cache.spi.CachingProvider)35 Cache (javax.cache.Cache)32 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)21 QuickTest (com.hazelcast.test.annotation.QuickTest)16 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)15 Test (org.junit.jupiter.api.Test)12 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)11 URI (java.net.URI)11 CreatedExpiryPolicy (javax.cache.expiry.CreatedExpiryPolicy)11 MutableCacheEntryListenerConfiguration (javax.cache.configuration.MutableCacheEntryListenerConfiguration)10 Duration (javax.cache.expiry.Duration)10 CountDownLatch (java.util.concurrent.CountDownLatch)8 ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)7 ExtendedMutableConfiguration (org.cache2k.jcache.ExtendedMutableConfiguration)7 AssertTask (com.hazelcast.test.AssertTask)6 BaseTest (org.redisson.BaseTest)6 RedisRunner (org.redisson.RedisRunner)6