Search in sources :

Example 11 with ListPartsRequest

use of com.aliyun.oss.model.ListPartsRequest in project aliyun-oss-java-sdk by aliyun.

the class UploadPartTest method testUnormalListParts.

@Test
public void testUnormalListParts() {
    final String key = "unormal-list-parts-object";
    // Try to list parts with non-existent part id
    final String nonexistentUploadId = "nonexistent-upload-id";
    try {
        ListPartsRequest listPartsRequest = new ListPartsRequest(bucketName, key, nonexistentUploadId);
        ossClient.listParts(listPartsRequest);
        Assert.fail("List parts should not be successful");
    } catch (OSSException e) {
        Assert.assertEquals(OSSErrorCode.NO_SUCH_UPLOAD, e.getErrorCode());
        Assert.assertTrue(e.getMessage().startsWith(NO_SUCH_UPLOAD_ERR));
    }
    // Try to list LIST_PART_MAX_RETURNS + 1 parts each time
    String uploadId = null;
    try {
        uploadId = claimUploadId(ossClient, bucketName, key);
        ListPartsRequest listPartsRequest = new ListPartsRequest(bucketName, key, uploadId);
        listPartsRequest.setMaxParts(LIST_PART_MAX_RETURNS + 1);
        ossClient.listParts(listPartsRequest);
        Assert.fail("List parts should not be successful");
    } catch (Exception e) {
        Assert.assertTrue(e instanceof IllegalArgumentException);
        AbortMultipartUploadRequest abortMultipartUploadRequest = new AbortMultipartUploadRequest(bucketName, key, uploadId);
        ossClient.abortMultipartUpload(abortMultipartUploadRequest);
    }
}
Also used : ListPartsRequest(com.aliyun.oss.model.ListPartsRequest) OSSException(com.aliyun.oss.OSSException) AbortMultipartUploadRequest(com.aliyun.oss.model.AbortMultipartUploadRequest) OSSException(com.aliyun.oss.OSSException) Test(org.junit.Test)

Example 12 with ListPartsRequest

use of com.aliyun.oss.model.ListPartsRequest in project aliyun-oss-java-sdk by aliyun.

the class OSSClientRequestTest method testListPartsRequest.

@Test
public void testListPartsRequest() {
    String uploadId = "upload123";
    final ListPartsRequest request = new ListPartsRequest(bucketName, objectKey, uploadId);
    String expectedUrl = objectKey + "?uploadId=" + uploadId;
    TestAction test1 = new TestAction() {

        public void run() throws Exception {
            multipartOp.listParts(request);
        }
    };
    executeTest(test1, HttpMethod.GET, bucketName + "." + endpoint.getHost(), expectedUrl, null);
    request.setMaxParts(100);
    request.setPartNumberMarker(50);
    expectedUrl += "&max-parts=" + request.getMaxParts().toString() + "&part-number-marker=" + request.getPartNumberMarker().toString();
    executeTest(test1, HttpMethod.GET, bucketName + "." + endpoint.getHost(), expectedUrl, null);
}
Also used : ListPartsRequest(com.aliyun.oss.model.ListPartsRequest) Test(org.junit.Test)

Aggregations

ListPartsRequest (com.aliyun.oss.model.ListPartsRequest)12 Test (org.junit.Test)11 OSSException (com.aliyun.oss.OSSException)10 PartListing (com.aliyun.oss.model.PartListing)10 TestUtils.genFixedLengthInputStream (com.aliyun.oss.integrationtests.TestUtils.genFixedLengthInputStream)9 CompleteMultipartUploadRequest (com.aliyun.oss.model.CompleteMultipartUploadRequest)9 PartETag (com.aliyun.oss.model.PartETag)9 InputStream (java.io.InputStream)9 ArrayList (java.util.ArrayList)9 CompleteMultipartUploadResult (com.aliyun.oss.model.CompleteMultipartUploadResult)7 OSSObject (com.aliyun.oss.model.OSSObject)7 UploadPartCopyRequest (com.aliyun.oss.model.UploadPartCopyRequest)5 UploadPartCopyResult (com.aliyun.oss.model.UploadPartCopyResult)5 PartSummary (com.aliyun.oss.model.PartSummary)4 UploadPartRequest (com.aliyun.oss.model.UploadPartRequest)4 UploadPartResult (com.aliyun.oss.model.UploadPartResult)4 PutObjectResult (com.aliyun.oss.model.PutObjectResult)3 FileInputStream (java.io.FileInputStream)3 AbortMultipartUploadRequest (com.aliyun.oss.model.AbortMultipartUploadRequest)2 OSSClient (com.aliyun.oss.OSSClient)1