Search in sources :

Example 21 with CacheManager

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

the class CacheManagerExclusiveTest method closeAll.

@Test
public void closeAll() {
    CacheManager cm = CacheManager.getInstance();
    ClassLoader cl1 = new URLClassLoader(new URL[0], this.getClass().getClassLoader());
    ClassLoader cl2 = new URLClassLoader(new URL[0], this.getClass().getClassLoader());
    CacheManager cm1 = CacheManager.getInstance(cl1);
    CacheManager cm2 = CacheManager.getInstance(cl2);
    CacheManager.closeAll();
    assertTrue(cm1.isClosed());
    assertTrue(cm2.isClosed());
    assertTrue(cm.isClosed());
}
Also used : URLClassLoader(java.net.URLClassLoader) CacheManager(org.cache2k.CacheManager) URLClassLoader(java.net.URLClassLoader) Test(org.junit.Test)

Example 22 with CacheManager

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

the class CacheManagerLifeCycleTest method differentClassLoaderDifferentManager.

@Test
public void differentClassLoaderDifferentManager() {
    ClassLoader cl1 = new URLClassLoader(new URL[0], this.getClass().getClassLoader());
    ClassLoader cl2 = new URLClassLoader(new URL[0], this.getClass().getClassLoader());
    CacheManager cm1 = CacheManager.getInstance(cl1);
    CacheManager cm2 = CacheManager.getInstance(cl2);
    assertNotSame(cm1, cm2);
    assertFalse(cm1.isClosed());
    assertFalse(cm2.isClosed());
    CacheManager.closeAll(cl1);
    CacheManager.closeAll(cl2);
    assertTrue(cm1.isClosed());
    assertTrue(cm2.isClosed());
}
Also used : URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) CacheManager(org.cache2k.CacheManager) Test(org.junit.Test)

Example 23 with CacheManager

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

the class CacheManagerLifeCycleTest method closeSpecific.

@Test
public void closeSpecific() {
    ClassLoader cl1 = new URLClassLoader(new URL[0], this.getClass().getClassLoader());
    CacheManager cm1 = CacheManager.getInstance(cl1);
    CacheManager.close(cl1, "something");
    assertFalse(cm1.isClosed());
    CacheManager.close(cl1, "default");
    assertTrue(cm1.isClosed());
}
Also used : URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) CacheManager(org.cache2k.CacheManager) Test(org.junit.Test)

Example 24 with CacheManager

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

the class CacheManagerLifeCycleTest method openClose.

@Test
public void openClose() {
    String _uniqueName = this.getClass().getName() + ".openClose";
    CacheManager cm = CacheManager.getInstance(_uniqueName);
    cm.close();
    CacheManager cm2 = CacheManager.getInstance(_uniqueName);
    assertNotSame(cm, cm2);
    cm2.close();
}
Also used : CacheManager(org.cache2k.CacheManager) Test(org.junit.Test)

Example 25 with CacheManager

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

the class CacheManagerLifeCycleTest method clearAllCaches.

@Test
public void clearAllCaches() {
    String _uniqueName = this.getClass().getName() + ".clearAllCaches";
    CacheManager cm = CacheManager.getInstance(_uniqueName);
    Cache c = Cache2kBuilder.forUnknownTypes().manager(cm).name("dummy").build();
    c.put("hello", "paul");
    assertTrue("has some data", c.keys().iterator().hasNext());
    c.getCacheManager().clear();
    assertFalse("no data", c.keys().iterator().hasNext());
    cm.close();
}
Also used : CacheManager(org.cache2k.CacheManager) 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