Search in sources :

Example 6 with MutableCacheEntry

use of org.cache2k.processor.MutableCacheEntry 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");
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EntryProcessor(org.cache2k.processor.EntryProcessor) MutableCacheEntry(org.cache2k.processor.MutableCacheEntry) Test(org.junit.Test)

Example 7 with MutableCacheEntry

use of org.cache2k.processor.MutableCacheEntry 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 8 with MutableCacheEntry

use of org.cache2k.processor.MutableCacheEntry 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 9 with MutableCacheEntry

use of org.cache2k.processor.MutableCacheEntry 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

MutableCacheEntry (org.cache2k.processor.MutableCacheEntry)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 EntryProcessor (org.cache2k.processor.EntryProcessor)8 Test (org.junit.Test)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 NoSuchElementException (java.util.NoSuchElementException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Duration (javax.cache.expiry.Duration)1 CacheEntry (org.cache2k.CacheEntry)1 CacheLoaderException (org.cache2k.integration.CacheLoaderException)1 ExceptionInformation (org.cache2k.integration.ExceptionInformation)1 ResiliencePolicy (org.cache2k.integration.ResiliencePolicy)1 EntryProcessingException (org.cache2k.processor.EntryProcessingException)1 CacheRule (org.cache2k.test.util.CacheRule)1 IntCacheRule (org.cache2k.test.util.IntCacheRule)1