@Override public CompletableFuture<Void> deleteAllAsync(List<K> keys) { Preconditions.checkNotNull(writeFn, "null writeFn"); return writeFn.deleteAllAsync(keys); }
/** * Delete all {@code records} with the specified {@code keys} from the remote store * The default implementation calls deleteAllAsync and blocks on the completion afterwards. * @param keys keys for the table records to be written */ default void deleteAll(Collection<K> keys) { try { deleteAllAsync(keys).get(); } catch (InterruptedException | ExecutionException e) { throw new SamzaException("DELETE failed for " + keys, e); } }
/** * Delete all {@code records} with the specified {@code keys} from the remote store * The default implementation calls deleteAllAsync and blocks on the completion afterwards. * @param keys keys for the table records to be written */ default void deleteAll(Collection<K> keys) { try { deleteAllAsync(keys).get(); } catch (InterruptedException | ExecutionException e) { throw new SamzaException("DELETE failed for " + keys, e); } }
/** * Delete all {@code records} with the specified {@code keys} from the remote store * The default implementation calls deleteAllAsync and blocks on the completion afterwards. * @param keys keys for the table records to be written */ default void deleteAll(Collection<K> keys) { try { deleteAllAsync(keys).get(); } catch (InterruptedException | ExecutionException e) { throw new SamzaException("DELETE failed for " + keys, e); } }
/** * Delete all {@code records} with the specified {@code keys} from the remote store * The default implementation calls deleteAllAsync and blocks on the completion afterwards. * @param keys keys for the table records to be written */ default void deleteAll(Collection<K> keys) { try { deleteAllAsync(keys).get(); } catch (InterruptedException | ExecutionException e) { throw new SamzaException("DELETE failed for " + keys, e); } }
/** * Delete all {@code records} with the specified {@code keys} from the remote store * The default implementation calls deleteAllAsync and blocks on the completion afterwards. * @param keys keys for the table records to be written */ default void deleteAll(Collection<K> keys) { try { deleteAllAsync(keys).get(); } catch (InterruptedException | ExecutionException e) { throw new SamzaException("DELETE failed for " + keys, e); } }
@Override public CompletableFuture<Void> deleteAllAsync(Collection<K> keys) { return failsafe(retryPolicy, retryMetrics, retryExecutor) .future(() -> writeFn.deleteAllAsync(keys)) .exceptionally(e -> { throw new SamzaException("Failed to delete the records for " + keys + " after retries.", e); }); }
@Override public CompletableFuture<Void> deleteAllAsync(Collection<K> keys) { return failsafe(retryPolicy, retryMetrics, retryExecutor) .future(() -> writeFn.deleteAllAsync(keys)) .exceptionally(e -> { throw new SamzaException("Failed to delete the records for " + keys + " after retries.", e); }); }
@Override public CompletableFuture<Void> deleteAllAsync(Collection<K> keys) { return failsafe(retryPolicy, retryMetrics, retryExecutor) .future(() -> writeFn.deleteAllAsync(keys)) .exceptionally(e -> { throw new SamzaException("Failed to delete the records for " + keys + " after retries.", e); }); }
@Override public CompletableFuture<Void> deleteAllAsync(Collection<K> keys) { return failsafe(retryPolicy, retryMetrics, retryExecutor) .future(() -> writeFn.deleteAllAsync(keys)) .exceptionally(e -> { throw new SamzaException("Failed to delete the records for " + keys + " after retries.", e); }); }
@Override public CompletableFuture<Void> deleteAllAsync(Collection<K> keys) { return failsafe(retryPolicy, retryMetrics, retryExecutor) .future(() -> writeFn.deleteAllAsync(keys)) .exceptionally(e -> { throw new SamzaException("Failed to delete the records for " + keys + " after retries.", e); }); }
@Test public void testDeleteAllAsync() { verifyFailure(() -> roTable.deleteAllAsync(Arrays.asList(1))); rwTable.deleteAllAsync(Arrays.asList(1, 2)); verify(writeFn, times(1)).deleteAllAsync(any()); }
public void doTestDeleteAll(boolean sync, boolean error) throws Exception { TableWriteFunction<String, String> writeFn = mock(TableWriteFunction.class); RemoteTable<String, String> table = getTable("testDeleteAll-" + sync + error, mock(TableReadFunction.class), writeFn, false); CompletableFuture<Void> future; if (error) { future = new CompletableFuture(); future.completeExceptionally(new RuntimeException("Test exception")); } else { future = CompletableFuture.completedFuture(null); } // Sync is backed by async so needs to mock the async method doReturn(future).when(writeFn).deleteAllAsync(any()); List<String> keys = Arrays.asList("foo1", "foo2"); ArgumentCaptor<List> argCaptor = ArgumentCaptor.forClass(List.class); if (sync) { table.deleteAll(keys); } else { table.deleteAllAsync(keys).get(); } verify(writeFn, times(1)).deleteAllAsync(argCaptor.capture()); Assert.assertEquals(keys, argCaptor.getValue()); verify(table.writeRateLimiter, times(1)).throttle(anyCollection()); }
@Test public void testRetryExhaustedAttemptsPut() throws Exception { String tableId = "testRetryExhaustedAttemptsPut"; TableRetryPolicy policy = new TableRetryPolicy(); policy.withFixedBackoff(Duration.ofMillis(5)); policy.withStopAfterAttempts(10); TableWriteFunction<String, String> writeFn = mock(TableWriteFunction.class); doReturn(true).when(writeFn).isRetriable(any()); CompletableFuture<String> future = new CompletableFuture(); future.completeExceptionally(new RuntimeException("test exception")); doReturn(future).when(writeFn).deleteAllAsync(any()); RetriableWriteFunction<String, String> retryIO = new RetriableWriteFunction<>(policy, writeFn, schedExec); retryIO.setMetrics(getMetricsUtil(tableId)); try { retryIO.deleteAllAsync(Arrays.asList("foo1", "foo2")).get(); Assert.fail(); } catch (ExecutionException e) { } // 1 initial try + 10 retries verify(writeFn, times(11)).deleteAllAsync(any()); Assert.assertEquals(10, retryIO.retryMetrics.retryCount.getCount()); Assert.assertEquals(0, retryIO.retryMetrics.successCount.getCount()); Assert.assertTrue(retryIO.retryMetrics.retryTimer.getSnapshot().getMax() > 0); }
doReturn(future).when(writeFn).deleteAllAsync(any()); if (hasDelete) { ArgumentCaptor<List> delArgCaptor = ArgumentCaptor.forClass(List.class); verify(writeFn, times(1)).deleteAllAsync(delArgCaptor.capture()); Assert.assertEquals(Arrays.asList("foo2"), delArgCaptor.getValue()); Assert.assertEquals(1, argCaptor.getValue().size());
doReturn(CompletableFuture.completedFuture(null)).when(writeFn).putAllAsync(any()); doReturn(CompletableFuture.completedFuture(null)).when(writeFn).deleteAsync(any()); doReturn(CompletableFuture.completedFuture(null)).when(writeFn).deleteAllAsync(any()); AsyncReadWriteTable delegate = new AsyncRemoteTable(readFn, writeFn); AsyncRateLimitedTable table = new AsyncRateLimitedTable("t1", delegate, verify(writeFn, times(1)).deleteAllAsync(any()); verify(writeRateLimiter, times(1)).throttle(anyString(), anyString()); verify(writeRateLimiter, times(1)).throttleRecords(anyList());
doReturn(CompletableFuture.completedFuture(null)).when(writeFn).putAllAsync(any()); doReturn(CompletableFuture.completedFuture(null)).when(writeFn).deleteAsync(any()); doReturn(CompletableFuture.completedFuture(null)).when(writeFn).deleteAllAsync(any()); AsyncReadWriteTable delegate = new AsyncRemoteTable(readFn, writeFn); AsyncRetriableTable table = new AsyncRetriableTable("t1", delegate, null, policy, schedExec, readFn, writeFn); assertEquals(++times, table.writeRetryMetrics.successCount.getCount()); table.deleteAllAsync(Arrays.asList("1", "2")).get(); verify(writeFn, times(1)).deleteAllAsync(any()); assertEquals(++times, table.writeRetryMetrics.successCount.getCount()); assertEquals(0, table.writeRetryMetrics.retryCount.getCount());
doReturn(CompletableFuture.completedFuture(null)).when(writeFn).deleteAllAsync(any()); entries = new ArrayList<>(); entries.add(new Entry<>("foo1", "bar111")); doReturn(CompletableFuture.completedFuture(null)).when(writeFn).deleteAllAsync(any()); cachingTable.deleteAllAsync(Arrays.asList("foo1", "foo3")).get();