use of org.cache2k.Cache 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());
}
use of org.cache2k.Cache 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) {
}
}
use of org.cache2k.Cache 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);
}
use of org.cache2k.Cache 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;
}
use of org.cache2k.Cache in project cache2k by cache2k.
the class ListenerTest method manyAsyncUpdateListenerCalled.
/**
* Check that we do not miss events.
*/
@Test(timeout = TestingParameters.MAX_FINISH_WAIT_MILLIS)
public void manyAsyncUpdateListenerCalled() {
final AtomicInteger _callCount = new AtomicInteger();
final ConcurrentMap<Integer, Integer> _seenValues = new ConcurrentHashMap<Integer, Integer>();
Cache<Integer, Integer> c = target.cache(new CacheRule.Specialization<Integer, Integer>() {
@Override
public void extend(final Cache2kBuilder<Integer, Integer> b) {
b.addAsyncListener(new CacheEntryUpdatedListener<Integer, Integer>() {
@Override
public void onEntryUpdated(final Cache<Integer, Integer> cache, final CacheEntry<Integer, Integer> currentEntry, final CacheEntry<Integer, Integer> entryWithNewData) {
_seenValues.put(entryWithNewData.getValue(), entryWithNewData.getValue());
_callCount.incrementAndGet();
}
});
}
});
c.put(1, 2);
assertEquals(0, _callCount.get());
final int _UPDATE_COUNT = 123;
for (int i = 0; i < _UPDATE_COUNT; i++) {
c.put(1, i);
}
ConcurrencyHelper.await(new Condition() {
@Override
public boolean check() throws Exception {
return _callCount.get() == _UPDATE_COUNT;
}
});
assertEquals("Event dispatching is using copied events", 123, _seenValues.size());
}
Aggregations