private void condRemove(Cache<Long, String> cache, String value, boolean addToCacheRecords) { cache.remove(KEY, value); if (addToCacheRecords) { cacheRecords.add(new Record(KEY, null)); } }
@Test public void testRemove2ArgsWithNoCacheEntry_should_not_call_writer() throws Exception { doThrow(new Exception("Mock Exception: cannot write 1")).when(cacheLoaderWriter).delete(eq(1)); testCache.remove(1, "one"); }
@Test public void testRemove2ArgsWithNotMatchingCacheEntry_should_not_call_writer() throws Exception { doThrow(new Exception("Mock Exception: cannot write 1")).when(cacheLoaderWriter).delete(eq(1)); testCache.put(1, "un"); testCache.remove(1, "one"); }
@Test public void testRemoveWithWriterException() throws Exception { doThrow(new Exception("Mock Exception: cannot write 1")).when(cacheLoaderWriter).delete(eq(1)); try { testCache.remove(1); fail("expected CacheWritingException"); } catch (CacheWritingException ex) { // expected } }
@Test @SuppressWarnings("unchecked") public void testSimpleRemove2ArgsWithLoaderAndWriter_existsInStore_notEquals() throws Exception { testCache.put(1, "un"); reset(cacheLoaderWriter); assertThat(testCache.remove(1, "one"), is(false)); verifyZeroInteractions(cacheLoaderWriter); }
@Test @SuppressWarnings("unchecked") public void testSimpleRemove2ArgsWithLoaderAndWriter_existsInStore() throws Exception { testCache.put(1, "un"); reset(cacheLoaderWriter); assertThat(testCache.remove(1, "un"), is(true)); verify(cacheLoaderWriter, times(1)).delete(eq(1)); verifyNoMoreInteractions(cacheLoaderWriter); }
@Test public void testSimpleRemove2ArgsWithLoaderAndWriter_existsInSor_notEquals() throws Exception { when(cacheLoaderWriter.load(eq(1))).thenAnswer((Answer) invocation -> "un"); assertThat(testCache.containsKey(1), is(false)); assertThat(testCache.remove(1, "one"), is(false)); verify(cacheLoaderWriter, times(1)).load(eq(1)); verifyNoMoreInteractions(cacheLoaderWriter); }
@Test public void testSimpleRemove2ArgsWithLoaderAndWriter_absent() throws Exception { when(cacheLoaderWriter.load(eq(1))).thenAnswer((Answer) invocation -> null); assertThat(testCache.containsKey(1), is(false)); assertThat(testCache.remove(1, "one"), is(false)); verify(cacheLoaderWriter, times(1)).load(eq(1)); verifyNoMoreInteractions(cacheLoaderWriter); }
@Test public void testSimpleRemove2ArgsWithLoaderAndWriter_existsInSor() throws Exception { when(cacheLoaderWriter.load(eq(1))).thenAnswer((Answer) invocation -> "un"); assertThat(testCache.containsKey(1), is(false)); assertThat(testCache.remove(1, "un"), is(true)); verify(cacheLoaderWriter, times(1)).load(eq(1)); verify(cacheLoaderWriter, times(1)).delete(eq(1)); }
@Test public void testRemove2ArgsWithWriterException_should_call_writer() throws Exception { doThrow(new Exception("Mock Exception: cannot write 1")).when(cacheLoaderWriter).delete(eq(1)); testCache.put(1, "one"); try { testCache.remove(1, "one"); fail("expected CacheWritingException"); } catch (CacheWritingException ex) { // expected } }
@Test public void getRemovals() throws Exception { cache.put(1L, "a"); cache.remove(1L); assertThat(onHeap.getRemovals()).isEqualTo(1L); assertStat("OnHeap:RemovalCount").isEqualTo(1L); }
@Test public void removeKV() { expect(cache.remove(1, "a")).isFalse(); changesOf(0, 1, 0, 0); cache.put(1, "a"); changesOf(0, 0, 1, 0); expect(cache.remove(1, "xxx")).isFalse(); changesOf(0, 1, 0, 0); // FIXME The cache counts a hit here expect(cache.remove(1, "a")).isTrue(); changesOf(1, 0, 0, 1); }
@Test public void getRemovals() { cache.put(1L, "a"); cache.remove(1L); assertThat(onHeap.getRemovals()).isEqualTo(0L); assertNoStat("OnHeap:RemovalCount"); }
@Test public void testSimpleRemove2Args() throws Exception { Cache<Number, CharSequence> testCache = cacheManager.createCache("testCache", newCacheConfigurationBuilder(Number.class, CharSequence.class, heap(10))); testCache.put(1, "one"); assertThat(testCache.remove(1, "one_"), is(false)); assertThat(testCache.get(1), is(notNullValue())); assertThat(testCache.remove(1, "one"), is(true)); assertThat(testCache.get(1), is(nullValue())); }
@Test public void testSimplePutWithExpiry_remove2Args() throws Exception { insert(testCache, getEntries()); assertThat(cacheSize(testCache), is(2)); manualTimeSource.setTimeMillis(1001); assertThat(testCache.remove(1, "one"), is(false)); assertThat(testCache.get(1), is(nullValue())); assertThat(testCache.remove(2, "two"), is(false)); assertThat(testCache.get(2), is(nullValue())); }
@SuppressWarnings("unchecked") @Exposed public void remove(@Named("key") Object key) { Object convertedKey = convert(key, cacheBinding.getCache().getRuntimeConfiguration().getKeyType()); cacheBinding.getCache().remove(convertedKey); }
@Test public void testSimpleRemove() throws Exception { Cache<Number, CharSequence> testCache = cacheManager.createCache("testCache", newCacheConfigurationBuilder(Number.class, CharSequence.class, heap(10))); testCache.put(1, "one"); testCache.put(2, "two"); testCache.remove(1); assertThat(testCache.get(1), is(nullValue())); assertThat(testCache.get(2), is(notNullValue())); }