public function testUploadAndDeleteArchives() { self::log('Create a 6MB+ string of test data to upload.'); $length = 6 * Size::MB + 425; $content = EntityBody::factory(str_repeat('x', $length)); $partSize = 4 * Size::MB; self::log('Perform a single upload.'); $archiveId = $this->client->uploadArchive(array('vaultName' => self::TEST_VAULT, 'archiveDescription' => 'Foo bar', 'body' => $content))->get('archiveId'); $this->assertNotEmpty($archiveId); self::log('Delete the archive that was just uploaded.'); $this->client->deleteArchive(array('vaultName' => self::TEST_VAULT, 'archiveId' => $archiveId)); sleep(3); self::log('Initiate a multipart upload with a part size of ' . $partSize . ' bytes.'); $generator = UploadPartGenerator::factory($content, $partSize); $this->assertEquals($length, $generator->getArchiveSize()); $uploadId = $this->client->initiateMultipartUpload(array('vaultName' => self::TEST_VAULT, 'partSize' => $partSize))->get('uploadId'); /** @var $part UploadPart */ foreach ($generator as $part) { self::log('Upload bytes ' . join('-', $part->getRange()) . '.'); $this->client->uploadMultipartPart(array('vaultName' => self::TEST_VAULT, 'uploadId' => $uploadId, 'range' => $part->getFormattedRange(), 'checksum' => $part->getChecksum(), 'ContentSHA256' => $part->getContentHash(), 'body' => new ReadLimitEntityBody($content, $part->getSize(), $part->getOffset()))); sleep(3); } self::log('Complete the multipart upload.'); $archiveId = $this->client->completeMultipartUpload(array('vaultName' => self::TEST_VAULT, 'uploadId' => $uploadId, 'archiveSize' => $generator->getArchiveSize(), 'checksum' => $generator->getRootChecksum()))->get('archiveId'); $this->assertNotEmpty($archiveId); self::log('Delete the archive that was just uploaded in parts.'); $this->client->deleteArchive(array('vaultName' => self::TEST_VAULT, 'archiveId' => $archiveId)); }
public function testMultipartUploadAbstractions() { $source = EntityBody::factory(str_repeat('x', 6 * Size::MB + 425)); /** @var $transfer Transfer */ $transfer = UploadBuilder::newInstance()->setClient($this->client)->setSource($source)->setVaultName(self::TEST_VAULT)->setPartSize(Size::MB)->setArchiveDescription('Foo bar 3')->build(); $transfer->getEventDispatcher()->addListener($transfer::BEFORE_PART_UPLOAD, function ($event) { static $count = 0; if ($count > 2) { throw new \Exception(); } $count++; }); try { $transfer->upload(); $serializedState = null; $this->fail('Unexpected code execution - exit point 1'); } catch (MultipartUploadException $e) { $serializedState = serialize($e->getState()); } $state = unserialize($serializedState); $this->assertInstanceOf('Aws\\Glacier\\Model\\MultipartUpload\\TransferState', $state); /** @var $transfer Transfer */ $transfer = UploadBuilder::newInstance()->setClient($this->client)->setSource($source)->setVaultName(self::TEST_VAULT)->resumeFrom($state)->build(); try { $result = $transfer->upload(); } catch (MultipartUploadException $e) { $result = null; $this->fail('Unexpected code execution - exit point 2'); } $this->assertNotEmpty($result['archiveId']); $this->assertEquals($result['checksum'], $transfer->getState()->getPartGenerator()->getRootChecksum()); $this->client->deleteArchive(array('vaultName' => self::TEST_VAULT, 'archiveId' => $result['archiveId'])); }
public function testUploadAndDeleteArchives() { $length = 6 * Size::MB + 425; $content = EntityBody::factory(str_repeat('x', $length)); $partSize = 2 * Size::MB; // Single upload $archiveId = $this->client->getCommand('UploadArchive', array('vaultName' => self::TEST_VAULT, 'archiveDescription' => 'Foo bar', 'body' => $content))->getResult()->get('archiveId'); $this->assertNotEmpty($archiveId); // Delete the archive $this->client->deleteArchive(array('vaultName' => self::TEST_VAULT, 'archiveId' => $archiveId)); sleep(3); // Multipart upload $generator = UploadPartGenerator::factory($content, $partSize); $this->assertEquals($length, $generator->getArchiveSize()); $uploadId = $this->client->getCommand('InitiateMultipartUpload', array('vaultName' => self::TEST_VAULT, 'partSize' => (string) $partSize))->getResult()->get('uploadId'); /** @var $part UploadPart */ foreach ($generator as $part) { $this->client->uploadMultipartPart(array('vaultName' => self::TEST_VAULT, 'uploadId' => $uploadId, 'range' => $part->getFormattedRange(), 'checksum' => $part->getChecksum(), 'ContentSHA256' => $part->getContentHash(), 'body' => new ReadLimitEntityBody($content, $part->getSize(), $part->getOffset()))); sleep(3); } $archiveId = $this->client->getCommand('CompleteMultipartUpload', array('vaultName' => self::TEST_VAULT, 'uploadId' => $uploadId, 'archiveSize' => $generator->getArchiveSize(), 'checksum' => $generator->getRootChecksum()))->getResult()->get('archiveId'); $this->assertNotEmpty($archiveId); // Delete the archive $this->client->deleteArchive(array('vaultName' => self::TEST_VAULT, 'archiveId' => $archiveId)); }