/** * Creates a snapshot of a blob. * * @param string $container The name of the container. * @param string $blob The name of the blob. * @param Models\CreateBlobSnapshotOptions $options The optional parameters. * * @return Models\CreateBlobSnapshotResult * * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691971.aspx */ public function createBlobSnapshot($container, $blob, $options = null) { Validate::isString($container, 'container'); Validate::isString($blob, 'blob'); Validate::notNullOrEmpty($blob, 'blob'); $method = Resources::HTTP_PUT; $headers = array(); $postParams = array(); $queryParams = array(); $path = $this->_createPath($container, $blob); $expectedStatusCode = Resources::STATUS_CREATED; if (is_null($options)) { $options = new CreateBlobSnapshotOptions(); } $queryParams[Resources::QP_COMP] = 'snapshot'; $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout()); $headers = $this->addOptionalAccessConditionHeader($headers, $options->getAccessCondition()); $headers = $this->addMetadataHeaders($headers, $options->getMetadata()); $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ID, $options->getLeaseId()); $response = $this->send($method, $headers, $queryParams, $postParams, $path, $expectedStatusCode); return CreateBlobSnapshotResult::create($response->getHeader()); }
/** * @covers WindowsAzure\Blob\BlobRestProxy::createBlobSnapshot * @covers WindowsAzure\Blob\BlobRestProxy::createPageBlob * @covers WindowsAzure\Blob\BlobRestProxy::deleteBlob * @covers WindowsAzure\Blob\BlobRestProxy::getBlob * @covers WindowsAzure\Blob\BlobRestProxy::listBlobs */ private function createBlobSnapshotWorker($options, $container) { $blob = BlobServiceFunctionalTestData::getInterestingBlobName(); // 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(500, $e->getCode(), 'bad timeout: deleteHttpStatusCode'); } else { if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) { $this->assertEquals(412, $e->getCode(), 'bad temporal access condition IF_UNMODIFIED_SINCE: deleteHttpStatusCode'); } else { if (!BlobServiceFunctionalTestData::passEtagAccessCondition($options->getAccessCondition())) { $this->assertEquals(412, $e->getCode(), 'bad etag access condition: deleteHttpStatusCode'); } else { } } } } // Clean up. $this->restProxy->deleteBlob($container, $blob); }