/** * {@inheritDoc} */ @Override public V get(K key) throws CacheLoadingException { return cache.get(key); }
/** * {@inheritDoc} */ @Override public void put(K key, V value) throws CacheWritingException { cache.put(key, value); }
/** * {@inheritDoc} */ @Override public boolean remove(K key, V value) throws CacheWritingException { return cache.remove(key, value); }
ehcache.get("foo"); fail(); } catch (IllegalStateException e) { ehcache.put("foo", "bar"); fail(); } catch (IllegalStateException e) { ehcache.remove("foo"); fail(); } catch (IllegalStateException e) { ehcache.remove("foo", "bar"); fail(); } catch (IllegalStateException e) { ehcache.containsKey("foo"); fail(); } catch (IllegalStateException e) { ehcache.replace("foo", "bar"); fail(); } catch (IllegalStateException e) { ehcache.replace("foo", "foo", "bar"); fail(); } catch (IllegalStateException e) { ehcache.putIfAbsent("foo", "bar");
@Test public void testFailingTransitionGoesToLowestStatus() throws Exception { final LifeCycled mock = mock(LifeCycled.class); InternalCache ehcache = getCache(mock(Store.class)); doThrow(new Exception()).when(mock).init(); ehcache.addHook(mock); try { ehcache.init(); fail(); } catch (StateTransitionException e) { assertThat(ehcache.getStatus(), is(Status.UNINITIALIZED)); } reset(mock); ehcache.init(); assertThat(ehcache.getStatus(), is(Status.AVAILABLE)); ehcache.close(); }
/** * {@inheritDoc} */ @Override public boolean replace(K key, V oldValue, V newValue) throws CacheLoadingException, CacheWritingException { return cache.replace(key, oldValue, newValue); }
CacheEventListener<K, V> lsnr = evntLsnrFactory.createEventListener(alias, lsnrConfig); if (lsnr != null) { cache.getRuntimeConfiguration().registerCacheEventListener(lsnr, lsnrConfig.orderingMode(), lsnrConfig.firingMode(), lsnrConfig.fireOn()); lifeCycledList.add(new LifeCycled() { cache.addHook(lifeCycled);
@Test public void testRemoveAll() throws Exception { Store<Number, CharSequence> store = mock(Store.class); InternalCache<Number, CharSequence> ehcache = getCache(store); ehcache.init(); ehcache.removeAll(new HashSet<Number>(Arrays.asList(1, 2, 3))); verify(store).bulkCompute((Set<? extends Number>) argThat(hasItems(1, 2, 3)), any(Function.class)); }
@Test public void testPutAll() throws Exception { @SuppressWarnings("unchecked") Store<Number, CharSequence> store = mock(Store.class); InternalCache<Number, CharSequence> ehcache = getCache(store); ehcache.init(); Map<Number, CharSequence> map = new HashMap<>(3); map.put(1, "one"); map.put(2, "two"); map.put(3, "three"); ehcache.putAll(map); verify(store).bulkCompute((Set<? extends Number>) argThat(hasItems((Number)1, 2, 3)), any(Function.class)); }
}); InternalCache<Object, Object> ehcache = getCache(store); ehcache.init(); assertThat(ehcache.putIfAbsent("foo", value), nullValue()); assertThat(ehcache.putIfAbsent("foo", "foo"), CoreMatchers.is(value)); assertThat(ehcache.putIfAbsent("foo", "foobar"), CoreMatchers.is(value)); assertThat(ehcache.putIfAbsent("foo", value), CoreMatchers.is(value));
/** * {@inheritDoc} */ @Override public boolean containsKey(K key) { return cache.containsKey(key); }
/** * {@inheritDoc} */ @Override public void clear() { cache.clear(); }
/** * {@inheritDoc} */ @Override public void putAll(Map<? extends K, ? extends V> entries) throws BulkCacheWritingException { cache.putAll(entries); }
/** * {@inheritDoc} */ @Override public V putIfAbsent(K key, V value) throws CacheLoadingException, CacheWritingException { return cache.putIfAbsent(key, value); }
/** * {@inheritDoc} */ @Override public void removeAll(Set<? extends K> keys) throws BulkCacheWritingException { cache.removeAll(keys); }
registerListeners(cache, serviceLocator, lifeCycledList); for (LifeCycled lifeCycled : lifeCycledList) { (cache).addHook(lifeCycled);
private void assertFailingTransitionGoesToLowestStatus(InternalCache cache) throws Exception { final LifeCycled mock = mock(LifeCycled.class); cache.addHook(mock); doThrow(new Exception()).when(mock).init(); try { cache.init(); fail(); } catch (StateTransitionException e) { assertThat(cache.getStatus(), CoreMatchers.is(Status.UNINITIALIZED)); } reset(mock); cache.init(); assertThat(cache.getStatus(), is(Status.AVAILABLE)); doThrow(new Exception()).when(mock).close(); try { cache.close(); fail(); } catch (StateTransitionException e) { assertThat(cache.getStatus(), is(Status.UNINITIALIZED)); } }