I need to be able to record items that has not been deleted in batch delete operation. I can get a list of keys but I am not able to test the case when there is a fail. Setting incorrect DynamoDBHashKey doesn't work. The failures list is empty.

  public void deleteAll(List<Grant> grants) {

    if (grants.stream().anyMatch(g -> StringUtils.isEmpty(g.getHashedRefreshToken()))) {
      throw new RuntimeException("Grant's HashedRefreshToken is null");

    final List<FailedBatch> failedBatches = mapper.batchDelete(grants);

    List<Map<String, AttributeValue>> collect = failedBatches.stream()
        .map(b -> b.getUnprocessedItems())
        .flatMap(e -> e.values().stream())
        .flatMap(e -> e.stream())
        .map(e -> e.getDeleteRequest())
        .map(v -> v.getKey())
    // FIXME
    System.out.println("Failed items : " + collect.size());
    collect.forEach(e -> System.out.println(e));

0 Answers