@@ -236,6 +236,7 @@ public void testStat() throws Exception {
236
236
public void testFile (TestConfig .TestFile file , BucketManager bucketManager ) throws IOException {
237
237
String bucket = file .getBucketName ();
238
238
String key = file .getKey ();
239
+ key = "12344" ;
239
240
try {
240
241
FileInfo info = bucketManager .stat (bucket , key );
241
242
Assert .assertNotNull (info .hash );
@@ -1559,6 +1560,129 @@ public void testFile(TestConfig.TestFile file, BucketManager bucketManager) thro
1559
1560
});
1560
1561
}
1561
1562
1563
+ @ Test
1564
+ public void testBatchRestoreArchive () throws Exception {
1565
+
1566
+ testFileWithHandler (new TestFileHandler () {
1567
+ @ Override
1568
+ public void testFile (TestConfig .TestFile file , BucketManager bucketManager ) throws IOException {
1569
+ String bucket = file .getBucketName ();
1570
+ String key = file .getKey ();
1571
+ String keyToTestPrefix = "batch_restore_archive" ;
1572
+
1573
+ BucketManager .BatchOperations deleteOps = new BucketManager .BatchOperations ();
1574
+ try {
1575
+ List <String > keys = new ArrayList <>();
1576
+ for (int i = 0 ; i < 5 ; i ++) {
1577
+ keys .add (keyToTestPrefix + "_" + i );
1578
+ }
1579
+
1580
+ for (String keyToTest : keys ) {
1581
+ // if stat, delete
1582
+ try {
1583
+ Response resp = bucketManager .statResponse (bucket , keyToTest );
1584
+ if (resp .statusCode == 200 ) bucketManager .delete (bucket , keyToTest );
1585
+ } catch (QiniuException ex ) {
1586
+ System .out .println ("file " + keyToTest + " not exists, ok." );
1587
+ }
1588
+ }
1589
+
1590
+ // copy and changeType to Archive
1591
+ BucketManager .BatchOperations copyOps = new BucketManager .BatchOperations ();
1592
+ BucketManager .BatchOperations copyAfterArchiveOps = new BucketManager .BatchOperations ();
1593
+ BucketManager .BatchOperations changeTypeOps = new BucketManager .BatchOperations ();
1594
+ BucketManager .BatchOperations restoreArchiveOps = new BucketManager .BatchOperations ();
1595
+ for (String keyToTest : keys ) {
1596
+ copyOps .addCopyOp (bucket , key , bucket , keyToTest );
1597
+ copyAfterArchiveOps .addCopyOp (bucket , keyToTest , bucket , keyToTest + "_copy" );
1598
+ deleteOps .addDeleteOp (bucket , keyToTest , keyToTest + "_copy" );
1599
+ changeTypeOps .addChangeTypeOps (bucket , StorageType .Archive , keyToTest );
1600
+ restoreArchiveOps .addRestoreArchiveOps (bucket , 1 , keyToTest );
1601
+ }
1602
+ Response copyResponse = bucketManager .batch (copyOps );
1603
+ Assert .assertEquals (200 , copyResponse .statusCode );
1604
+
1605
+ Response changeTypeResponse = bucketManager .batch (changeTypeOps );
1606
+ Assert .assertEquals (200 , changeTypeResponse .statusCode );
1607
+
1608
+ // 验证归档不可 copy
1609
+ try {
1610
+ Response copyAfterArchiveResponse = bucketManager .batch (copyAfterArchiveOps );
1611
+ String bodyString = copyAfterArchiveResponse .bodyString ();
1612
+ Assert .assertNotEquals (200 , "batch copy can't be success" + bodyString );
1613
+ } catch (QiniuException ex ) {
1614
+ Assert .assertEquals (400 , ex .response .statusCode );
1615
+ System .out .println (ex .response .bodyString ());
1616
+ }
1617
+
1618
+ // restoreArchive
1619
+ Response restoreResponse = bucketManager .batch (restoreArchiveOps );
1620
+ String bodyString = restoreResponse .bodyString ();
1621
+ System .out .println (bodyString );
1622
+ Assert .assertEquals (200 , restoreResponse .statusCode );
1623
+
1624
+ //test for 400 Bad Request {"error":"invalid freeze after days"}
1625
+ try {
1626
+ restoreResponse = bucketManager .batch (restoreArchiveOps );
1627
+ bodyString = restoreResponse .bodyString ();
1628
+ System .out .println (bodyString );
1629
+ } catch (QiniuException ex ) {
1630
+ Assert .assertEquals (400 , ex .response .statusCode );
1631
+ System .out .println (ex .response .bodyString ());
1632
+ }
1633
+
1634
+ long checkStart = new Date ().getTime ();
1635
+ boolean shouldCheck = true ;
1636
+ boolean success = false ;
1637
+ while (shouldCheck ) {
1638
+ // 验证解归档可 copy
1639
+ try {
1640
+ Response copyAfterArchiveResponse = bucketManager .batch (copyAfterArchiveOps );
1641
+ bodyString = copyAfterArchiveResponse .bodyString ();
1642
+ System .out .println (bodyString );
1643
+ // 可以 copy 但文件已存在
1644
+ if (bodyString .contains ("\" code\" :614" )) {
1645
+ success = true ;
1646
+ break ;
1647
+ }
1648
+ } catch (QiniuException ex ) {
1649
+ System .out .println (ex .response .bodyString ());
1650
+ if (ex .response .statusCode == 400 ) {
1651
+ success = true ;
1652
+ break ;
1653
+ }
1654
+ }
1655
+
1656
+ long current = new Date ().getTime ();
1657
+ if (current - checkStart > 1000 * 60 * 5.5 ) {
1658
+ shouldCheck = false ;
1659
+ }
1660
+
1661
+ try {
1662
+ Thread .sleep (1000 * 10 );
1663
+ } catch (InterruptedException e ) {
1664
+ e .printStackTrace ();
1665
+ }
1666
+ }
1667
+
1668
+ Assert .assertTrue ("can copy after restore archive" , success );
1669
+ } catch (QiniuException e ) {
1670
+ Assert .fail (bucket + ":" + key + " > " + keyToTestPrefix + " >> " + e .response .toString ());
1671
+ } finally {
1672
+ try {
1673
+ Response response = bucketManager .batch (deleteOps );
1674
+ String bodyString = response .bodyString ();
1675
+ System .out .println (bodyString );
1676
+ Assert .assertTrue (bodyString , response .statusCode == 200 || response .statusCode == 298 );
1677
+ } catch (QiniuException ex ) {
1678
+ Assert .assertEquals (400 , ex .response .statusCode );
1679
+ System .out .println (ex .response .bodyString ());
1680
+ }
1681
+ }
1682
+ }
1683
+ });
1684
+ }
1685
+
1562
1686
/**
1563
1687
* 测试noIndexPage
1564
1688
*
0 commit comments