Skip to content

Commit

Permalink
Delete the objects and buckets created by test
Browse files Browse the repository at this point in the history
It was trying to delete all the buckets and their objects
for the setup used in testing.

Signed-off-by: Shubhendu Ram Tripathi <shubhendu@minio.io>
  • Loading branch information
shtripat committed May 23, 2024
1 parent 105c01a commit 4f8714f
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
Expand All @@ -55,6 +56,8 @@ public class FunctionalTests {
private static String endpoint;
private static boolean enableHTTPS;

private static final List<String> bucketsList = new ArrayList<>();

private static final Random random = new Random(new SecureRandom().nextLong());
private static final String bucketName = getRandomName();
private static boolean mintEnv = false;
Expand Down Expand Up @@ -112,6 +115,7 @@ public static void initTests() throws IOException {
.builder()
.bucket(bucketName)
.build());
bucketsList.add(bucketName);
}

// Run tests
Expand Down Expand Up @@ -145,6 +149,7 @@ public static void createBucket_test() throws Exception {
.builder()
.bucket(bucket)
.build());
bucketsList.add(bucket);
mintSuccessLog("S3Client.createBucket", "bucket: " + bucket, startTime);
} catch (Exception ex) {
mintFailedLog(
Expand Down Expand Up @@ -184,6 +189,7 @@ public static void createBucketWithVersion_test() throws Exception {
.status(BucketVersioningStatus.ENABLED)
.build())
.build());
bucketsList.add(bucket);
mintSuccessLog("S3Client.putBucketVersioning", "bucket: " + bucket, startTime);
} catch (Exception ex) {
mintFailedLog(
Expand Down Expand Up @@ -313,6 +319,9 @@ public static void uploadObjectVersions_test() throws Exception {
s3TestUtils.uploadObject(bucketName, objectName, file1Kb);
s3TestUtils.uploadObject(bucketName, objectName, file1Kb);
s3TestUtils.downloadObject(bucketName, objectName, "");

bucketsList.add(bucket);

mintSuccessLog("S3Client.putObject versions",
"bucket: " + bucket + ", object: " + objectName,
startTime);
Expand Down Expand Up @@ -352,6 +361,9 @@ public static void crtClientDownload_test() throws Exception {
s3CrtAsyncClient.getObject(
r -> r.bucket(bucket).key(objectName), Path.of("/tmp/test")
).join();

bucketsList.add(bucket);

mintSuccessLog("Async S3CrtClient.getObject versions",
"bucket: " + bucket + ", object: " + objectName,
startTime);
Expand All @@ -366,31 +378,27 @@ public static void crtClientDownload_test() throws Exception {
}

public static void teardown() throws IOException {
ListBucketsResponse response = s3Client.listBuckets(ListBucketsRequest
.builder()
.build());
List<Bucket> buckets = response.buckets();
for (Bucket bucket : buckets) {
for (String bkt : bucketsList) {
// Remove all objects under the test bucket & the bucket itself
ListObjectsV2Request request = ListObjectsV2Request
.builder()
.bucket(bucket.name())
.bucket(bkt)
.build();
ListObjectsV2Response listObjectsResponse;
do {
listObjectsResponse = s3Client.listObjectsV2(request);
for (S3Object obj : listObjectsResponse.contents()) {
s3Client.deleteObject(DeleteObjectRequest
.builder()
.bucket(bucket.name())
.bucket(bkt)
.key(obj.key())
.build());
}
} while (listObjectsResponse.isTruncated());
// finally remove the bucket
s3Client.deleteBucket(DeleteBucketRequest
.builder()
.bucket(bucket.name())
.bucket(bkt)
.build());
}
}
Expand Down

0 comments on commit 4f8714f

Please # to comment.