/** * Obliterate a list of keys. * * @param keys keys to obliterate * @throws StoreAccessException in case of store failure */ default void obliterate(Iterable<? extends K> keys) throws StoreAccessException { for (K key : keys) { obliterate(key); } }
@Test public void putAllFailure() throws StoreAccessException { strategy.putAllFailure(of(1, 2).collect(toMap(identity(), k -> (long) k)), accessException); @SuppressWarnings("unchecked") ArgumentCaptor<Iterable<Integer>> captor = ArgumentCaptor.forClass(Iterable.class); verify(store).obliterate(captor.capture()); assertThat(captor.getValue()).contains(1, 2); }
@Test public void removeFailure1() throws StoreAccessException { assertThat(strategy.removeFailure(1, 1L, accessException)).isFalse(); verify(store).obliterate(1); }
@Test public void replaceFailure1() throws StoreAccessException { assertThat(strategy.replaceFailure(1, 1L, 2L, accessException)).isFalse(); verify(store).obliterate(1); }
@Test public void replaceFailure1_notFound() throws Exception { assertThat(strategy.replaceFailure(1, 1L, 2L, accessException)).isFalse(); verify(store).obliterate(1); verify(loaderWriter).load(1); }
@Test public void clearFailure() throws StoreAccessException { strategy.clearFailure(accessException); verify(store).obliterate(); }
@Test public void clearFailure() throws Exception { strategy.clearFailure(accessException); verify(store).obliterate(); }
@Test public void putIfAbsentFailure_found() throws Exception { when(loaderWriter.load(1)).thenReturn(1L); assertThat(strategy.putIfAbsentFailure(1, 2L, accessException)).isEqualTo(1); verify(store).obliterate(1); verify(loaderWriter).load(1); }
@Test public void removeAllFailure_deleteAllFailsWithBulkException() throws Exception { List<Integer> entryList = Arrays.asList(1, 2); doThrow(bulkWritingException).when(loaderWriter).deleteAll(entryList); assertThatThrownBy(() -> strategy.removeAllFailure(entryList, accessException)) .isSameAs(bulkWritingException); @SuppressWarnings("unchecked") ArgumentCaptor<Iterable<Integer>> captor = ArgumentCaptor.forClass(Iterable.class); verify(store).obliterate(captor.capture()); assertThat(captor.getValue()).contains(1, 2); verify(loaderWriter).deleteAll(entryList); }
@Test public void replaceFailure1_foundEquals() throws Exception { when(loaderWriter.load(1)).thenReturn(1L); assertThat(strategy.replaceFailure(1, 1L, 2L, accessException)).isTrue(); verify(store).obliterate(1); verify(loaderWriter).load(1); verify(loaderWriter).write(1, 2L); }
@Test public void getFailure() throws StoreAccessException { assertThat(strategy.getFailure(1, accessException)).isNull(); verify(store).obliterate(1); }
@Test public void replaceFailure() throws StoreAccessException { assertThat(strategy.replaceFailure(1, 1L, accessException)).isNull(); verify(store).obliterate(1); }
@Test public void removeFailure() throws Exception { strategy.removeFailure(1, accessException); verify(store).obliterate(1); verify(loaderWriter).delete(1); }
@Test public void getAllFailure() throws StoreAccessException { assertThat(strategy.getAllFailure(asList(1, 2), accessException)).containsExactly(entry(1, null), entry(2, null)); @SuppressWarnings("unchecked") ArgumentCaptor<Iterable<Integer>> captor = ArgumentCaptor.forClass(Iterable.class); verify(store).obliterate(captor.capture()); assertThat(captor.getValue()).contains(1, 2); }
@Test public void getFailure_failedLoaderWriter() throws Exception { when(loaderWriter.load(1)).thenThrow(exception); assertThatThrownBy(() -> strategy.getFailure(1, accessException)) .isExactlyInstanceOf(CacheLoadingException.class) .hasCause(exception); verify(store).obliterate(1); verify(loaderWriter).load(1); }
@Test public void removeFailure1_deleteFails() throws Exception { when(loaderWriter.load(1)).thenReturn(1L); doThrow(exception).when(loaderWriter).delete(1); assertThatThrownBy(() -> strategy.removeFailure(1, 1L, accessException)) .isExactlyInstanceOf(CacheWritingException.class) .hasCause(exception); verify(store).obliterate(1); verify(loaderWriter).load(1); verify(loaderWriter).delete(1); }
@Test public void replaceFailure_writeFails() throws Exception { when(loaderWriter.load(1)).thenReturn(2L); doThrow(exception).when(loaderWriter).write(1, 1L); assertThatThrownBy(() -> strategy.replaceFailure(1, 1L, accessException)) .isExactlyInstanceOf(CacheWritingException.class) .hasCause(exception); verify(store).obliterate(1); verify(loaderWriter).load(1); verify(loaderWriter).write(1, 1L); }
@Test public void putFailure_failedLoaderWriter() throws Exception { doThrow(exception).when(loaderWriter).write(1, 1L); assertThatThrownBy(() -> strategy.putFailure(1, 1L, accessException)) .isExactlyInstanceOf(CacheWritingException.class) .hasCause(exception); verify(store).obliterate(1); verify(loaderWriter).write(1, 1L); }
@Test public void removeFailure_failedLoaderWriter() throws Exception { doThrow(exception).when(loaderWriter).delete(1); assertThatThrownBy(() -> strategy.removeFailure(1, accessException)) .isExactlyInstanceOf(CacheWritingException.class) .hasCause(exception); verify(store).obliterate(1); verify(loaderWriter).delete(1); }
@Test public void replaceFailure_loadFails() throws Exception { when(loaderWriter.load(1)).thenThrow(exception); assertThatThrownBy(() -> strategy.replaceFailure(1, 1L, accessException)) .isExactlyInstanceOf(CacheLoadingException.class) .hasCause(exception); verify(store).obliterate(1); verify(loaderWriter).load(1); }