Search in sources :

Example 51 with MutableConfiguration

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

the class CacheManagerClassLoadingTest method testCorrectClassLoaderForValue.

/**
 * Request cache manager with different class loader and put a value in the cache that
 * was loaded by that class loader. equals() needs to work and class loaders needs to be
 * identical
 */
@Test
public void testCorrectClassLoaderForValue() throws Exception {
    SpecialClassLoader loader = new SpecialClassLoader();
    CachingProvider provider = getCachingProvider();
    CacheManager mgr = getCachingProvider().getCacheManager(provider.getDefaultURI(), loader);
    Cache<Object, Object> cache = mgr.createCache(CACHE_NAME, new MutableConfiguration());
    Class valueClass = loader.loadSpecial(DomainValue.class);
    assertThat(loader).isEqualTo(valueClass.getClassLoader());
    Object value = valueClass.newInstance();
    setValue(value, "someValue");
    String someKey = "Key";
    cache.put(someKey, value);
    Entry e = cache.iterator().next();
    Assertions.assertSame(value.getClass().getClassLoader(), e.getValue().getClass().getClassLoader(), "class loaders identical");
    assertThat(e.getValue()).isEqualTo(value);
    mgr.close();
}
Also used : Entry(javax.cache.Cache.Entry) CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CachingProvider(javax.cache.spi.CachingProvider) Caching.getCachingProvider(javax.cache.Caching.getCachingProvider) Test(org.junit.jupiter.api.Test)

Example 52 with MutableConfiguration

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

the class CacheManagerTest method create_empty_config.

@Test
public void create_empty_config() {
    CachingProvider p = 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);
    assertThat(c.getName()).isEqualTo("aCache");
    assertThat(c.getConfiguration(Configuration.class).getKeyType()).isEqualTo(String.class);
    assertThat(c.getConfiguration(Configuration.class).getValueType()).isEqualTo(BigDecimal.class);
    c.close();
}
Also used : ExtendedMutableConfiguration(org.cache2k.jcache.ExtendedMutableConfiguration) ExtendedMutableConfiguration(org.cache2k.jcache.ExtendedMutableConfiguration) CacheEntryListenerConfiguration(javax.cache.configuration.CacheEntryListenerConfiguration) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Configuration(javax.cache.configuration.Configuration) CacheManager(javax.cache.CacheManager) BigDecimal(java.math.BigDecimal) CachingProvider(javax.cache.spi.CachingProvider) Caching.getCachingProvider(javax.cache.Caching.getCachingProvider) Test(org.junit.jupiter.api.Test)

Example 53 with MutableConfiguration

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

the class XmlConfigurationTest method configurationPresent_defaults.

@Test
public void configurationPresent_defaults() throws Exception {
    javax.cache.CacheManager manager = getCachingProvider().getCacheManager(new URI(MANAGER_NAME), null);
    JCacheBuilder b = new JCacheBuilder("default", (JCacheManagerAdapter) manager);
    b.setConfiguration(new MutableConfiguration());
    assertThat(b.getExtraConfiguration().isCopyAlwaysIfRequested()).isEqualTo(false);
}
Also used : URI(java.net.URI) ExtendedMutableConfiguration(org.cache2k.jcache.ExtendedMutableConfiguration) MutableConfiguration(javax.cache.configuration.MutableConfiguration) Test(org.junit.jupiter.api.Test)

Example 54 with MutableConfiguration

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

the class CacheManagerTest method cachingProviderGetCache.

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

Example 55 with MutableConfiguration

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

the class CacheManagerTest method testReuseCacheManager.

@Test
public void testReuseCacheManager() throws Exception {
    CachingProvider provider = Caching.getCachingProvider();
    URI uri = provider.getDefaultURI();
    CacheManager cacheManager = provider.getCacheManager(uri, provider.getDefaultClassLoader());
    assertFalse(cacheManager.isClosed());
    cacheManager.close();
    assertTrue(cacheManager.isClosed());
    try {
        cacheManager.createCache("Dog", new MutableConfiguration());
        fail();
    } catch (IllegalStateException e) {
    // expected
    }
    CacheManager otherCacheManager = provider.getCacheManager(uri, provider.getDefaultClassLoader());
    assertFalse(otherCacheManager.isClosed());
    assertNotSame(cacheManager, otherCacheManager);
}
Also used : CacheManager(javax.cache.CacheManager) URI(java.net.URI) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CachingProvider(javax.cache.spi.CachingProvider) 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