Skip to content

Commit

Permalink
Add S3 list-parts UTs
Browse files Browse the repository at this point in the history
### What changes are proposed in this pull request?

add S3 list-parts UTs.

### Why are the changes needed?

test for s3 list parts

### Does this PR introduce any user facing changes?

none

			pr-link: #18048
			change-id: cid-89e5c55284c4b0e7bf081ff6bb7d76c356149629
  • Loading branch information
007DXR authored Aug 23, 2023
1 parent 7505ea4 commit 54121a7
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,7 @@ public Response continueTask() {
try {
List<URIStatus> children = mHandler.getMetaFS().listStatus(new AlluxioURI(
S3RestUtils.MULTIPART_UPLOADS_METADATA_DIR));
final List<URIStatus> uploadIds = children.stream()
.filter((uri) -> uri.getOwner().equals(user))
.collect(Collectors.toList());
return ListMultipartUploadsResult.buildFromStatuses(bucket, uploadIds);
return ListMultipartUploadsResult.buildFromStatuses(bucket, children);
} catch (Exception e) {
throw S3RestUtils.toBucketS3Exception(e, bucket, auditContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import alluxio.proxy.s3.CompleteMultipartUploadRequest.Part;
import alluxio.proxy.s3.CompleteMultipartUploadResult;
import alluxio.proxy.s3.InitiateMultipartUploadResult;
import alluxio.proxy.s3.ListPartsResult;
import alluxio.proxy.s3.S3RestUtils;
import alluxio.s3.S3ErrorCode;
import alluxio.testutils.LocalAlluxioClusterResource;
Expand All @@ -32,6 +33,7 @@
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.google.common.collect.ImmutableMap;
import org.gaul.s3proxy.junit.S3ProxyRule;
import org.junit.After;
import org.junit.Assert;
Expand Down Expand Up @@ -106,7 +108,7 @@ public void after() {
}

/**
* Initiate a multipart upload.
* Create a bucket and initiate a multipart upload under path "bucket/object".
*
* @return the upload id
*/
Expand Down Expand Up @@ -415,6 +417,69 @@ public void abortMultipartUploadWithNonExistentUpload() throws Exception {
Assert.assertTrue(mFileSystem.exists(tmpDir));
}

/**
* List parts.
*
* @throws Exception
*/
@Test
public void listParts() throws Exception {
final int partsNum = 10;
final List<String> objects = new ArrayList<>();
final List<Integer> parts = new ArrayList<>();
final String uploadId = initiateMultipartUpload();
for (int i = 1; i <= partsNum; i++) {
parts.add(i);
objects.add(CommonUtils.randomAlphaNumString(Constants.KB));
}
Collections.shuffle(parts);
uploadParts(uploadId, objects, parts);

final ListPartsResult listPartsResult =
listTestCase(OBJECT_KEY, ImmutableMap.of("uploadId", uploadId))
.checkResponseCode(Status.OK.getStatusCode())
.getResponse(ListPartsResult.class);

Assert.assertEquals(AlluxioURI.SEPARATOR + BUCKET_NAME, listPartsResult.getBucket());
Assert.assertEquals(OBJECT_NAME, listPartsResult.getKey());
Assert.assertEquals(uploadId, listPartsResult.getUploadId());
Assert.assertEquals(partsNum, listPartsResult.getParts().size());
for (int i = 0; i < partsNum; i++) {
Assert.assertEquals(i + 1, listPartsResult.getParts().get(i).getPartNumber());
Assert.assertEquals(Constants.KB, listPartsResult.getParts().get(i).getSize());
}
}

/**
* List parts with non-existent upload id.
*
* @throws Exception
*/
@Test
public void listPartsWithNonExistentUpload() throws Exception {
final String uploadId = initiateMultipartUpload();
listTestCase(OBJECT_KEY, ImmutableMap.of("uploadId", "wrong"))
.checkResponseCode(Status.NOT_FOUND.getStatusCode())
.checkErrorCode(S3ErrorCode.Name.NO_SUCH_UPLOAD);
listTestCase(OBJECT_KEY + AlluxioURI.SEPARATOR, ImmutableMap.of("uploadId", uploadId))
.checkResponseCode(Status.NOT_FOUND.getStatusCode())
.checkErrorCode(S3ErrorCode.Name.NO_SUCH_UPLOAD);
}

/**
* List parts with non-existent bucket.
*
* @throws Exception
*/
@Test
public void listPartsWithNonExistentBucket() throws Exception {
final String uploadId = initiateMultipartUpload();
String objectKey = "wrong" + AlluxioURI.SEPARATOR + OBJECT_NAME;
listTestCase(objectKey, ImmutableMap.of("uploadId", uploadId))
.checkResponseCode(Status.NOT_FOUND.getStatusCode())
.checkErrorCode(S3ErrorCode.Name.NO_SUCH_BUCKET);
}

/**
* Get default options with username {@code [email protected]}.
*
Expand Down

0 comments on commit 54121a7

Please sign in to comment.