public function testHasChainableSetterMethods()
 {
     /** @var $builder UploadBuilder */
     $builder = UploadBuilder::newInstance();
     $builder->setAccountId('foo')->setVaultName('bar')->setPartGenerator(UploadPartGenerator::factory(EntityBody::factory(), 1024 * 1024))->setConcurrency(1)->setPartSize(1024 * 1024)->setArchiveDescription('abc');
     $this->assertEquals('foo', $this->readAttribute($builder, 'accountId'));
     $this->assertEquals('bar', $this->readAttribute($builder, 'vaultName'));
     $this->assertEquals('abc', $this->readAttribute($builder, 'archiveDescription'));
     $this->assertEquals(1, $this->readAttribute($builder, 'concurrency'));
     $this->assertEquals(1024 * 1024, $this->readAttribute($builder, 'partSize'));
     $this->assertInstanceOf('Aws\\Glacier\\Model\\MultipartUpload\\UploadPartGenerator', $this->readAttribute($builder, 'partGenerator'));
 }
 protected function prepComponents()
 {
     $uploadId = $this->getMockBuilder('Aws\\Glacier\\Model\\MultipartUpload\\UploadId')->setMethods(array('toParams'))->getMock();
     $uploadId->expects($this->any())->method('toParams')->will($this->returnValue(array('accountId' => '-', 'vaultName' => 'foo', 'uploadId' => 'bar')));
     $body = EntityBody::factory(str_repeat('x', 1024 * 1024 + 1024));
     $generator = UploadPartGenerator::factory($body, 1024 * 1024);
     $client = $this->getServiceBuilder()->get('glacier', true);
     $state = new TransferState($uploadId);
     $state->setPartGenerator($generator);
     $transfer = new SerialTransfer($client, $state, $body);
     return array($transfer, $client, $state);
 }
 /**
  * Retrieve bodies passed in as UploadPartContext objects and set the real hash, length, etc. values on the command
  *
  * @param Event $event Event emitted
  */
 public function onCommandBeforeSend(Event $event)
 {
     /** @var AbstractCommand $command */
     $command = $event['command'];
     $contentHash = $command->get('ContentSHA256');
     if ($contentHash === true) {
         /** @var EntityEnclosingRequest $request */
         $request = $command->getRequest();
         $upload = UploadPartGenerator::createSingleUploadPart($request->getBody());
         $request->addHeader('x-amz-content-sha256', $upload->getContentHash());
         if (!$command->get('checksum')) {
             $request->addHeader('x-amz-sha256-tree-hash', $upload->getChecksum());
         }
     } elseif (is_string($contentHash)) {
         $request = $command->getRequest();
         $request->addHeader('x-amz-content-sha256', $contentHash);
     }
 }
 public function testSerializationAndUnserializationWorks()
 {
     $generator = UploadPartGenerator::factory($this->bodyContent, Size::MB);
     $startingSize = $generator->getArchiveSize();
     $serialized = serialize($generator);
     $newGenerator = unserialize($serialized);
     $endingSize = $newGenerator->getArchiveSize();
     $this->assertEquals($startingSize, $endingSize);
 }
 /**
  * {@inheritdoc}
  */
 protected function initiateMultipartUpload()
 {
     $params = array('accountId' => $this->accountId, 'vaultName' => $this->vaultName);
     $partGenerator = $this->partGenerator ?: UploadPartGenerator::factory($this->source, $this->partSize);
     $command = $this->client->getCommand('InitiateMultipartUpload', array_replace($params, array('command.headers' => $this->headers, 'partSize' => $partGenerator->getPartSize(), 'archiveDescription' => $this->archiveDescription, Ua::OPTION => Ua::MULTIPART_UPLOAD)));
     $params['uploadId'] = $command->getResult()->get('uploadId');
     // Create a new state based on the initiated upload
     $state = new TransferState(UploadId::fromParams($params));
     $state->setPartGenerator($partGenerator);
     return $state;
 }
 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   1', '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, 'archiveDescription' => 'Foo   bar   2', '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));
 }
 protected function generateUploadParts(EntityBodyInterface $body)
 {
     $this->partSize = 1024;
     parent::generateUploadParts($body);
 }
 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));
 }