Search in sources :

Example 11 with Cache

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

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

the class CacheManagerLifeCycleTest method closesCache.

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

Example 13 with Cache

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

the class JmxSupportTest method testCacheCreated.

@Test
public void testCacheCreated() throws Exception {
    String _name = getClass().getName() + ".testCacheCreated";
    Cache c = Cache2kBuilder.of(Object.class, Object.class).name(_name).eternal(true).build();
    MBeanInfo i = getCacheInfo(_name);
    assertEquals(CacheMXBeanImpl.class.getName(), i.getClassName());
    c.close();
}
Also used : MBeanInfo(javax.management.MBeanInfo) Cache(org.cache2k.Cache) Test(org.junit.Test)

Example 14 with Cache

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

the class JmxSupportTest method testCacheDestroyed.

@Test(expected = InstanceNotFoundException.class)
public void testCacheDestroyed() throws Exception {
    String _name = getClass().getName() + ".testCacheDestroyed";
    Cache c = Cache2kBuilder.of(Object.class, Object.class).name(_name).eternal(true).build();
    MBeanInfo i = getCacheInfo(_name);
    assertEquals(CacheMXBeanImpl.class.getName(), i.getClassName());
    c.close();
    getCacheInfo(_name);
}
Also used : MBeanInfo(javax.management.MBeanInfo) Cache(org.cache2k.Cache) Test(org.junit.Test)

Example 15 with Cache

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

the class LegalNamesTest method testCache.

@Test
public void testCache() throws Exception {
    String _name = LegalNamesTest.class.getName() + "-test-with-char-" + aChar;
    Cache c = Cache2kBuilder.forUnknownTypes().name(_name).build();
    assertEquals("default", c.getCacheManager().getName());
    assertTrue(c.getCacheManager().isDefaultManager());
    assertEquals(_name, c.getName());
    MBeanInfo inf = JmxSupportTest.getCacheManagerInfo(c.getCacheManager().getName());
    assertNotNull(inf);
    inf = JmxSupportTest.getCacheInfo(c.getName());
    assertNotNull(inf);
    c.close();
}
Also used : MBeanInfo(javax.management.MBeanInfo) 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