Search in sources :

Example 6 with EntryProcessor

use of org.cache2k.processor.EntryProcessor in project cache2k by cache2k.

the class EntryProcessorTest method initial_GetYieldsNull.

@Test
public void initial_GetYieldsNull() {
    Cache<Integer, Integer> c = target.cache();
    final AtomicBoolean _reached = new AtomicBoolean(false);
    EntryProcessor p = new EntryProcessor() {

        @Override
        public Object process(MutableCacheEntry e) throws Exception {
            assertNull(e.getValue());
            _reached.set(true);
            return null;
        }
    };
    final int _KEY = 123;
    Object _result = c.invoke(_KEY, p);
    assertNull(_result);
    assertTrue("no exception during process", _reached.get());
    assertFalse(c.containsKey(_KEY));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EntryProcessor(org.cache2k.processor.EntryProcessor) MutableCacheEntry(org.cache2k.processor.MutableCacheEntry) Test(org.junit.Test)

Example 7 with EntryProcessor

use of org.cache2k.processor.EntryProcessor in project cache2k by cache2k.

the class EntryProcessorTest method test_Initial_GetSet.

@Test
public void test_Initial_GetSet() {
    target.statistics();
    Cache<Integer, Integer> c = target.cache();
    EntryProcessor p = new EntryProcessor() {

        @Override
        public Object process(MutableCacheEntry e) throws Exception {
            Object o = e.getValue();
            assertNull(o);
            e.setValue("dummy");
            return "abc";
        }
    };
    Object _result = c.invoke(123, p);
    assertEquals("abc", _result);
    target.statistics().missCount.expect(1).getCount.expect(1).putCount.expect(1).expectAllZero();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EntryProcessor(org.cache2k.processor.EntryProcessor) MutableCacheEntry(org.cache2k.processor.MutableCacheEntry) Test(org.junit.Test)

Example 8 with EntryProcessor

use of org.cache2k.processor.EntryProcessor in project cache2k by cache2k.

the class EntryProcessorTest method test_Initial_Set.

@Test
public void test_Initial_Set() {
    Cache<Integer, Integer> c = target.cache();
    EntryProcessor p = new EntryProcessor() {

        @Override
        public Object process(MutableCacheEntry e) throws Exception {
            e.setValue("dummy");
            return "abc";
        }
    };
    Object _result = c.invoke(123, p);
    assertEquals("abc", _result);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EntryProcessor(org.cache2k.processor.EntryProcessor) MutableCacheEntry(org.cache2k.processor.MutableCacheEntry) Test(org.junit.Test)

Aggregations

EntryProcessor (org.cache2k.processor.EntryProcessor)8 MutableCacheEntry (org.cache2k.processor.MutableCacheEntry)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Test (org.junit.Test)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Duration (javax.cache.expiry.Duration)1