public void deleteObjects(List<String> keysToDelete) throws IOException {
    if (CollectionUtils.isEmpty(keysToDelete)) {
      LOG.warn("Keys to delete is empty.");
      return;
    }

    int retry = 10;
    int tries = 0;
    while (CollectionUtils.isNotEmpty(keysToDelete)) {
      DeleteObjectsRequest deleteRequest = new DeleteObjectsRequest(bucketName);
      deleteRequest.setKeys(keysToDelete);
      // There are two modes to do batch delete:
      // 1. verbose mode: A list of all deleted objects is returned.
      // 2. quiet mode: No message body is returned.
      // Here, we choose the verbose mode to do batch delete.
      deleteRequest.setQuiet(false);
      DeleteObjectsResult result = ossClient.deleteObjects(deleteRequest);
      statistics.incrementWriteOps(1);
      final List<String> deletedObjects = result.getDeletedObjects();
      keysToDelete = keysToDelete.stream().filter(item -> !deletedObjects.contains(item))
          .collect(Collectors.toList());
      tries++;
      if (tries == retry) {
        break;
      }
    }

    if (tries == retry && CollectionUtils.isNotEmpty(keysToDelete)) {
      // Most of time, it is impossible to try 10 times, expect the
      // Aliyun OSS service problems.
      throw new IOException("Failed to delete Aliyun OSS objects for " + tries + " times.");
    }
  }
@Test
  public void testDeleteObjects() throws IOException, NoSuchAlgorithmException {
    // generate test files
    final int files = 10;
    final long size = 5 * 1024 * 1024;
    final String prefix = "dir";
    for (int i = 0; i < files; i++) {
      Path path = new Path(String.format("/%s/testFile-%d.txt", prefix, i));
      ContractTestUtils.generateTestFile(this.fs, path, size, 256, 255);
    }
    OSSListRequest listRequest =
        store.createListObjectsRequest(prefix, MAX_PAGING_KEYS_DEFAULT, null, null, true);
    List<String> keysToDelete = new ArrayList<>();
    OSSListResult objects = store.listObjects(listRequest);
    assertEquals(files, objects.getObjectSummaries().size());

    // test delete files
    for (OSSObjectSummary objectSummary : objects.getObjectSummaries()) {
      keysToDelete.add(objectSummary.getKey());
    }
    store.deleteObjects(keysToDelete);
    objects = store.listObjects(listRequest);
    assertEquals(0, objects.getObjectSummaries().size());
  }