Search in sources :

Example 36 with Cache

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

the class BasicCacheOperationsTest method peekAndPut_Exception.

@Test(expected = CacheLoaderException.class)
public void peekAndPut_Exception() {
    ((Cache) cache).put(KEY, new ExceptionWrapper(OUCH));
    cache.peekAndPut(KEY, VALUE);
}
Also used : ExceptionWrapper(org.cache2k.core.ExceptionWrapper) InternalCache(org.cache2k.core.InternalCache) Cache(org.cache2k.Cache)

Example 37 with Cache

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

the class BasicCacheOperationsTest method peekEntry_Exception.

@Test
public void peekEntry_Exception() {
    ((Cache) cache).put(KEY, new ExceptionWrapper(OUCH));
    CacheEntry<Integer, Integer> e = cache.peekEntry(KEY);
    assertEquals(KEY, e.getKey());
    entryHasException(e);
    assertEquals(OUCH, e.getException());
}
Also used : ExceptionWrapper(org.cache2k.core.ExceptionWrapper) InternalCache(org.cache2k.core.InternalCache) Cache(org.cache2k.Cache)

Example 38 with Cache

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

the class Cache2kBuilderTest method cacheNameInClassConstructor0.

@Test
public void cacheNameInClassConstructor0() {
    Cache c = BuildCacheInClassConstructor0.cache;
    assertThat(c.getName(), startsWith("_" + CLASSNAME + "$BuildCacheInClassConstructor0.CLINIT"));
    c.close();
}
Also used : Cache(org.cache2k.Cache) Test(org.junit.Test)

Example 39 with Cache

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

the class Cache2kBuilderTest method cacheCapacityDefault1234.

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

Example 40 with Cache

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

the class Cache2kBuilderTest method illegalCharacterInCacheName_unsafeSet.

@Test
public void illegalCharacterInCacheName_unsafeSet() {
    for (char c : ILLEGAL_CHARACTERS_IN_NAME.toCharArray()) {
        try {
            Cache _cache = Cache2kBuilder.forUnknownTypes().name("illegalCharName" + c).build();
            _cache.close();
            fail("Expect exception for illegal name in character '" + c + "', code " + ((int) c));
        } catch (IllegalArgumentException ex) {
        }
    }
}
Also used : 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