ResumeUpTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace Qiniu\Tests;
  3. use phpDocumentor\Reflection\DocBlock\Tags\Version;
  4. use Qiniu\Region;
  5. use Qiniu\Storage\ResumeUploader;
  6. use Qiniu\Storage\UploadManager;
  7. use Qiniu\Config;
  8. use Qiniu\Zone;
  9. class ResumeUpTest extends \PHPUnit_Framework_TestCase
  10. {
  11. protected $bucketName;
  12. protected $auth;
  13. protected function setUp()
  14. {
  15. global $bucketName;
  16. $this->bucketName = $bucketName;
  17. global $testAuth;
  18. $this->auth = $testAuth;
  19. }
  20. public function test4ML()
  21. {
  22. $key = 'resumePutFile4ML';
  23. $upManager = new UploadManager();
  24. $token = $this->auth->uploadToken($this->bucketName, $key);
  25. $tempFile = qiniuTempFile(4 * 1024 * 1024 + 10);
  26. $resumeFile = tempnam(sys_get_temp_dir(), 'resume_file');
  27. $this->assertNotFalse($resumeFile);
  28. list($ret, $error) = $upManager->putFile(
  29. $token,
  30. $key,
  31. $tempFile,
  32. null,
  33. 'application/octet-stream',
  34. false,
  35. $resumeFile
  36. );
  37. $this->assertNull($error);
  38. $this->assertNotNull($ret['hash']);
  39. unlink($resumeFile);
  40. unlink($tempFile);
  41. }
  42. public function test4ML2()
  43. {
  44. $key = 'resumePutFile4ML';
  45. $zone = new Zone(array('upload.fake.qiniu.com'), array('upload.qiniup.com'));
  46. $cfg = new Config($zone);
  47. $upManager = new UploadManager($cfg);
  48. $token = $this->auth->uploadToken($this->bucketName, $key);
  49. $tempFile = qiniuTempFile(4 * 1024 * 1024 + 10);
  50. $resumeFile = tempnam(sys_get_temp_dir(), 'resume_file');
  51. $this->assertNotFalse($resumeFile);
  52. list($ret, $error) = $upManager->putFile(
  53. $token,
  54. $key,
  55. $tempFile,
  56. null,
  57. 'application/octet-stream',
  58. false,
  59. $resumeFile
  60. );
  61. $this->assertNull($error);
  62. $this->assertNotNull($ret['hash']);
  63. unlink($resumeFile);
  64. unlink($tempFile);
  65. }
  66. // public function test8M()
  67. // {
  68. // $key = 'resumePutFile8M';
  69. // $upManager = new UploadManager();
  70. // $token = $this->auth->uploadToken($this->bucketName, $key);
  71. // $tempFile = qiniuTempFile(8*1024*1024+10);
  72. // list($ret, $error) = $upManager->putFile($token, $key, $tempFile);
  73. // $this->assertNull($error);
  74. // $this->assertNotNull($ret['hash']);
  75. // unlink($tempFile);
  76. // }
  77. public function testResumeUploadV2()
  78. {
  79. $key = 'resumePutFile4ML';
  80. $zone = new Zone(array('up.qiniup.com'));
  81. $cfg = new Config($zone);
  82. $upManager = new UploadManager($cfg);
  83. $token = $this->auth->uploadToken($this->bucketName, $key);
  84. $testFileSize = array(
  85. config::BLOCK_SIZE / 2,
  86. config::BLOCK_SIZE,
  87. config::BLOCK_SIZE + 10,
  88. config::BLOCK_SIZE * 2,
  89. config::BLOCK_SIZE * 2.5
  90. );
  91. $partSize = 5 * 1024 * 1024;
  92. foreach ($testFileSize as $item) {
  93. $tempFile = qiniuTempFile($item);
  94. $resumeFile = tempnam(sys_get_temp_dir(), 'resume_file');
  95. $this->assertNotFalse($resumeFile);
  96. list($ret, $error) = $upManager->putFile(
  97. $token,
  98. $key,
  99. $tempFile,
  100. null,
  101. 'application/octet-stream',
  102. false,
  103. $resumeFile,
  104. 'v2',
  105. $partSize
  106. );
  107. $this->assertNull($error);
  108. $this->assertNotNull($ret['hash']);
  109. unlink($resumeFile);
  110. unlink($tempFile);
  111. }
  112. }
  113. }