Search in sources :

Example 46 with MutableConfiguration

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

the class CacheManagerTest method create_cache2k_config_key_type_mismatch.

@Test(expected = IllegalArgumentException.class)
public void create_cache2k_config_key_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(Integer.class, Double.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 47 with MutableConfiguration

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

the class CacheLoaderTest method setup.

@Before
public void setup() {
    CachingProvider cachingProvider = Caching.getCachingProvider();
    CacheManager cacheManager = cachingProvider.getCacheManager();
    MutableConfiguration<Integer, String> config = new MutableConfiguration<Integer, String>().setReadThrough(true).setCacheLoaderFactory(new FactoryBuilder.SingletonFactory<>(new SimpleCacheLoader()));
    this.cache = cacheManager.createCache("SimpleCache", config);
}
Also used : CacheManager(javax.cache.CacheManager) FactoryBuilder(javax.cache.configuration.FactoryBuilder) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CachingProvider(javax.cache.spi.CachingProvider) Before(org.junit.Before)

Example 48 with MutableConfiguration

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

the class JCacheIntegrationTest method instantiateCache.

@Test
public void instantiateCache() {
    CachingProvider cachingProvider = Caching.getCachingProvider();
    CacheManager cacheManager = cachingProvider.getCacheManager();
    MutableConfiguration<String, String> config = new MutableConfiguration<>();
    Cache<String, String> cache = cacheManager.createCache("simpleCache", config);
    cache.put("key1", "value1");
    cache.put("key2", "value2");
    assertEquals("value1", cache.get("key1"));
    assertEquals("value2", cache.get("key2"));
    cacheManager.close();
}
Also used : CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CachingProvider(javax.cache.spi.CachingProvider) Test(org.junit.Test)

Example 49 with MutableConfiguration

use of javax.cache.configuration.MutableConfiguration in project micrometer by micrometer-metrics.

the class JCacheMetricsCompatibilityTest method createCache.

@Override
public Cache<String, String> createCache() {
    CacheManager cacheManager = new RICachingProvider().getCacheManager();
    MutableConfiguration<String, String> configuration = new MutableConfiguration<>();
    configuration.setTypes(String.class, String.class).setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR)).setStatisticsEnabled(true);
    return cacheManager.createCache("mycache", configuration);
}
Also used : RICachingProvider(org.jsr107.ri.spi.RICachingProvider) CacheManager(javax.cache.CacheManager) MutableConfiguration(javax.cache.configuration.MutableConfiguration)

Example 50 with MutableConfiguration

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

the class CacheManagerClassLoadingTest method testCorrectClassLoaderForKey.

/**
 * Request cache manager with different class loader and put a key in the cache that
 * was loaded by that class loader. equals() needs to work and class loaders needs to be
 * identical
 */
@Test
public void testCorrectClassLoaderForKey() 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 keyClass = loader.loadSpecial(DomainKey.class);
    assertThat(loader).isEqualTo(keyClass.getClassLoader());
    Object key = keyClass.newInstance();
    setValue(key, "someKey");
    String someValue = "Value";
    cache.put(key, someValue);
    Entry e = cache.iterator().next();
    Assertions.assertSame(key.getClass().getClassLoader(), e.getKey().getClass().getClassLoader(), "class loaders identical");
    assertThat(e.getKey()).isEqualTo(key);
    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)

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