/** * @covers WindowsAzure\Blob\BlobRestProxy::createBlockBlob **/ public function testCreateBlobLargerThanSingleBlock() { // First step, lets set the value for automagic splitting to somethign very small $max_size = 50; $this->restProxy->setSingleBlobUploadThresholdInBytes($max_size); $this->assertEquals($this->restProxy->getSingleBlobUploadThresholdInBytes(), $max_size); $name = 'createbloblargerthansingleblock' . $this->createSuffix(); $this->createContainer($name); $contentType = 'text/plain; charset=UTF-8'; $content = "This is a really long section of text needed for this test."; // Note this grows fast, each loop doubles the last run. Do not make too big // This results in a 1888 byte string, divided by 50 results in 38 blocks for ($i = 0; $i < 5; $i++) { $content .= $content; } $options = new CreateBlobOptions(); $options->setContentType($contentType); $this->restProxy->createBlockBlob($name, 'little_split', $content, $options); // Block specific $boptions = new ListBlobBlocksOptions(); $boptions->setIncludeUncommittedBlobs(true); $boptions->setIncludeCommittedBlobs(true); $result = $this->restProxy->listBlobBlocks($name, 'little_split', $boptions); $blocks = $result->getUnCommittedBlocks(); $this->assertEquals(count($blocks), 0); $blocks = $result->getCommittedBlocks(); $this->assertEquals(count($blocks), ceil(strlen($content) / $max_size)); // Setting back to default value for one shot test $this->restProxy->setSingleBlobUploadThresholdInBytes(0); $this->restProxy->createBlockBlob($name, 'oneshot', $content, $options); $result = $this->restProxy->listBlobBlocks($name, 'oneshot', $boptions); $blocks = $result->getUnCommittedBlocks(); $this->assertEquals(count($blocks), 0); $blocks = $result->getCommittedBlocks(); // this one doesn't make sense. On emulator, there is no block created, // so relying on content size to be final approval $this->assertEquals(count($blocks), 0); $this->assertEquals($result->getContentLength(), strlen($content)); // make string even larger for automagic splitting // This should result in a string longer than 32M, and force the blob into 2 blocks for ($i = 0; $i < 15; $i++) { $content .= $content; } $this->restProxy->createBlockBlob($name, 'bigsplit', $content, $options); $result = $this->restProxy->listBlobBlocks($name, 'bigsplit', $boptions); $blocks = $result->getUnCommittedBlocks(); $this->assertEquals(count($blocks), 0); $blocks = $result->getCommittedBlocks(); $this->assertEquals(count($blocks), ceil(strlen($content) / (4 * 1024 * 1024))); }
/** * @covers WindowsAzure\Blob\Models\ListBlobBlocksOptions::getBlockListType */ public function testGetBlockListType() { // Setup $options = new ListBlobBlocksOptions(); $expected = 'all'; // Test $actual = $options->getBlockListType(); // Assert $this->assertEquals($expected, $actual); }
/** * Retrieves the list of blocks that have been uploaded as part of a block blob. * * There are two block lists maintained for a blob: * 1) Committed Block List: The list of blocks that have been successfully * committed to a given blob with commitBlobBlocks. * 2) Uncommitted Block List: The list of blocks that have been uploaded for a * blob using Put Block (REST API), but that have not yet been committed. * These blocks are stored in Windows Azure in association with a blob, but do * not yet form part of the blob. * * @param string $container name of the container * @param string $blob name of the blob * @param Models\ListBlobBlocksOptions $options optional parameters * * @return Models\ListBlobBlocksResult * * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179400.aspx */ public function listBlobBlocks($container, $blob, $options = null) { Validate::isString($container, 'container'); Validate::isString($blob, 'blob'); Validate::notNullOrEmpty($blob, 'blob'); $method = Resources::HTTP_GET; $headers = array(); $postParams = array(); $queryParams = array(); $path = $this->_createPath($container, $blob); $statusCode = Resources::STATUS_OK; if (is_null($options)) { $options = new ListBlobBlocksOptions(); } $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ID, $options->getLeaseId()); $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout()); $this->addOptionalQueryParam($queryParams, Resources::QP_BLOCK_LIST_TYPE, $options->getBlockListType()); $this->addOptionalQueryParam($queryParams, Resources::QP_SNAPSHOT, $options->getSnapshot()); $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'blocklist'); $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode); $parsed = $this->dataSerializer->unserialize($response->getBody()); return ListBlobBlocksResult::create($response->getHeader(), $parsed); }
/** * @covers WindowsAzure\Blob\BlobRestProxy::commitBlobBlocks * @covers WindowsAzure\Blob\BlobRestProxy::createBlobBlock * @covers WindowsAzure\Blob\BlobRestProxy::createBlockBlob * @covers WindowsAzure\Blob\BlobRestProxy::listBlobBlocks */ public function testCommitBlobBlocksWithArrayWorks() { // Act $container = self::$_test_container_for_blobs; $blob = 'test14a'; $blockId1 = '1fedcba'; $blockId2 = '2abcdef'; $blockId3 = '3zzzzzz'; $this->restProxy->createBlockBlob($container, $blob, ''); $this->restProxy->createBlobBlock($container, $blob, $blockId1, str_pad('', 256)); $this->restProxy->createBlobBlock($container, $blob, $blockId2, str_pad('', 512)); $this->restProxy->createBlobBlock($container, $blob, $blockId3, str_pad('', 195)); $block1 = new Block(); $block1->setBlockId($blockId1); $block1->setType(BlobBlockType::UNCOMMITTED_TYPE); $block3 = new Block(); $block3->setBlockId($blockId3); $block3->setType(BlobBlockType::LATEST_TYPE); $blockList = array($block1, $block3); $this->restProxy->commitBlobBlocks($container, $blob, $blockList); $opts = new ListBlobBlocksOptions(); $opts->setIncludeCommittedBlobs(true); $opts->setIncludeUncommittedBlobs(true); $result = $this->restProxy->listBlobBlocks($container, $blob, $opts); // Assert $this->assertNotNull($result, '$result'); $this->assertNotNull($result->getLastModified(), '$result->getLastModified()'); $this->assertNotNull($result->getETag(), '$result->getETag()'); $this->assertEquals(256 + 195, $result->getContentLength(), '$result->getContentLength()'); $this->assertNotNull($result->getCommittedBlocks(), '$result->getCommittedBlocks()'); $this->assertEquals(2, count($result->getCommittedBlocks()), 'count($result->getCommittedBlocks())'); $comblk = $result->getCommittedBlocks(); $keys = array_keys($comblk); $this->assertEquals($blockId1, $keys[0], '$keys[0]'); $this->assertEquals(256, $comblk[$keys[0]], '$comblk[$keys[0]]'); $this->assertEquals($blockId3, $keys[1], '$keys[1]'); $this->assertEquals(195, $comblk[$keys[1]], '$comblk[$keys[1]]'); $this->assertNotNull($result->getUncommittedBlocks(), '$result->getUncommittedBlocks()'); $this->assertEquals(0, count($result->getUncommittedBlocks()), 'count($result->getUncommittedBlocks())'); }