use of org.cache2k.processor.EntryProcessor in project cache2k by cache2k.
the class EntryProcessorTest method initial_Not_Existing.
@Test
public void initial_Not_Existing() {
Cache<Integer, Integer> c = target.cache();
final AtomicBoolean _reached = new AtomicBoolean(false);
final int _KEY = 123;
EntryProcessor p = new EntryProcessor() {
@Override
public Object process(MutableCacheEntry e) throws Exception {
assertFalse(e.exists());
assertEquals(0, e.getLastModification());
assertEquals(_KEY, e.getKey());
_reached.set(true);
return null;
}
};
Object _result = c.invoke(_KEY, p);
assertNull(_result);
}
use of org.cache2k.processor.EntryProcessor in project cache2k by cache2k.
the class EntryProcessorTest method intial_noop.
/*
Cache<Integer, Integer> cache;
@Before public void setup() { cache = target.cache(); }
*/
@Test
public void intial_noop() {
Cache<Integer, Integer> c = target.cache();
EntryProcessor p = new EntryProcessor() {
@Override
public Object process(MutableCacheEntry e) throws Exception {
return null;
}
};
Object _result = c.invoke(123, p);
assertNull(_result);
}
use of org.cache2k.processor.EntryProcessor in project cache2k by cache2k.
the class EntryProcessorTest method initial_Return.
@Test
public void initial_Return() {
Cache<Integer, Integer> c = target.cache();
EntryProcessor p = new EntryProcessor() {
@Override
public Object process(MutableCacheEntry e) throws Exception {
return "abc";
}
};
Object _result = c.invoke(123, p);
assertEquals("abc", _result);
}
use of org.cache2k.processor.EntryProcessor in project cache2k by cache2k.
the class TouchyJCacheAdapter method remove.
@Override
public boolean remove(final K key, final V oldValue) {
checkClosed();
checkNullValue(oldValue);
if (key == null) {
throw new NullPointerException();
}
EntryProcessor<K, V, Boolean> ep = new EntryProcessor<K, V, Boolean>() {
@Override
public Boolean process(final MutableCacheEntry<K, V> e) throws Exception {
if (!e.exists()) {
return false;
}
V _existingValue = e.getValue();
if (_existingValue.equals(oldValue)) {
e.remove();
return true;
}
Duration d = expiryPolicy.getExpiryForAccess();
if (d != null) {
e.setExpiry(calculateExpiry(d));
}
return false;
}
};
return c2kCache.invoke(key, ep);
}
use of org.cache2k.processor.EntryProcessor in project cache2k by cache2k.
the class EntryProcessorTest method initial_NullKey.
@Test(expected = NullPointerException.class)
public void initial_NullKey() {
Cache<Integer, Integer> c = target.cache();
EntryProcessor p = new EntryProcessor() {
@Override
public Object process(MutableCacheEntry e) throws Exception {
return null;
}
};
Object _result = c.invoke(null, p);
fail("never reached");
}
Aggregations