Search in sources :

Example 6 with Cache2kBuilder

use of org.cache2k.Cache2kBuilder 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 7 with Cache2kBuilder

use of org.cache2k.Cache2kBuilder 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 8 with Cache2kBuilder

use of org.cache2k.Cache2kBuilder in project cache2k by cache2k.

the class OsgiIT method testEventPackage.

/**
 * Simple test to see whether event package is exported.
 */
@Test
public void testEventPackage() {
    CacheManager m = CacheManager.getInstance("testEventPackage");
    final AtomicInteger _count = new AtomicInteger();
    Cache<String, String> c = new Cache2kBuilder<String, String>() {
    }.manager(m).eternal(true).addListener(new CacheEntryCreatedListener<String, String>() {

        @Override
        public void onEntryCreated(final Cache<String, String> cache, final CacheEntry<String, String> entry) {
            _count.incrementAndGet();
        }
    }).build();
    c.put("abc", "123");
    assertTrue(c.containsKey("abc"));
    assertEquals("123", c.peek("abc"));
    assertEquals(1, _count.get());
    c.close();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheEntryCreatedListener(org.cache2k.event.CacheEntryCreatedListener) CacheManager(org.cache2k.CacheManager) CacheEntry(org.cache2k.CacheEntry) Cache2kBuilder(org.cache2k.Cache2kBuilder) Cache(org.cache2k.Cache) Test(org.junit.Test)

Example 9 with Cache2kBuilder

use of org.cache2k.Cache2kBuilder in project cache2k by cache2k.

the class CacheManagerTest method create_cache2k_config_wrap.

@Test
public void create_cache2k_config_wrap() {
    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).with(new JCacheConfiguration.Builder().copyAlwaysIfRequested(true))));
    assertTrue(cache instanceof CopyCacheProxy);
    cache.close();
}
Also used : CopyCacheProxy(org.cache2k.jcache.provider.generic.storeByValueSimulation.CopyCacheProxy) Cache2kBuilder(org.cache2k.Cache2kBuilder) CacheManager(javax.cache.CacheManager) CachingProvider(javax.cache.spi.CachingProvider) Test(org.junit.Test)

Example 10 with Cache2kBuilder

use of org.cache2k.Cache2kBuilder in project cache2k by cache2k.

the class JmxSupportTest method testDisabled.

@Test
public void testDisabled() throws Exception {
    String _name = getClass().getName() + ".testInitialProperties";
    Cache c = new Cache2kBuilder<Long, List<Collection<Long>>>() {
    }.name(_name).disableStatistics(true).eternal(true).build();
    objectName = constructCacheObjectName(_name);
    try {
        retrieve("Alert");
        fail("exception expected");
    } catch (InstanceNotFoundException ex) {
    }
    c.close();
}
Also used : InstanceNotFoundException(javax.management.InstanceNotFoundException) Collection(java.util.Collection) Cache2kBuilder(org.cache2k.Cache2kBuilder) Cache(org.cache2k.Cache) Test(org.junit.Test)

Aggregations

Cache2kBuilder (org.cache2k.Cache2kBuilder)13 Test (org.junit.Test)11 Cache (org.cache2k.Cache)9 CacheManager (javax.cache.CacheManager)3 CachingProvider (javax.cache.spi.CachingProvider)3 CacheManager (org.cache2k.CacheManager)3 CopyCacheProxy (org.cache2k.jcache.provider.generic.storeByValueSimulation.CopyCacheProxy)2 BigDecimal (java.math.BigDecimal)1 Collection (java.util.Collection)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 CacheEntry (org.cache2k.CacheEntry)1 CacheClosedListener (org.cache2k.event.CacheClosedListener)1 CacheEntryCreatedListener (org.cache2k.event.CacheEntryCreatedListener)1 ExtendedMutableConfiguration (org.cache2k.jcache.ExtendedMutableConfiguration)1 Ignore (org.junit.Ignore)1