/**
* Cleaning of bucket after test run.
*/
public void deleteBucket() throws Exception {
Properties props = Utils.readConfig(config);
AmazonS3Client s3service = Utils.openService(props);
Backend backend = ds.getBackend();
String bucket = ((S3Backend)backend).getBucket();
LOG.info("delete bucket [" + bucket + "]");
TransferManager tmx = new TransferManager(s3service);
if (s3service.doesBucketExist(bucket)) {
for (int i = 0; i < 3; i++) {
tmx.abortMultipartUploads(bucket, startTime);
ObjectListing prevObjectListing = s3service.listObjects(bucket);
while (prevObjectListing != null ) {
List<DeleteObjectsRequest.KeyVersion> deleteList = new ArrayList<DeleteObjectsRequest.KeyVersion>();
for (S3ObjectSummary s3ObjSumm : prevObjectListing.getObjectSummaries()) {
deleteList.add(new DeleteObjectsRequest.KeyVersion(s3ObjSumm.getKey()));
}
if (deleteList.size() > 0) {
DeleteObjectsRequest delObjsReq = new DeleteObjectsRequest(bucket);
delObjsReq.setKeys(deleteList);
s3service.deleteObjects(delObjsReq);
}
if (!prevObjectListing.isTruncated()) break;
prevObjectListing = s3service.listNextBatchOfObjects(prevObjectListing);
}
}
s3service.deleteBucket(bucket);
LOG.info("bucket: " + bucket + " deleted");
tmx.shutdownNow();
s3service.shutdown();
}
}