Search in sources :

Example 1 with ExceptionWrapper

use of org.cache2k.core.ExceptionWrapper in project cache2k by cache2k.

the class BasicCacheOperationsTest method getEntry_Exception.

@Test
public void getEntry_Exception() {
    ((Cache) cache).put(KEY, new ExceptionWrapper(OUCH));
    CacheEntry<Integer, Integer> e = cache.getEntry(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 2 with ExceptionWrapper

use of org.cache2k.core.ExceptionWrapper in project cache2k by cache2k.

the class BasicCacheOperationsTest method peekAll_Exception.

@Test
public void peekAll_Exception() {
    ((Cache) cache).put(KEY, new ExceptionWrapper(OUCH));
    Map<Integer, Integer> m = cache.peekAll(toIterable(KEY, OTHER_KEY));
    assertEquals(1, m.size());
    assertEquals(1, m.values().size());
    assertEquals(1, m.keySet().size());
    assertEquals(1, m.entrySet().size());
    try {
        m.get(KEY);
        fail("Exception expected");
    } catch (CacheLoaderException ex) {
    }
    Iterator<Integer> it = m.keySet().iterator();
    assertTrue(it.hasNext());
    assertEquals(KEY, it.next());
    assertFalse("one entry", it.hasNext());
    it = m.values().iterator();
    assertTrue(it.hasNext());
    try {
        assertEquals(KEY, it.next());
        fail("Exception expected");
    } catch (CacheLoaderException ex) {
    }
    Iterator<Map.Entry<Integer, Integer>> ei = m.entrySet().iterator();
    assertTrue(ei.hasNext());
    Map.Entry<Integer, Integer> e = ei.next();
    assertEquals(KEY, e.getKey());
    try {
        e.getValue();
        fail("Exception expected");
    } catch (CacheLoaderException ex) {
    }
}
Also used : CacheEntry(org.cache2k.CacheEntry) CacheLoaderException(org.cache2k.integration.CacheLoaderException) ExceptionWrapper(org.cache2k.core.ExceptionWrapper) HashMap(java.util.HashMap) Map(java.util.Map) InternalCache(org.cache2k.core.InternalCache) Cache(org.cache2k.Cache)

Example 3 with ExceptionWrapper

use of org.cache2k.core.ExceptionWrapper in project cache2k by cache2k.

the class BasicCacheOperationsTest method peekAndReplace_Exception.

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

Example 4 with ExceptionWrapper

use of org.cache2k.core.ExceptionWrapper in project cache2k by cache2k.

the class ExceptionPropagatorTest method prepCache.

Cache<Integer, Integer> prepCache() {
    Cache c = target.cache();
    c.put(KEY, new ExceptionWrapper(new IllegalArgumentException("Test")));
    assertTrue(c.containsKey(KEY));
    return c;
}
Also used : ExceptionWrapper(org.cache2k.core.ExceptionWrapper) Cache(org.cache2k.Cache)

Example 5 with ExceptionWrapper

use of org.cache2k.core.ExceptionWrapper in project cache2k by cache2k.

the class BasicCacheOperationsTest method peekAndRemove_Exception.

@Test
public void peekAndRemove_Exception() {
    ((Cache) cache).put(KEY, new ExceptionWrapper(OUCH));
    try {
        cache.peekAndRemove(KEY);
        fail("exception expected");
    } catch (CacheLoaderException ex) {
    }
}
Also used : CacheLoaderException(org.cache2k.integration.CacheLoaderException) ExceptionWrapper(org.cache2k.core.ExceptionWrapper) InternalCache(org.cache2k.core.InternalCache) Cache(org.cache2k.Cache)

Aggregations

Cache (org.cache2k.Cache)8 ExceptionWrapper (org.cache2k.core.ExceptionWrapper)8 InternalCache (org.cache2k.core.InternalCache)7 CacheLoaderException (org.cache2k.integration.CacheLoaderException)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CacheEntry (org.cache2k.CacheEntry)1