/** * Tests {@link Ehcache#containsKey(Object) Ehcache.containsKey} over an empty cache * where {@link Store#containsKey(Object) Store.containsKey} throws a * {@link StoreAccessException StoreAccessException}. */ @Test public void testContainsKeyEmptyStoreAccessException() throws Exception { final FakeStore realStore = new FakeStore(Collections.<String, String>emptyMap()); this.store = spy(realStore); doThrow(new StoreAccessException("")).when(this.store).containsKey("key"); final Ehcache<String, String> ehcache = this.getEhcache(); ehcache.containsKey("key"); verify(this.resilienceStrategy).containsKeyFailure(eq("key"), any(StoreAccessException.class)); }
/** * Tests {@link Ehcache#clear()} over an empty cache. */ @Test public void testClearEmpty() throws Exception { final FakeStore realStore = new FakeStore(Collections.<String, String>emptyMap()); this.store = spy(realStore); final Ehcache<String, String> ehcache = this.getEhcache(); ehcache.clear(); verifyZeroInteractions(this.resilienceStrategy); assertThat(realStore.getEntryMap().isEmpty(), is(true)); }
/** * Tests {@link Ehcache#clear()} over an empty cache where * {@link Store#clear() Store.clear} throws a * {@link StoreAccessException StoreAccessException}. */ @Test public void testClearEmptyStoreAccessException() throws Exception { final FakeStore realStore = new FakeStore(Collections.<String, String>emptyMap()); this.store = spy(realStore); doThrow(new StoreAccessException("")).when(this.store).clear(); final Ehcache<String, String> ehcache = this.getEhcache(); ehcache.clear(); verify(this.resilienceStrategy).clearFailure(any(StoreAccessException.class)); }
/** * Tests {@link java.util.Iterator#next()} from {@link Ehcache#iterator()} on an empty cache. */ @Test public void testIteratorEmptyStoreNext() throws Exception { this.store = new FakeStore(Collections.emptyMap()); final InternalCache<String, String> ehcache = this.getEhcache(); final Iterator<Cache.Entry<String, String>> iterator = ehcache.iterator(); try { iterator.next(); fail(); } catch (NoSuchElementException e) { // expected } }
/** * Tests {@link java.util.Iterator#remove()} from {@link Ehcache#iterator()} on an empty cache. */ @Test public void testIteratorEmptyStoreRemoveBeforeNext() throws Exception { this.store = new FakeStore(Collections.emptyMap()); final InternalCache<String, String> ehcache = this.getEhcache(); final Iterator<Cache.Entry<String, String>> iterator = ehcache.iterator(); try { iterator.remove(); fail(); } catch (IllegalStateException e) { // expected } }
/** * Tests fetching all entries via an {@link Ehcache#iterator()} on a non-empty cache. */ @Test public void testIteratorNonEmptyAll() throws Exception { final Map<String, String> testStoreEntries = this.getTestStoreEntries(); this.store = new FakeStore(testStoreEntries); final InternalCache<String, String> ehcache = this.getEhcache(); for (Cache.Entry<String, String> cacheEntry : ehcache) { final String cacheEntryKey = cacheEntry.getKey(); assertThat(testStoreEntries, hasEntry(equalTo(cacheEntryKey), equalTo(cacheEntry.getValue()))); testStoreEntries.remove(cacheEntryKey); } assertThat("Iterator did not return all values", testStoreEntries.isEmpty(), is(true)); }
@Test public void testRemoveAllNull() throws Exception { final Map<String, String> originalStoreContent = getEntryMap(KEY_SET_A, KEY_SET_B); final FakeStore fakeStore = new FakeStore(originalStoreContent); this.store = spy(fakeStore); final Ehcache<String, String> ehcache = this.getEhcache(); try { ehcache.removeAll(null); fail(); } catch (NullPointerException e) { // Expected } assertThat(fakeStore.getEntryMap(), equalTo(originalStoreContent)); }
@Test public void testPutAllNull() throws Exception { final Map<String, String> originalStoreContent = getEntryMap(KEY_SET_A, KEY_SET_B); final FakeStore fakeStore = new FakeStore(originalStoreContent); this.store = spy(fakeStore); final Ehcache<String, String> ehcache = this.getEhcache(); try { ehcache.putAll(null); fail(); } catch (NullPointerException e) { // Expected } assertThat(fakeStore.getEntryMap(), equalTo(originalStoreContent)); }
/** * Tests {@link Ehcache#containsKey(Object) Ehcache.containsKey} over a non-empty cache * not holding the target key where {@link Store#containsKey(Object) Store.containsKey} * throws a {@link StoreAccessException StoreAccessException}. */ @Test public void testContainsKeyMissingStoreAccessException() throws Exception { final FakeStore realStore = new FakeStore(this.getTestStoreEntries()); this.store = spy(realStore); doThrow(new StoreAccessException("")).when(this.store).containsKey("missingKey"); final Ehcache<String, String> ehcache = this.getEhcache(); ehcache.containsKey("missingKey"); verify(this.resilienceStrategy).containsKeyFailure(eq("missingKey"), any(StoreAccessException.class)); }
/** * Tests {@link Ehcache#containsKey(Object) Ehcache.containsKey} over a cache holding * the target key where {@link Store#containsKey(Object) Store.containsKey} * throws a {@link StoreAccessException StoreAccessException}. */ @Test public void testContainsKeyContainsStoreAccessException() throws Exception { final FakeStore realStore = new FakeStore(this.getTestStoreEntries()); this.store = spy(realStore); doThrow(new StoreAccessException("")).when(this.store).containsKey("keyA"); final Ehcache<String, String> ehcache = this.getEhcache(); ehcache.containsKey("keyA"); verify(this.resilienceStrategy).containsKeyFailure(eq("keyA"), any(StoreAccessException.class)); }
/** * Tests {@link java.util.Iterator#hasNext()} <b>after</b> exhausting the {@code Iterator} returned * from {@link Ehcache#iterator()} on a non-empty cache. */ @Test public void testIteratorNonEmptyHasNextAfterLast() throws Exception { this.store = new FakeStore(this.getTestStoreEntries()); final InternalCache<String, String> ehcache = this.getEhcache(); final Iterator<Cache.Entry<String, String>> iterator = ehcache.iterator(); while (iterator.hasNext()) { iterator.next(); } assertThat(iterator.hasNext(), is(false)); }
/** * Tests {@link Ehcache#clear()} over a non-empty cache. */ @Test public void testClearNonEmpty() throws Exception { final FakeStore realStore = new FakeStore(this.getTestStoreEntries()); this.store = spy(realStore); final Ehcache<String, String> ehcache = this.getEhcache(); assertThat(realStore.getEntryMap().isEmpty(), is(false)); ehcache.clear(); verifyZeroInteractions(this.resilienceStrategy); assertThat(realStore.getEntryMap().isEmpty(), is(true)); }
/** * Tests {@link Ehcache#containsKey(Object) Ehcache.containsKey} over an empty cache. */ @Test public void testContainsKeyEmpty() throws Exception { final FakeStore realStore = new FakeStore(Collections.<String, String>emptyMap()); this.store = spy(realStore); final Ehcache<String, String> ehcache = this.getEhcache(); assertFalse(ehcache.containsKey("key")); verifyZeroInteractions(this.resilienceStrategy); }
/** * Tests {@link java.util.Iterator#next()} from {@link Ehcache#iterator()} on a non-empty cache. */ @Test public void testIteratorNonEmptyStoreNext() throws Exception { this.store = new FakeStore(this.getTestStoreEntries()); final InternalCache<String, String> ehcache = this.getEhcache(); final Iterator<Cache.Entry<String, String>> iterator = ehcache.iterator(); assertThat(iterator.next(), is(notNullValue())); }
/** * Tests {@link Ehcache#iterator()} on an empty cache. */ @Test public void testIteratorEmptyStoreGet() throws Exception { this.store = new FakeStore(Collections.emptyMap()); final InternalCache<String, String> ehcache = this.getEhcache(); assertThat(ehcache.iterator(), is(notNullValue())); }
/** * Tests {@link Ehcache#containsKey(Object) Ehcache.containsKey} over a non-empty cache * not holding the target key. */ @Test public void testContainsKeyMissing() throws Exception { final FakeStore realStore = new FakeStore(this.getTestStoreEntries()); this.store = spy(realStore); final Ehcache<String, String> ehcache = this.getEhcache(); assertFalse(ehcache.containsKey("missingKey")); verifyZeroInteractions(this.resilienceStrategy); }
/** * Tests {@link Ehcache#containsKey(Object) Ehcache.containsKey} over a cache holding * the target key. */ @Test public void testContainsKeyContains() throws Exception { final FakeStore realStore = new FakeStore(this.getTestStoreEntries()); this.store = spy(realStore); final Ehcache<String, String> ehcache = this.getEhcache(); assertTrue(ehcache.containsKey("keyA")); verifyZeroInteractions(this.resilienceStrategy); }
/** * Tests {@link java.util.Iterator#hasNext()} from {@link Ehcache#iterator()} on an empty cache. */ @Test public void testIteratorEmptyStoreHasNext() throws Exception { this.store = new FakeStore(Collections.emptyMap()); final InternalCache<String, String> ehcache = this.getEhcache(); final Iterator<Cache.Entry<String, String>> iterator = ehcache.iterator(); assertThat(iterator.hasNext(), is(false)); }
/** * Tests {@link java.util.Iterator#hasNext()} from {@link Ehcache#iterator()} on a non-empty cache. */ @Test public void testIteratorNonEmptyStoreHasNext() throws Exception { this.store = new FakeStore(this.getTestStoreEntries()); final InternalCache<String, String> ehcache = this.getEhcache(); final Iterator<Cache.Entry<String, String>> iterator = ehcache.iterator(); assertThat(iterator.hasNext(), is(true)); }
/** * Tests {@link Ehcache#iterator()} on a non-empty cache. */ @Test public void testIteratorNonEmptyStoreGet() throws Exception { this.store = new FakeStore(this.getTestStoreEntries()); final InternalCache<String, String> ehcache = this.getEhcache(); assertThat(ehcache.iterator(), is(notNullValue())); }