/** * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createBlobSnapshot * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createPageBlob * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::deleteBlob * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getBlob * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::listBlobs */ private function createBlobSnapshotWorker($options, $container) { $blob = BlobServiceFunctionalTestData::getInterestingBlobName($container); // Make sure there is something to test $dataSize = 512; $this->restProxy->createPageBlob($container, $blob, $dataSize); $snapshot1 = $this->restProxy->createBlobSnapshot($container, $blob); if (!is_null($options)) { BlobServiceFunctionalTestData::fixETagAccessCondition($options->getAccessCondition(), $snapshot1->getETag()); } try { $res = is_null($options) ? $this->restProxy->createBlobSnapshot($container, $blob) : $this->restProxy->createBlobSnapshot($container, $blob, $options); if (is_null($options)) { $options = new CreateBlobSnapshotOptions(); } if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) { $this->assertTrue(false, 'Expect negative timeouts in $options to throw'); } if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) { $this->assertTrue(false, 'Expect failing temporal access condition should throw'); } if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) { $this->assertTrue(false, 'Expect failing etag access condition to throw'); } $listOptions = new ListBlobsOptions(); $listOptions->setIncludeSnapshots(true); $listOptions->setPrefix($blob); $listBlobsResult = $this->restProxy->listBlobs($container == '' ? '$root' : $container, $listOptions); $blobs = $listBlobsResult->getBlobs(); $getBlobOptions = new GetBlobOptions(); $getBlobOptions->setSnapshot($res->getSnapshot()); $getBlobResult = $this->restProxy->getBlob($container, $blob, $getBlobOptions); $this->verifyCreateBlobSnapshotWorker($res, $options, $blobs, $getBlobResult); } catch (ServiceException $e) { if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) { $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'bad timeout: deleteHttpStatusCode'); } else { if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) { $this->assertEquals(TestResources::STATUS_PRECONDITION_FAILED, $e->getCode(), 'bad temporal access condition IF_UNMODIFIED_SINCE: deleteHttpStatusCode'); } else { if (!BlobServiceFunctionalTestData::passETagAccessCondition($options->getAccessCondition())) { $this->assertEquals(TestResources::STATUS_PRECONDITION_FAILED, $e->getCode(), 'bad etag access condition: deleteHttpStatusCode'); } else { throw $e; } } } } // Clean up. $this->restProxy->deleteBlob($container, $blob); }
public static function getGetBlobOptions() { $ret = array(); $options = new GetBlobOptions(); array_push($ret, $options); $options = new GetBlobOptions(); $options->setTimeout(10); array_push($ret, $options); $options = new GetBlobOptions(); $options->setTimeout(-10); array_push($ret, $options); // Get Blob only supports the temporal access conditions. foreach (self::getTemporalAccessConditions() as $ac) { $options = new GetBlobOptions(); $options->setAccessCondition($ac); array_push($ret, $options); } $options = new GetBlobOptions(); $options->setRangeStart(50); $options->setRangeEnd(200); array_push($ret, $options); $options = new GetBlobOptions(); $options->setRangeStart(50); $options->setRangeEnd(200); $options->setComputeRangeMD5(true); array_push($ret, $options); $options = new GetBlobOptions(); $options->setRangeStart(50); array_push($ret, $options); $options = new GetBlobOptions(); $options->setComputeRangeMD5(true); array_push($ret, $options); $options = new GetBlobOptions(); $options->setRangeEnd(200); $options->setComputeRangeMD5(true); array_push($ret, $options); $options = new GetBlobOptions(); $options->setRangeEnd(200); array_push($ret, $options); $options = new GetBlobOptions(); $options->setSnapshot('placeholder'); array_push($ret, $options); // TODO: Handle Lease ID // $options = new GetBlobOptions(); // $options->setLeaseId('setLeaseId'); // array_push($ret, $options); return $ret; }
/** * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createPageBlob * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getBlob * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getBlobProperties * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::setBlobMetadata */ public function testGetBlobWithIfNotModifiedSinceAccessConditionWorks() { // Act $container = self::$_test_container_for_blobs; $blob = 'test'; $this->restProxy->createPageBlob($container, $blob, 4096); $props = $this->restProxy->getBlobProperties($container, $blob); // To test for "IfNotModifiedSince", we need to make updates to the blob // until at least 1 second has passed since the blob creation $lastModifiedBase = $props->getProperties()->getLastModified(); // +1 second $lastModifiedNext = clone $lastModifiedBase; $lastModifiedNext = $lastModifiedNext->modify("+1 sec"); while (true) { $metadata = array('test' => 'test1'); $result = $this->restProxy->setBlobMetadata($container, $blob, $metadata); if ($result->getLastModified() >= $lastModifiedNext) { break; } } try { $opts = new GetBlobOptions(); $opts->setAccessCondition(AccessCondition::ifNotModifiedSince($lastModifiedBase)); $this->restProxy->getBlob($container, $blob, $opts); $this->fail('getBlob should throw an exception'); } catch (ServiceException $e) { $this->assertEquals(TestResources::STATUS_PRECONDITION_FAILED, $e->getCode(), 'got the expected exception'); } }
/** * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getBlob * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::_addOptionalRangeHeader * @covers MicrosoftAzure\Storage\Blob\Models\GetBlobResult::create */ public function testGetBlobWithEndRange() { // Setup $name = 'getblobwithendrange' . $this->createSuffix(); $blob = 'myblob'; $this->createContainer($name); $length = 512; $range = new PageRange(0, 511); $contentStream = Resources::EMPTY_STRING; $this->restProxy->createPageBlob($name, $blob, $length); for ($i = 0; $i < 512; $i++) { $contentStream .= 'A'; } $this->restProxy->createBlobPages($name, $blob, $range, $contentStream); $options = new GetBlobOptions(); $options->setRangeStart(null); $options->setRangeEnd(511); // Test $result = $this->restProxy->getBlob($name, $blob, $options); // Assert $this->assertEquals(BlobType::PAGE_BLOB, $result->getProperties()->getBlobType()); $this->assertEquals($contentStream, stream_get_contents($result->getContentStream())); }
/** * Reads or downloads a blob from the system, including its metadata and * properties. * * @param string $container name of the container * @param string $blob name of the blob * @param Models\GetBlobOptions $options optional parameters * * @return Models\GetBlobResult * * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179440.aspx */ public function getBlob($container, $blob, $options = null) { Validate::isString($container, 'container'); Validate::isString($blob, 'blob'); $method = Resources::HTTP_GET; $headers = array(); $postParams = array(); $queryParams = array(); $path = $this->_createPath($container, $blob); $statusCode = array(Resources::STATUS_OK, Resources::STATUS_PARTIAL_CONTENT); if (is_null($options)) { $options = new GetBlobOptions(); } $getMD5 = $options->getComputeRangeMD5(); $headers = $this->addOptionalAccessConditionHeader($headers, $options->getAccessCondition()); $headers = $this->_addOptionalRangeHeader($headers, $options->getRangeStart(), $options->getRangeEnd()); $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ID, $options->getLeaseId()); $this->addOptionalHeader($headers, Resources::X_MS_RANGE_GET_CONTENT_MD5, $getMD5 ? 'true' : null); $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout()); $this->addOptionalQueryParam($queryParams, Resources::QP_SNAPSHOT, $options->getSnapshot()); $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode); $metadata = $this->getMetadataArray(HttpFormatter::formatHeaders($response->getHeaders())); return GetBlobResult::create(HttpFormatter::formatHeaders($response->getHeaders()), $response->getBody(), $metadata); }
/** * @covers MicrosoftAzure\Storage\Blob\Models\GetBlobOptions::getComputeRangeMD5 */ public function testGetComputeRangeMD5() { // Setup $options = new GetBlobOptions(); $expected = true; $options->setComputeRangeMD5($expected); // Test $actual = $options->getComputeRangeMD5(); // Assert $this->assertEquals($expected, $actual); }