|
39 | 39 | import java.util.ArrayList; |
40 | 40 | import java.util.List; |
41 | 41 |
|
| 42 | +import com.aliyun.oss.model.*; |
42 | 43 | import junit.framework.Assert; |
43 | 44 |
|
44 | 45 | import org.junit.Ignore; |
45 | 46 | import org.junit.Test; |
46 | 47 |
|
47 | 48 | import com.aliyun.oss.OSSErrorCode; |
48 | 49 | import com.aliyun.oss.OSSException; |
49 | | -import com.aliyun.oss.model.AbortMultipartUploadRequest; |
50 | | -import com.aliyun.oss.model.Bucket; |
51 | | -import com.aliyun.oss.model.CompleteMultipartUploadRequest; |
52 | | -import com.aliyun.oss.model.CompleteMultipartUploadResult; |
53 | | -import com.aliyun.oss.model.ListMultipartUploadsRequest; |
54 | | -import com.aliyun.oss.model.ListPartsRequest; |
55 | | -import com.aliyun.oss.model.MultipartUpload; |
56 | | -import com.aliyun.oss.model.MultipartUploadListing; |
57 | | -import com.aliyun.oss.model.OSSObject; |
58 | | -import com.aliyun.oss.model.PartETag; |
59 | | -import com.aliyun.oss.model.PartListing; |
60 | | -import com.aliyun.oss.model.PartSummary; |
61 | | -import com.aliyun.oss.model.UploadPartRequest; |
62 | | -import com.aliyun.oss.model.UploadPartResult; |
63 | 50 |
|
64 | 51 | public class UploadPartTest extends TestBase { |
65 | 52 |
|
@@ -1120,4 +1107,103 @@ public void testDeleteAllBuckets() { |
1120 | 1107 | } |
1121 | 1108 | } |
1122 | 1109 |
|
| 1110 | + @Test |
| 1111 | + public void testNormalUploadWithEmptyPart() { |
| 1112 | + final String key = "normal-upload-empty-part-object"; |
| 1113 | + final int partSize = 128 * 1024; //128KB |
| 1114 | + |
| 1115 | + try { |
| 1116 | + String uploadId = claimUploadId(ossClient, bucketName, key); |
| 1117 | + List<PartETag> partETags = new ArrayList(); |
| 1118 | + |
| 1119 | + // Complete multipart upload |
| 1120 | + CompleteMultipartUploadRequest completeMultipartUploadRequest = new CompleteMultipartUploadRequest(bucketName, key, uploadId, partETags); |
| 1121 | + CompleteMultipartUploadResult completeMultipartUploadResult = |
| 1122 | + ossClient.completeMultipartUpload(completeMultipartUploadRequest); |
| 1123 | + |
| 1124 | + } catch (Exception e) { |
| 1125 | + Assert.fail(e.getMessage()); |
| 1126 | + } |
| 1127 | + } |
| 1128 | + |
| 1129 | + @Test |
| 1130 | + public void testNormalUploadWithCompleteAllFlag() { |
| 1131 | + final String key1 = "normal-upload-empty-part-object-1"; |
| 1132 | + final String key2 = "normal-upload-empty-part-object-2"; |
| 1133 | + final int partSize1 = 128 * 1024; //128KB |
| 1134 | + final int partSize2 = 63 * 1024; //128KB |
| 1135 | + |
| 1136 | + try { |
| 1137 | + String uploadId = claimUploadId(ossClient, bucketName, key1); |
| 1138 | + |
| 1139 | + List<PartETag> partETags = new ArrayList<PartETag>(); |
| 1140 | + |
| 1141 | + // Upload part1 part |
| 1142 | + InputStream instream = genFixedLengthInputStream(partSize1); |
| 1143 | + UploadPartRequest uploadPartRequest = new UploadPartRequest(); |
| 1144 | + uploadPartRequest.setBucketName(bucketName); |
| 1145 | + uploadPartRequest.setKey(key1); |
| 1146 | + uploadPartRequest.setInputStream(instream); |
| 1147 | + uploadPartRequest.setPartNumber(1); |
| 1148 | + uploadPartRequest.setPartSize(partSize1); |
| 1149 | + uploadPartRequest.setUploadId(uploadId); |
| 1150 | + UploadPartResult uploadPartResult = ossClient.uploadPart(uploadPartRequest); |
| 1151 | + partETags.add(uploadPartResult.getPartETag()); |
| 1152 | + |
| 1153 | + // Upload part2 part |
| 1154 | + instream = genFixedLengthInputStream(partSize2); |
| 1155 | + uploadPartRequest = new UploadPartRequest(); |
| 1156 | + uploadPartRequest.setBucketName(bucketName); |
| 1157 | + uploadPartRequest.setKey(key1); |
| 1158 | + uploadPartRequest.setInputStream(instream); |
| 1159 | + uploadPartRequest.setPartNumber(2); |
| 1160 | + uploadPartRequest.setPartSize(partSize2); |
| 1161 | + uploadPartRequest.setUploadId(uploadId); |
| 1162 | + uploadPartResult = ossClient.uploadPart(uploadPartRequest); |
| 1163 | + partETags.add(uploadPartResult.getPartETag()); |
| 1164 | + |
| 1165 | + // Complete multipart upload |
| 1166 | + CompleteMultipartUploadRequest completeMultipartUploadRequest = new CompleteMultipartUploadRequest(bucketName, key1, uploadId, partETags); |
| 1167 | + CompleteMultipartUploadResult completeMultipartUploadResult1 = ossClient.completeMultipartUpload(completeMultipartUploadRequest); |
| 1168 | + |
| 1169 | + |
| 1170 | + uploadId = claimUploadId(ossClient, bucketName, key2); |
| 1171 | + instream = genFixedLengthInputStream(partSize1); |
| 1172 | + uploadPartRequest = new UploadPartRequest(); |
| 1173 | + uploadPartRequest.setBucketName(bucketName); |
| 1174 | + uploadPartRequest.setKey(key2); |
| 1175 | + uploadPartRequest.setInputStream(instream); |
| 1176 | + uploadPartRequest.setPartNumber(1); |
| 1177 | + uploadPartRequest.setPartSize(partSize1); |
| 1178 | + uploadPartRequest.setUploadId(uploadId); |
| 1179 | + ossClient.uploadPart(uploadPartRequest); |
| 1180 | + |
| 1181 | + // Upload part2 part |
| 1182 | + instream = genFixedLengthInputStream(partSize2); |
| 1183 | + uploadPartRequest = new UploadPartRequest(); |
| 1184 | + uploadPartRequest.setBucketName(bucketName); |
| 1185 | + uploadPartRequest.setKey(key2); |
| 1186 | + uploadPartRequest.setInputStream(instream); |
| 1187 | + uploadPartRequest.setPartNumber(2); |
| 1188 | + uploadPartRequest.setPartSize(partSize2); |
| 1189 | + uploadPartRequest.setUploadId(uploadId); |
| 1190 | + ossClient.uploadPart(uploadPartRequest); |
| 1191 | + |
| 1192 | + completeMultipartUploadRequest = new CompleteMultipartUploadRequest(bucketName, key2, uploadId, null); |
| 1193 | + completeMultipartUploadRequest.addHeader("x-oss-complete-all", "yes"); |
| 1194 | + CompleteMultipartUploadResult completeMultipartUploadResult2 = ossClient.completeMultipartUpload(completeMultipartUploadRequest); |
| 1195 | + |
| 1196 | + ObjectMetadata meta1 = ossClient.getObjectMetadata(bucketName, key1); |
| 1197 | + ObjectMetadata meta2 = ossClient.getObjectMetadata(bucketName, key2); |
| 1198 | + |
| 1199 | + Assert.assertEquals(meta1.getContentLength(), meta2.getContentLength()); |
| 1200 | + Assert.assertEquals(meta1.getServerCRC(), meta2.getServerCRC()); |
| 1201 | + Assert.assertEquals(meta1.getETag(), meta2.getETag()); |
| 1202 | + |
| 1203 | + |
| 1204 | + } catch (Exception e) { |
| 1205 | + Assert.fail(e.getMessage()); |
| 1206 | + } |
| 1207 | + } |
| 1208 | + |
1123 | 1209 | } |
0 commit comments