Skip to content

Commit 73ead4c

Browse files
committed
add MPU scenario for bucket deletion improvement test
1 parent 47d0120 commit 73ead4c

File tree

1 file changed

+54
-4
lines changed

1 file changed

+54
-4
lines changed

src/test/java/com/emc/object/s3/S3JerseyClientTest.java

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@ public void testDeleteBucketWithBackgroundTasks() throws Exception {
517517
Assert.assertEquals("EmptyBucketStatus should not be found", "NOT_FOUND", statusNotBeingDeleted.getStatus());
518518
client.deleteBucket(new DeleteBucketRequest(bucketNameNotBeingDeleted, true));
519519

520-
// delete a bucket which is empty or not, the first status should always be PENDING.
521520
client.deleteBucket(new DeleteBucketRequest(bucketName, true));
522521
BucketDeletionStatus status = client.getBucketDeletionStatus(bucketName);
523522
// check the status and dates of the bucket delete task, other entries are not given.
@@ -539,7 +538,7 @@ public void testDeleteBucketWithBackgroundTasks() throws Exception {
539538
Assert.assertEquals("EmptyBucketInProgress", e.getErrorCode());
540539
}
541540

542-
// Empty bucket execution frequency is 1 min, so 3 min wait would be enough.
541+
// Empty bucket execution frequency is 1 min, so 3 min wait would be enough for this test to finish.
543542
Thread.sleep(3 * 60 * 1000);
544543

545544
try {
@@ -549,7 +548,58 @@ public void testDeleteBucketWithBackgroundTasks() throws Exception {
549548
Assert.assertEquals(404, e.getHttpCode());
550549
Assert.assertEquals("The specified bucket does not exist", e.getMessage());
551550
}
551+
Assert.assertFalse("Failed to delete bucket" + bucketName, client.bucketExists(bucketName));
552+
}
553+
554+
@Test
555+
public void testDeleteBucketWithMPUWithBackgroundTasks() throws Exception {
556+
Assume.assumeTrue("ECS version must be at least 3.8", ecsVersion != null && ecsVersion.compareTo("3.8") >= 0);
552557

558+
String bucketName = getTestBucket() + "-mpu";
559+
client.createBucket(bucketName);
560+
561+
String key = "mpu-abort-test";
562+
int partSize = 2 * 1024 * 1024;
563+
byte[] data = new byte[9 * 1024 * 1024];
564+
new Random().nextBytes(data);
565+
// init MPU
566+
String uploadId = client.initiateMultipartUpload(bucketName, key);
567+
// upload parts in background threads
568+
ExecutorService service = Executors.newFixedThreadPool(5);
569+
List<Future> futures = new ArrayList<Future>();
570+
int partNum = 1;
571+
for (int offset = 0; offset < data.length; offset += partSize) {
572+
int length = data.length - offset;
573+
if (length > partSize) length = partSize;
574+
final UploadPartRequest request = new UploadPartRequest(bucketName, key, uploadId, partNum++,
575+
Arrays.copyOfRange(data, offset, offset + length));
576+
futures.add(service.submit(() -> {
577+
client.uploadPart(request);
578+
}));
579+
}
580+
// abort while threads are uploading
581+
client.abortMultipartUpload(new AbortMultipartUploadRequest(bucketName, key, uploadId));
582+
583+
// start bucket deletion tasks
584+
client.deleteBucket(new DeleteBucketRequest(bucketName, true));
585+
586+
// let MPU threads finish
587+
futures.forEach(future -> {
588+
try {
589+
future.get();
590+
} catch (Exception ignored) {
591+
}
592+
});
593+
594+
// Empty bucket execution frequency is 1 min, so 3 min wait would be enough for this test to finish.
595+
Thread.sleep(3 * 60 * 1000);
596+
try {
597+
client.getBucketDeletionStatus(bucketName);
598+
Assert.fail("GET EmptyBucketStatus when the bucket is deleted should give 404.");
599+
} catch (S3Exception e) {
600+
Assert.assertEquals(404, e.getHttpCode());
601+
Assert.assertEquals("The specified bucket does not exist", e.getMessage());
602+
}
553603
Assert.assertFalse("Failed to delete bucket" + bucketName, client.bucketExists(bucketName));
554604
}
555605

@@ -577,8 +627,8 @@ public void testDeleteBucketInRetentionWithBackgroundTasks() throws Exception {
577627
client.putObject(bucketName, "foo", "bar", null);
578628

579629
client.deleteBucket(new DeleteBucketRequest(bucketName, true));
580-
// Empty bucket execution frequency is 1 min, so 3 min wait would be enough.
581-
Thread.sleep(3 * 60 * 1000);
630+
// Empty bucket execution frequency is 1 min, so 2 min wait would be enough for this test to go "FAILED".
631+
Thread.sleep(2 * 60 * 1000);
582632

583633
BucketDeletionStatus status = client.getBucketDeletionStatus(bucketName);
584634
// check the fields of the bucket deletion status

0 commit comments

Comments
 (0)