Search in sources :

Example 1 with Cache2kBuilder

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

the class Cache2kBuilderTest method cacheClosedEventFired.

private void cacheClosedEventFired(boolean _wiredCache) {
    final AtomicBoolean _FIRED = new AtomicBoolean();
    Cache2kBuilder _builder = Cache2kBuilder.forUnknownTypes();
    _builder.addCacheClosedListener(new CacheClosedListener() {

        @Override
        public void onCacheClosed(final Cache cache) {
            _FIRED.set(true);
        }
    });
    if (_wiredCache) {
        StaticUtil.enforceWiredCache(_builder);
    }
    Cache c = _builder.build();
    c.close();
    assertTrue(_FIRED.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CacheClosedListener(org.cache2k.event.CacheClosedListener) Cache2kBuilder(org.cache2k.Cache2kBuilder) Cache(org.cache2k.Cache)

Example 2 with Cache2kBuilder

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

the class Cache2kBuilderTest method cacheRemovedAfterClose_WiredCache.

@Test
public void cacheRemovedAfterClose_WiredCache() {
    final String _NAME = this.getClass().getSimpleName() + "-cacheRemovedAfterCloseWiredCache";
    CacheManager cm = CacheManager.getInstance(_NAME);
    Cache2kBuilder _builder = Cache2kBuilder.forUnknownTypes().manager(cm).name(_NAME);
    StaticUtil.enforceWiredCache(_builder);
    Cache c = _builder.build();
    assertEquals(c, cm.getActiveCaches().iterator().next());
    c.close();
    assertFalse(cm.getActiveCaches().iterator().hasNext());
}
Also used : CacheManager(org.cache2k.CacheManager) Cache2kBuilder(org.cache2k.Cache2kBuilder) Cache(org.cache2k.Cache) Test(org.junit.Test)

Example 3 with Cache2kBuilder

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

the class Cache2kBuilderTest method anonymousWithObjectObject.

@Test(expected = IllegalArgumentException.class)
public void anonymousWithObjectObject() {
    Cache c = new Cache2kBuilder<Object, Object>() {
    }.eternal(true).build();
    c.clear();
}
Also used : Cache2kBuilder(org.cache2k.Cache2kBuilder) Cache(org.cache2k.Cache) Test(org.junit.Test)

Example 4 with Cache2kBuilder

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

the class CacheManagerLifeCycleTest method onlyOneCacheForWired.

@Test
public void onlyOneCacheForWired() {
    String _uniqueName = this.getClass().getName() + ".onlyOneCacheForWired";
    CacheManager cm = CacheManager.getInstance(_uniqueName);
    Cache2kBuilder b = Cache2kBuilder.forUnknownTypes().manager(cm);
    StaticUtil.enforceWiredCache(b);
    Cache c = b.build();
    assertEquals("one cache active", 1, StaticUtil.count(cm.getActiveCaches()));
    cm.close();
}
Also used : CacheManager(org.cache2k.CacheManager) Cache2kBuilder(org.cache2k.Cache2kBuilder) Cache(org.cache2k.Cache) Test(org.junit.Test)

Example 5 with Cache2kBuilder

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

the class CacheRule method buildCache.

Cache<K, V> buildCache() {
    String _name = description.getTestClass().getName();
    Cache2kBuilder b = getInitialBuilder();
    for (Specialization sp : configurationSpecialization) {
        sp.extend(b);
    }
    if (shared) {
        b.name(description.getTestClass());
        sharedCache.put(_name, _name);
    } else {
        if (sharedCache.containsKey(_name)) {
            throw new IllegalArgumentException("Shared cache usage: Method rule must be identical instance.");
        }
        b.name(description.getTestClass(), description.getMethodName());
    }
    return b.build();
}
Also used : Cache2kBuilder(org.cache2k.Cache2kBuilder)

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