Search in sources :

Example 1 with CacheManager

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

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

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

the class CacheManagerLifeCycleTest method getActiveCaches.

@Test
public void getActiveCaches() {
    String _uniqueName = this.getClass().getName() + ".getActiveCaches";
    CacheManager cm = CacheManager.getInstance(_uniqueName);
    assertFalse(cm.getActiveCaches().iterator().hasNext());
    Cache c = Cache2kBuilder.forUnknownTypes().manager(cm).build();
    assertTrue(cm.getActiveCaches().iterator().hasNext());
    cm.close();
}
Also used : CacheManager(org.cache2k.CacheManager) Cache(org.cache2k.Cache) Test(org.junit.Test)

Example 4 with CacheManager

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

the class CacheManagerLifeCycleTest method createCache.

@Test
public void createCache() {
    String _uniqueName = this.getClass().getName() + ".createCache";
    CacheManager cm = CacheManager.getInstance(_uniqueName);
    Cache c = cm.createCache(Cache2kBuilder.forUnknownTypes().name("dummy").toConfiguration());
    assertEquals("dummy", c.getName());
    assertSame(cm, c.getCacheManager());
    cm.close();
}
Also used : CacheManager(org.cache2k.CacheManager) Cache(org.cache2k.Cache) Test(org.junit.Test)

Example 5 with CacheManager

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

Aggregations

CacheManager (org.cache2k.CacheManager)27 Test (org.junit.Test)24 Cache (org.cache2k.Cache)11 MBeanInfo (javax.management.MBeanInfo)4 URLClassLoader (java.net.URLClassLoader)3 Cache2kBuilder (org.cache2k.Cache2kBuilder)3 Log (org.cache2k.core.util.Log)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 WeakHashMap (java.util.WeakHashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CacheEntry (org.cache2k.CacheEntry)1 Cache2kConfiguration (org.cache2k.configuration.Cache2kConfiguration)1 CacheEntryCreatedListener (org.cache2k.event.CacheEntryCreatedListener)1