try {
// Can delete non-existent objects
String[] keys = new String[] {
"non-existent-1", "non-existent-2", "non-existent-3", "non-existent-4"};
MultipleDeleteResult result = s3Service.deleteMultipleObjects(bucketName, keys);
assertFalse(result.hasErrors());
assertEquals(0, result.getErrorResults().size());
assertEquals(4, result.getDeletedObjectResults().size());
// Delete existing objects
keys = new String[] {
"existent-1", "existent-2", "existent-3", "existent-4"};
for (String key: keys) {
s3Service.putObject(bucketName, new S3Object(key, "Some data"));
}
result = s3Service.deleteMultipleObjects(bucketName, keys);
assertFalse(result.hasErrors());
assertEquals(4, result.getDeletedObjectResults().size());
for (String key: keys) {
assertFalse(s3Service.isObjectInBucket(bucketName, key));
}
// Quiet mode does not list deleted objects in result
ObjectKeyAndVersion[] keyAndVersions = new ObjectKeyAndVersion[keys.length];
int i = 0;
for (String key: keys) {
s3Service.putObject(bucketName, new S3Object(key, "Some data"));
keyAndVersions[i++] = new ObjectKeyAndVersion(key);
}
result = s3Service.deleteMultipleObjects(bucketName, keyAndVersions, true);
assertFalse(result.hasErrors());
assertEquals(0, result.getDeletedObjectResults().size());
for (String key: keys) {
assertFalse(s3Service.isObjectInBucket(bucketName, key));
}
} finally {