/** * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::commitBlobBlocks * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createBlobBlock * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createBlockBlob * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::listBlobBlocks */ public function testCommitBlobBlocksWithArrayWorks() { // Act $container = self::$_test_container_for_blobs; $blob = 'test14a'; $blockId1 = base64_encode('1fedcba'); $blockId2 = base64_encode('2abcdef'); $blockId3 = base64_encode('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())'); }
/** * @covers MicrosoftAzure\Storage\Blob\Models\ListBlobBlocksOptions::getIncludeUncommittedBlobs */ public function testGetIncludeUncommittedBlobs() { // Setup $options = new ListBlobBlocksOptions(); $expected = true; $options->setIncludeUncommittedBlobs($expected); // Test $actual = $options->getIncludeUncommittedBlobs(); // Assert $this->assertEquals($expected, $actual); }
/** * @covers MicrosoftAzure\Storage\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))); }