Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete the objects and buckets created by test #384

Merged
merged 1 commit into from
May 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading