Search in sources :

Example 1 with Cache

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

the class Cache2kBuilderTest method cacheRemovedAfterClose.

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

Example 2 with Cache

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

the class Cache2kBuilderTest method cacheCapacity10.

@Test
public void cacheCapacity10() {
    Cache c0 = Cache2kBuilder.forUnknownTypes().entryCapacity(10).build();
    assertEquals(10, latestInfo(c0).getHeapCapacity());
    c0.close();
}
Also used : Cache(org.cache2k.Cache) Test(org.junit.Test)

Example 3 with Cache

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

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

use of org.cache2k.Cache 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)

Aggregations

Cache (org.cache2k.Cache)60 Test (org.junit.Test)49 CacheManager (org.cache2k.CacheManager)11 Cache2kBuilder (org.cache2k.Cache2kBuilder)9 CacheEntry (org.cache2k.CacheEntry)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 ExceptionWrapper (org.cache2k.core.ExceptionWrapper)8 InternalCache (org.cache2k.core.InternalCache)8 CacheRule (org.cache2k.test.util.CacheRule)6 Condition (org.cache2k.test.util.Condition)6 IntCacheRule (org.cache2k.test.util.IntCacheRule)5 CountDownLatch (java.util.concurrent.CountDownLatch)3 MBeanInfo (javax.management.MBeanInfo)3 Log (org.cache2k.core.util.Log)3 CacheEntryCreatedListener (org.cache2k.event.CacheEntryCreatedListener)3 CacheEntryUpdatedListener (org.cache2k.event.CacheEntryUpdatedListener)3 ArrayList (java.util.ArrayList)2 CacheLoaderException (org.cache2k.integration.CacheLoaderException)2 Collection (java.util.Collection)1 Date (java.util.Date)1