@Test public void testPageBlobDownloadRangeTest() throws URISyntaxException, StorageException, IOException { byte[] buffer = BlobTestHelper.getRandomBuffer(2 * 1024); CloudPageBlob blob = this.container.getPageBlobReference("blob1"); ByteArrayInputStream wholeBlob = new ByteArrayInputStream(buffer); blob.upload(wholeBlob, 2 * 1024); ByteArrayOutputStream blobStream = new ByteArrayOutputStream(); try { blob.downloadRange(0, new Long(0), blobStream); } catch (IndexOutOfBoundsException ex) { } blob.downloadRange(0, new Long(1024), blobStream); assertEquals(blobStream.size(), 1024); BlobTestHelper.assertStreamsAreEqualAtIndex(new ByteArrayInputStream(blobStream.toByteArray()), wholeBlob, 0, 0, 1024, 2 * 1024); CloudPageBlob blob2 = this.container.getPageBlobReference("blob1"); try { blob.downloadRange(1024, new Long(0), blobStream); } catch (IndexOutOfBoundsException ex) { } ByteArrayOutputStream blobStream2 = new ByteArrayOutputStream(); blob2.downloadRange(1024, new Long(1024), blobStream2); BlobTestHelper.assertStreamsAreEqualAtIndex(new ByteArrayInputStream(blobStream2.toByteArray()), wholeBlob, 1024, 1024, 1024, 2 * 1024); BlobTestHelper.assertAreEqual(blob, blob2); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testBlockBlobDownloadRangeTest() throws URISyntaxException, StorageException, IOException { byte[] buffer = BlobTestHelper.getRandomBuffer(2 * 1024); CloudBlockBlob blob = this.container.getBlockBlobReference("blob1"); ByteArrayInputStream wholeBlob = new ByteArrayInputStream(buffer); blob.upload(wholeBlob, -1); ByteArrayOutputStream blobStream = new ByteArrayOutputStream(); try { blob.downloadRange(0, new Long(0), blobStream, null, null, null); } catch (IndexOutOfBoundsException ex) { } blob.downloadRange(0, new Long(1024), blobStream); assertEquals(blobStream.size(), 1024); BlobTestHelper.assertStreamsAreEqualAtIndex(new ByteArrayInputStream(blobStream.toByteArray()), wholeBlob, 0, 0, 1024, 2 * 1024); CloudBlockBlob blob2 = this.container.getBlockBlobReference("blob1"); try { blob.downloadRange(1024, new Long(0), blobStream, null, null, null); } catch (IndexOutOfBoundsException ex) { } ByteArrayOutputStream blobStream2 = new ByteArrayOutputStream(); blob2.downloadRange(1024, new Long(1024), blobStream2); BlobTestHelper.assertStreamsAreEqualAtIndex(new ByteArrayInputStream(blobStream2.toByteArray()), wholeBlob, 1024, 1024, 1024, 2 * 1024); blob2.downloadAttributes(); BlobTestHelper.assertAreEqual(blob, blob2); }
@Test public void testAppendBlobDownloadRangeTest() throws URISyntaxException, StorageException, IOException { byte[] buffer = BlobTestHelper.getRandomBuffer(2 * 1024); CloudAppendBlob blob = this.container.getAppendBlobReference("blob1"); ByteArrayInputStream wholeBlob = new ByteArrayInputStream(buffer); BlobRequestOptions opt = new BlobRequestOptions(); opt.setStoreBlobContentMD5(false); blob.upload(wholeBlob, 2 * 1024, null, opt, null); ByteArrayOutputStream blobStream = new ByteArrayOutputStream(); try { blob.downloadRange(0, new Long(0), blobStream); } catch (IndexOutOfBoundsException ex) { } blob.downloadRange(0, new Long(1024), blobStream); assertEquals(blobStream.size(), 1024); BlobTestHelper.assertStreamsAreEqualAtIndex(new ByteArrayInputStream( blobStream.toByteArray()), wholeBlob, 0, 0, 1024, 2 * 1024); CloudAppendBlob blob2 = this.container.getAppendBlobReference("blob1"); try { blob.downloadRange(1024, new Long(0), blobStream); } catch (IndexOutOfBoundsException ex) { } ByteArrayOutputStream blobStream2 = new ByteArrayOutputStream(); blob2.downloadRange(1024, new Long(1024), blobStream2); BlobTestHelper.assertStreamsAreEqualAtIndex(new ByteArrayInputStream( blobStream2.toByteArray()), wholeBlob, 1024, 1024, 1024, 2 * 1024); BlobTestHelper.assertAreEqual(blob, blob2); }
public static void assertAreEqual(CloudBlob blob1, CloudBlob blob2) throws URISyntaxException, StorageException { if (blob1 == null) { assertNull(blob2); } else { assertNotNull(blob2); assertEquals(blob1.getClass(), blob2.getClass()); assertEquals(blob1.getUri(), blob2.getUri()); assertEquals(blob1.getSnapshotID(), blob2.getSnapshotID()); assertEquals(blob1.isSnapshot(), blob2.isSnapshot()); assertEquals(blob1.getSnapshotQualifiedStorageUri(), blob2.getSnapshotQualifiedStorageUri()); assertAreEqual(blob1.getProperties(), blob2.getProperties()); assertAreEqual(blob1.getCopyState(), blob2.getCopyState()); } }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testCloudBlobContainerReferenceFromServer() throws StorageException, URISyntaxException, IOException { this.container.create(); CloudBlob blob = BlobTestHelper.uploadNewBlob(this.container, BlobType.BLOCK_BLOB, null, 1024, null); blob.getProperties().setContentType("application/octet-stream"); blob.getProperties().setLength(1024); CloudBlob blobRef = this.container.getBlobReferenceFromServer(blob.getName()); BlobTestHelper.assertAreEqual(blob, blobRef); blob = BlobTestHelper.uploadNewBlob(this.container, BlobType.PAGE_BLOB, null, 1024, null); blob.getProperties().setContentType("application/octet-stream"); blob.getProperties().setLength(1024); blobRef = this.container.getBlobReferenceFromServer(blob.getName()); BlobTestHelper.assertAreEqual(blob, blobRef); blob = BlobTestHelper.uploadNewBlob(this.container, BlobType.APPEND_BLOB, null, 1024, null); blob.getProperties().setContentType("application/octet-stream"); blob.getProperties().setLength(1024); blobRef = this.container.getBlobReferenceFromServer(blob.getName()); BlobTestHelper.assertAreEqual(blob, blobRef); }
@Test public void testUploadDownloadBlobProperties() throws URISyntaxException, StorageException, IOException { final int length = 512; // do this to make sure the set MD5 can be compared without an exception being thrown BlobRequestOptions options = new BlobRequestOptions(); options.setDisableContentMD5Validation(true); // with explicit upload/download of properties String pageBlobName1 = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob"); CloudPageBlob pageBlobRef1 = this.container.getPageBlobReference(pageBlobName1); pageBlobRef1.upload(BlobTestHelper.getRandomDataStream(length), length); BlobTestHelper.setBlobProperties(pageBlobRef1); BlobProperties props1 = pageBlobRef1.getProperties(); pageBlobRef1.uploadProperties(); pageBlobRef1.downloadAttributes(null, options, null); BlobProperties props2 = pageBlobRef1.getProperties(); BlobTestHelper.assertAreEqual(props1, props2); // by uploading/downloading the blob pageBlobName1 = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob"); pageBlobRef1 = this.container.getPageBlobReference(pageBlobName1); BlobTestHelper.setBlobProperties(pageBlobRef1); props1 = pageBlobRef1.getProperties(); pageBlobRef1.upload(BlobTestHelper.getRandomDataStream(length), length); pageBlobRef1.download(new ByteArrayOutputStream(), null, options, null); props2 = pageBlobRef1.getProperties(); BlobTestHelper.assertAreEqual(props1, props2); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testCloudBlobContainerReferenceFromServerSnapshot() throws StorageException, URISyntaxException, IOException { this.container.create(); CloudBlob blob = BlobTestHelper.uploadNewBlob(this.container, BlobType.BLOCK_BLOB, null, 1024, null); CloudBlob snapshot = blob.createSnapshot(); snapshot.getProperties().setContentType("application/octet-stream"); snapshot.getProperties().setLength(1024); CloudBlob blobRef = this.container.getBlobReferenceFromServer(snapshot.getName(), snapshot.getSnapshotID(), null, null, null); BlobTestHelper.assertAreEqual(snapshot, blobRef); }
@Test @Category({ DevFabricTests.class, DevStoreTests.class }) public void testUploadDownloadBlobProperties() throws URISyntaxException, StorageException, IOException { final int length = 0; // do this to make sure the set MD5 can be compared without an exception being thrown BlobRequestOptions options = new BlobRequestOptions(); options.setDisableContentMD5Validation(true); // with explicit upload/download of properties String blockBlobName1 = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob"); CloudBlockBlob blockBlobRef1 = this.container.getBlockBlobReference(blockBlobName1); blockBlobRef1.upload(BlobTestHelper.getRandomDataStream(length), length); // this is not set by upload (it is for page blob!), so set this manually blockBlobRef1.getProperties().setLength(length); BlobTestHelper.setBlobProperties(blockBlobRef1); BlobProperties props1 = blockBlobRef1.getProperties(); blockBlobRef1.uploadProperties(); blockBlobRef1.downloadAttributes(null, options, null); BlobProperties props2 = blockBlobRef1.getProperties(); Assert.assertEquals(props1.getLength(), props2.getLength()); BlobTestHelper.assertAreEqual(props1, props2); // by uploading/downloading the blob blockBlobName1 = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob"); blockBlobRef1 = this.container.getBlockBlobReference(blockBlobName1); BlobTestHelper.setBlobProperties(blockBlobRef1); props1 = blockBlobRef1.getProperties(); blockBlobRef1.upload(BlobTestHelper.getRandomDataStream(length), length); blockBlobRef1.download(new ByteArrayOutputStream(), null, options, null); props2 = blockBlobRef1.getProperties(); BlobTestHelper.assertAreEqual(props1, props2); }
BlobProperties props2 = appendBlobRef1.getProperties(); BlobTestHelper.assertAreEqual(props1, props2); props2 = appendBlobRef1.getProperties(); BlobTestHelper.assertAreEqual(props1, props2);