/** * 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 containsKeyFailure() throws Exception { assertThat(strategy.containsKeyFailure(1, accessException)).isFalse(); verify(store).obliterate(1); verifyZeroInteractions(loaderWriter); }
@Test public void containsKeyFailure() throws StoreAccessException { assertThat(strategy.containsKeyFailure(1, accessException)).isFalse(); verify(store).obliterate(1); }
@Test public void removeFailure() throws StoreAccessException { assertThat(strategy.removeFailure(1, 1L, accessException)).isFalse(); verify(store).obliterate(1); }
@Test public void removeAllFailure() throws StoreAccessException { strategy.removeAllFailure(asList(1, 2), 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 getAllFailure_allFound() throws Exception { List<Integer> keys = Arrays.asList(1, 2); Map<Integer, Long> entries = keys.stream().collect(toMap(identity(), k -> (long) k)); when(loaderWriter.loadAll(keys)).thenReturn(entries); assertThat(strategy.getAllFailure(keys, accessException)).isEqualTo(entries); @SuppressWarnings("unchecked") ArgumentCaptor<Iterable<Integer>> captor = ArgumentCaptor.forClass(Iterable.class); verify(store).obliterate(captor.capture()); assertThat(captor.getValue()).contains(1, 2); verify(loaderWriter).loadAll(keys); }
@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 removeAllFailure() throws Exception { List<Integer> entryList = Arrays.asList(1, 2); strategy.removeAllFailure(entryList, accessException); @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 putFailure() throws StoreAccessException { strategy.putFailure(1, 1L, accessException); verify(store).obliterate(1); }
@Test public void getFailure() throws Exception { when(loaderWriter.load(1)).thenReturn(1L); assertThat(strategy.getFailure(1, accessException)).isEqualTo(1L); verify(store).obliterate(1); verify(loaderWriter).load(1); }
@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 removeFailure1_foundNotEquals() throws Exception { when(loaderWriter.load(1)).thenReturn(2L); assertThat(strategy.removeFailure(1, 1L, accessException)).isFalse(); verify(store).obliterate(1); verify(loaderWriter).load(1); }
@Test public void replaceFailure1_foundNotEquals() throws Exception { when(loaderWriter.load(1)).thenReturn(3L); assertThat(strategy.replaceFailure(1, 1L, 2L, accessException)).isFalse(); 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); }