Skip to content

Commit 8d40276

Browse files
zhuxiaolong37huiguangjun
authored andcommitted
Add RestoreInfo field and modify some error test cases
1 parent 1b71e4d commit 8d40276

File tree

9 files changed

+347
-10
lines changed

9 files changed

+347
-10
lines changed

src/main/java/com/aliyun/oss/internal/ResponseParsers.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,7 @@ public static ObjectListing parseListObjects(InputStream responseBody) throws Re
12911291
ossObjectSummary.setLastModified(DateUtil.parseIso8601Date(elem.getChildText("LastModified")));
12921292
ossObjectSummary.setSize(Long.valueOf(elem.getChildText("Size")));
12931293
ossObjectSummary.setStorageClass(elem.getChildText("StorageClass"));
1294+
ossObjectSummary.setRestoreInfo(elem.getChildText("RestoreInfo"));
12941295
ossObjectSummary.setBucketName(objectListing.getBucketName());
12951296

12961297
if (elem.getChild("Type") != null) {
@@ -1375,6 +1376,7 @@ public static ListObjectsV2Result parseListObjectsV2(InputStream responseBody) t
13751376
ossObjectSummary.setLastModified(DateUtil.parseIso8601Date(elem.getChildText("LastModified")));
13761377
ossObjectSummary.setSize(Long.valueOf(elem.getChildText("Size")));
13771378
ossObjectSummary.setStorageClass(elem.getChildText("StorageClass"));
1379+
ossObjectSummary.setRestoreInfo(elem.getChildText("RestoreInfo"));
13781380
ossObjectSummary.setBucketName(result.getBucketName());
13791381

13801382
if (elem.getChild("Type") != null) {
@@ -1475,6 +1477,7 @@ public static VersionListing parseListVersions(InputStream responseBody) throws
14751477
ossVersionSummary.setLastModified(DateUtil.parseIso8601Date(elem.getChildText("LastModified")));
14761478
ossVersionSummary.setSize(Long.valueOf(elem.getChildText("Size")));
14771479
ossVersionSummary.setStorageClass(elem.getChildText("StorageClass"));
1480+
ossVersionSummary.setRestoreInfo(elem.getChildText("RestoreInfo"));
14781481
ossVersionSummary.setBucketName(versionListing.getBucketName());
14791482
ossVersionSummary.setIsDeleteMarker(false);
14801483

src/main/java/com/aliyun/oss/model/OSSObjectSummary.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public class OSSObjectSummary {
4444

4545
private String type;
4646

47+
/** The restore info status of the object */
48+
private String restoreInfo;
49+
4750
/**
4851
* Constructor.
4952
*/
@@ -203,4 +206,22 @@ public void setType(String type) {
203206
this.type = type;
204207
}
205208

209+
/**
210+
* Gets the restore info of the object.
211+
*
212+
* @return Object restore info.
213+
*/
214+
public String getRestoreInfo() {
215+
return restoreInfo;
216+
}
217+
218+
/**
219+
* Sets the restore info of the object.
220+
*
221+
* @param restoreInfo
222+
* object restore info
223+
*/
224+
public void setRestoreInfo(String restoreInfo) {
225+
this.restoreInfo = restoreInfo;
226+
}
206227
}

src/main/java/com/aliyun/oss/model/OSSVersionSummary.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ public class OSSVersionSummary implements Serializable {
6868
/** True if this object represents a delete marker */
6969
private boolean isDeleteMarker;
7070

71+
/** The restore info status of the object */
72+
private String restoreInfo;
73+
7174

7275
/**
7376
* Gets the name of the OSS bucket in which this version is stored.
@@ -336,4 +339,22 @@ public void setSize(long size) {
336339
this.size = size;
337340
}
338341

342+
/**
343+
* Gets the restore info of the object.
344+
*
345+
* @return Object restore info.
346+
*/
347+
public String getRestoreInfo() {
348+
return restoreInfo;
349+
}
350+
351+
/**
352+
* Sets the restore info of the object.
353+
*
354+
* @param restoreInfo
355+
* object restore info
356+
*/
357+
public void setRestoreInfo(String restoreInfo) {
358+
this.restoreInfo = restoreInfo;
359+
}
339360
}

src/test/java/com/aliyun/oss/common/parser/ResponseParsersTest.java

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5009,4 +5009,135 @@ public void testParseErrorResponse() {
50095009
Assert.assertTrue(false);
50105010
}
50115011
}
5012+
5013+
@Test
5014+
public void testParseListObjectsWithRestoreInfo() {
5015+
InputStream instream = null;
5016+
String respBody;
5017+
5018+
respBody = "" +
5019+
"<ListBucketResult>\n" +
5020+
" <Name>oss-java-sdk-1667542813</Name>\n" +
5021+
" <Prefix></Prefix>\n" +
5022+
" <Marker></Marker>\n" +
5023+
" <MaxKeys>100</MaxKeys>\n" +
5024+
" <Delimiter></Delimiter>\n" +
5025+
" <IsTruncated>false</IsTruncated>\n" +
5026+
" <Contents>\n" +
5027+
" <Key>object-with-special-restore</Key>\n" +
5028+
" <LastModified>2022-11-04T05:23:18.000Z</LastModified>\n" +
5029+
" <ETag>\"AB56B4D92B40713ACC5AF89985D4B786\"</ETag>\n" +
5030+
" <Type>Normal</Type>\n" +
5031+
" <Size>5</Size>\n" +
5032+
" <StorageClass>Archive</StorageClass>\n" +
5033+
" <Owner>\n" +
5034+
" <ID>1283641064516515</ID>\n" +
5035+
" <DisplayName>1283641064516515</DisplayName>\n" +
5036+
" </Owner>\n" +
5037+
" <RestoreInfo>ongoing-request=\"true\"</RestoreInfo>\n" +
5038+
" </Contents>\n" +
5039+
"</ListBucketResult>";
5040+
try {
5041+
instream = new ByteArrayInputStream(respBody.getBytes("utf-8"));
5042+
} catch (UnsupportedEncodingException e) {
5043+
Assert.fail("UnsupportedEncodingException");
5044+
}
5045+
5046+
ObjectListing result = null;
5047+
try {
5048+
result = ResponseParsers.parseListObjects(instream);
5049+
Assert.assertTrue(true);
5050+
} catch (Exception e) {
5051+
Assert.assertTrue(false);
5052+
}
5053+
Assert.assertEquals("object-with-special-restore", result.getObjectSummaries().get(0).getKey());
5054+
Assert.assertEquals("ongoing-request=\"true\"", result.getObjectSummaries().get(0).getRestoreInfo());
5055+
}
5056+
5057+
@Test
5058+
public void testParseListObjectsV2WithRestoreInfo() {
5059+
InputStream instream = null;
5060+
String respBody;
5061+
5062+
respBody = "" +
5063+
"<ListBucketResult>\n" +
5064+
" <Name>oss-java-sdk-1667548362-list-v2</Name>\n" +
5065+
" <Prefix></Prefix>\n" +
5066+
" <MaxKeys>100</MaxKeys>\n" +
5067+
" <Delimiter></Delimiter>\n" +
5068+
" <IsTruncated>false</IsTruncated>\n" +
5069+
" <Contents>\n" +
5070+
" <Key>object-with-special-restore</Key>\n" +
5071+
" <LastModified>2022-11-04T07:37:25.000Z</LastModified>\n" +
5072+
" <ETag>\"AB56B4D92B40713ACC5AF89985D4B786\"</ETag>\n" +
5073+
" <Type>Normal</Type>\n" +
5074+
" <Size>5</Size>\n" +
5075+
" <StorageClass>Archive</StorageClass>\n" +
5076+
" <RestoreInfo>ongoing-request=\"false\", expiry-date=\"Sat, 05 Nov 2022 07:38:08 GMT\"</RestoreInfo>\n" +
5077+
" </Contents>\n" +
5078+
" <KeyCount>1</KeyCount>\n" +
5079+
"</ListBucketResult>\n";
5080+
try {
5081+
instream = new ByteArrayInputStream(respBody.getBytes("utf-8"));
5082+
} catch (UnsupportedEncodingException e) {
5083+
Assert.fail("UnsupportedEncodingException");
5084+
}
5085+
5086+
ListObjectsV2Result result = null;
5087+
try {
5088+
result = ResponseParsers.parseListObjectsV2(instream);
5089+
Assert.assertTrue(true);
5090+
} catch (Exception e) {
5091+
Assert.assertTrue(false);
5092+
}
5093+
Assert.assertEquals("object-with-special-restore", result.getObjectSummaries().get(0).getKey());
5094+
Assert.assertEquals("ongoing-request=\"false\", expiry-date=\"Sat, 05 Nov 2022 07:38:08 GMT\"", result.getObjectSummaries().get(0).getRestoreInfo());
5095+
}
5096+
5097+
@Test
5098+
public void testParseListVersionsWithRestoreInfo() {
5099+
InputStream instream = null;
5100+
String respBody;
5101+
5102+
respBody = "" +
5103+
"<ListVersionsResult>\n" +
5104+
" <Name>oss-java-sdk-1667549556-list-versions</Name>\n" +
5105+
" <Prefix></Prefix>\n" +
5106+
" <KeyMarker></KeyMarker>\n" +
5107+
" <VersionIdMarker></VersionIdMarker>\n" +
5108+
" <MaxKeys>100</MaxKeys>\n" +
5109+
" <Delimiter></Delimiter>\n" +
5110+
" <IsTruncated>false</IsTruncated>\n" +
5111+
" <Version>\n" +
5112+
" <Key>object-with-special-restore</Key>\n" +
5113+
" <VersionId>CAEQDxiBgID78pyGohgiIDFhNWM0ODYxMDcyNTQ0ODJiZDJjZDlmNjRhZmU5MWEy</VersionId>\n" +
5114+
" <IsLatest>true</IsLatest>\n" +
5115+
" <LastModified>2022-11-04T07:32:45.000Z</LastModified>\n" +
5116+
" <ETag>\"AB56B4D92B40713ACC5AF89985D4B786\"</ETag>\n" +
5117+
" <Type>Normal</Type>\n" +
5118+
" <Size>5</Size>\n" +
5119+
" <StorageClass>Archive</StorageClass>\n" +
5120+
" <RestoreInfo>ongoing-request=\"true\"</RestoreInfo>\n" +
5121+
" <Owner>\n" +
5122+
" <ID>1283641064516515</ID>\n" +
5123+
" <DisplayName>1283641064516515</DisplayName>\n" +
5124+
" </Owner>\n" +
5125+
" </Version>\n" +
5126+
"</ListVersionsResult>";
5127+
try {
5128+
instream = new ByteArrayInputStream(respBody.getBytes("utf-8"));
5129+
} catch (UnsupportedEncodingException e) {
5130+
Assert.fail("UnsupportedEncodingException");
5131+
}
5132+
5133+
VersionListing result = null;
5134+
try {
5135+
result = ResponseParsers.parseListVersions(instream);
5136+
Assert.assertTrue(true);
5137+
} catch (Exception e) {
5138+
Assert.assertTrue(false);
5139+
}
5140+
Assert.assertEquals("object-with-special-restore", result.getVersionSummaries().get(0).getKey());
5141+
Assert.assertEquals("ongoing-request=\"true\"", result.getVersionSummaries().get(0).getRestoreInfo());
5142+
}
50125143
}

src/test/java/com/aliyun/oss/integrationtests/ListObjectsTest.java

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@
2121

2222
import static com.aliyun.oss.integrationtests.TestUtils.batchPutObject;
2323

24+
import java.io.ByteArrayInputStream;
2425
import java.net.URLDecoder;
2526
import java.util.ArrayList;
27+
import java.util.HashMap;
2628
import java.util.List;
29+
import java.util.Map;
2730

31+
import com.aliyun.oss.internal.OSSHeaders;
32+
import com.aliyun.oss.model.PutObjectRequest;
2833
import junit.framework.Assert;
2934

3035
import org.junit.Test;
@@ -286,5 +291,54 @@ public void testListObjectsWithEncodingType() {
286291
Assert.fail(e.getMessage());
287292
}
288293
}
289-
294+
295+
@Test
296+
public void testListObjectsWithRestoreInfo() {
297+
String objectPrefix = "object-with-special-restore";
298+
String content = "abcde";
299+
300+
try {
301+
// First upload the archive file, and then unfreeze it to obtain the returned RestoreInfo
302+
Map<String, String> header = new HashMap<String, String>();
303+
header.put(OSSHeaders.STORAGE_CLASS, "Archive");
304+
305+
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectPrefix, new ByteArrayInputStream(content.getBytes()));
306+
putObjectRequest.setHeaders(header);
307+
ossClient.putObject(putObjectRequest);
308+
309+
ossClient.restoreObject(bucketName, objectPrefix);
310+
311+
ListObjectsRequest listObjectsRequest = new ListObjectsRequest(bucketName);
312+
ObjectListing objectListing = ossClient.listObjects(listObjectsRequest);
313+
for (OSSObjectSummary s : objectListing.getObjectSummaries()) {
314+
String restoreInfo = s.getRestoreInfo();
315+
Assert.assertEquals(restoreInfo, "ongoing-request=\"true\"");
316+
}
317+
318+
boolean flag = true;
319+
long startTime = System.currentTimeMillis();
320+
while (flag){
321+
try {
322+
Thread.sleep(1000);
323+
} catch (InterruptedException e) {
324+
e.printStackTrace();
325+
}
326+
objectListing = ossClient.listObjects(listObjectsRequest);
327+
for (OSSObjectSummary s : objectListing.getObjectSummaries()) {
328+
if(s.getRestoreInfo().contains("ongoing-request=\"false\"")){
329+
flag = false;
330+
Assert.assertTrue(true);
331+
break;
332+
}
333+
long endTime = System.currentTimeMillis();
334+
if(endTime - startTime > 1000 * 120){
335+
Assert.assertFalse(true);
336+
}
337+
}
338+
}
339+
340+
} catch (Exception e) {
341+
Assert.fail(e.getMessage());
342+
}
343+
}
290344
}

src/test/java/com/aliyun/oss/integrationtests/ListObjectsV2Test.java

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@
2727
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
2828
import com.aliyun.oss.common.auth.DefaultCredentials;
2929
import com.aliyun.oss.common.utils.HttpUtil;
30-
import com.aliyun.oss.model.ListObjectsV2Request;
31-
import com.aliyun.oss.model.ListObjectsV2Result;
32-
import com.aliyun.oss.model.OSSObjectSummary;
30+
import com.aliyun.oss.internal.OSSHeaders;
31+
import com.aliyun.oss.model.*;
3332
import junit.framework.Assert;
3433
import org.junit.Test;
3534
import java.io.ByteArrayInputStream;
3635
import java.net.URLDecoder;
3736
import java.util.ArrayList;
37+
import java.util.HashMap;
3838
import java.util.List;
39+
import java.util.Map;
40+
3941
import static com.aliyun.oss.integrationtests.TestUtils.batchPutObject;
4042
import static com.aliyun.oss.integrationtests.TestUtils.waitForCacheExpiration;
4143
import static com.aliyun.oss.internal.OSSConstants.DEFAULT_CHARSET_NAME;
@@ -405,4 +407,53 @@ public void testUnnormalListObjects() {
405407
}
406408
}
407409

410+
@Test
411+
public void testListObjectsWithRestoreInfo() {
412+
String objectPrefix = "object-with-special-restore";
413+
String content = "abcde";
414+
415+
try {
416+
// First upload the archive file, and then unfreeze it to obtain the returned RestoreInfo
417+
Map<String, String> header = new HashMap<String, String>();
418+
header.put(OSSHeaders.STORAGE_CLASS, "Archive");
419+
420+
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectPrefix, new ByteArrayInputStream(content.getBytes()));
421+
putObjectRequest.setHeaders(header);
422+
ossClient.putObject(putObjectRequest);
423+
424+
ossClient.restoreObject(bucketName, objectPrefix);
425+
426+
ListObjectsV2Request listObjectsRequest = new ListObjectsV2Request(bucketName);
427+
ListObjectsV2Result objectListing = ossClient.listObjectsV2(listObjectsRequest);
428+
for (OSSObjectSummary s : objectListing.getObjectSummaries()) {
429+
String restoreInfo = s.getRestoreInfo();
430+
Assert.assertEquals(restoreInfo, "ongoing-request=\"true\"");
431+
}
432+
433+
boolean flag = true;
434+
long startTime = System.currentTimeMillis();
435+
while (flag){
436+
try {
437+
Thread.sleep(1000);
438+
} catch (InterruptedException e) {
439+
e.printStackTrace();
440+
}
441+
objectListing = ossClient.listObjectsV2(listObjectsRequest);
442+
for (OSSObjectSummary s : objectListing.getObjectSummaries()) {
443+
if(s.getRestoreInfo().contains("ongoing-request=\"false\"")){
444+
flag = false;
445+
Assert.assertTrue(true);
446+
break;
447+
}
448+
long endTime = System.currentTimeMillis();
449+
if(endTime - startTime > 1000 * 120){
450+
Assert.assertFalse(true);
451+
}
452+
}
453+
}
454+
455+
} catch (Exception e) {
456+
Assert.fail(e.getMessage());
457+
}
458+
}
408459
}

0 commit comments

Comments
 (0)