@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 public void testPageBlobUploadFromStreamTest() throws URISyntaxException, StorageException, IOException { final String pageBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testPageBlob"); final CloudPageBlob pageBlobRef = this.container.getPageBlobReference(pageBlobName); int length = 2 * 1024; ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length); pageBlobRef.upload(srcStream, length); ByteArrayOutputStream dstStream = new ByteArrayOutputStream(); pageBlobRef.download(dstStream); BlobTestHelper.assertStreamsAreEqual(srcStream, new ByteArrayInputStream(dstStream.toByteArray())); length = 5 * 1024 * 1024; srcStream = BlobTestHelper.getRandomDataStream(length); pageBlobRef.upload(srcStream, length); dstStream = new ByteArrayOutputStream(); pageBlobRef.download(dstStream); BlobTestHelper.assertStreamsAreEqual(srcStream, new ByteArrayInputStream(dstStream.toByteArray())); }
@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 public void testCloudPageBlobDownloadRangeToByteArrayNegativeTest() throws URISyntaxException, StorageException, IOException { CloudPageBlob blob = this.container.getPageBlobReference(BlobTestHelper .generateRandomBlobNameWithPrefix("downloadrangenegative")); BlobTestHelper.doDownloadRangeToByteArrayNegativeTests(blob); }
@Test public void testCloudPageBlobDownloadRangeToByteArray() throws URISyntaxException, StorageException, IOException { CloudPageBlob blob = this.container.getPageBlobReference(BlobTestHelper .generateRandomBlobNameWithPrefix("downloadrange")); BlobTestHelper.doDownloadRangeToByteArrayTest(blob, 8 * 1024 * 1024, 8 * 1024 * 1024, 1 * 1024 * 1024, new Long(1 * 1024 * 1024), new Long(5 * 1024 * 1024)); BlobTestHelper.doDownloadRangeToByteArrayTest(blob, 8 * 1024 * 1024, 8 * 1024 * 1024, 2 * 1024 * 1024, new Long(2 * 1024 * 1024), new Long(6 * 1024 * 1024)); BlobTestHelper.doDownloadRangeToByteArrayTest(blob, 8 * 1024 * 1024, 8 * 1024 * 1024, 1 * 1024 * 1024, new Long(4 * 1024 * 1024), new Long(4 * 1024 * 1024)); BlobTestHelper.doDownloadRangeToByteArrayTest(blob, 2 * 512, 4 * 512, 0, new Long(1 * 512), new Long(1 * 512)); BlobTestHelper.doDownloadRangeToByteArrayTest(blob, 2 * 512, 4 * 512, 1 * 512, new Long(0), null); BlobTestHelper.doDownloadRangeToByteArrayTest(blob, 2 * 512, 4 * 512, 1 * 512, new Long(1 * 512), null); BlobTestHelper.doDownloadRangeToByteArrayTest(blob, 2 * 512, 4 * 512, 1 * 512, new Long(0), new Long(1 * 512)); BlobTestHelper.doDownloadRangeToByteArrayTest(blob, 2 * 512, 4 * 512, 2 * 512, new Long(1 * 512), new Long( 1 * 512)); BlobTestHelper.doDownloadRangeToByteArrayTest(blob, 2 * 512, 4 * 512, 2 * 512, new Long(1 * 512), new Long( 2 * 512)); // Edge cases BlobTestHelper.doDownloadRangeToByteArrayTest(blob, 1024, 1024, 1023, new Long(1023), new Long(1)); BlobTestHelper.doDownloadRangeToByteArrayTest(blob, 1024, 1024, 0, new Long(1023), new Long(1)); BlobTestHelper.doDownloadRangeToByteArrayTest(blob, 1024, 1024, 0, new Long(0), new Long(1)); BlobTestHelper.doDownloadRangeToByteArrayTest(blob, 1024, 1024, 0, new Long(512), new Long(1)); BlobTestHelper.doDownloadRangeToByteArrayTest(blob, 1024, 1024, 512, new Long(1023), new Long(1)); }
private static CloudBlobContainer createContainer(String delimiter) throws URISyntaxException, StorageException { CloudBlobClient client = BlobTestHelper.createCloudBlobClient(); client.setDirectoryDelimiter(delimiter); String name = BlobTestHelper.generateRandomContainerName(); CloudBlobContainer container = client.getContainerReference(name); container.create(); return container; } }
CloudPageBlob source = this.container.getPageBlobReference("source"); byte[] buffer = BlobTestHelper.getRandomBuffer(512); ByteArrayInputStream stream = new ByteArrayInputStream(buffer); byte[] buffer2 = BlobTestHelper.getRandomBuffer(512); ByteArrayInputStream stream2 = new ByteArrayInputStream(buffer2); source.getMetadata().put("Test", "newvalue"); BlobTestHelper.assertStreamsAreEqual(stream2, new ByteArrayInputStream(outputStream.toByteArray())); BlobTestHelper.assertStreamsAreEqual(stream, new ByteArrayInputStream(snapshotStream.toByteArray())); String copyId = copy.startCopy(BlobTestHelper.defiddler(snapshot)); BlobTestHelper.waitForCopy(copy); BlobTestHelper.assertStreamsAreEqual(stream, new ByteArrayInputStream(copyStream.toByteArray())); assertEquals(copyId, copy.getProperties().getCopyState().getCopyId());
@Test public void testBlobEmptyHeaderSigningTest() throws URISyntaxException, StorageException, IOException { final String pageBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testPageBlob"); final CloudPageBlob pageBlobRef = this.container.getPageBlobReference(pageBlobName); final int length = 2 * 1024; ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length); OperationContext context = new OperationContext(); context.getSendingRequestEventHandler().addListener(new StorageEvent<SendingRequestEvent>() { @Override public void eventOccurred(SendingRequestEvent eventArg) { HttpURLConnection connection = (HttpURLConnection) eventArg.getConnectionObject(); connection.setRequestProperty("x-ms-foo", ""); } }); pageBlobRef.upload(srcStream, length, null, null, context); pageBlobRef.download(new ByteArrayOutputStream(), null, null, context); }
@Test public void testPageBlobCopyWithSasAndSnapshot() throws URISyntaxException, StorageException, InterruptedException, IOException, InvalidKeyException { String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob"); CloudPageBlob source = this.container.getPageBlobReference(blobName); source.create(1024); byte[] buffer = BlobTestHelper.getRandomBuffer(512); ByteArrayInputStream stream = new ByteArrayInputStream(buffer); source.upload(stream, buffer.length); sasBlob.exists(); String copyId = copySas.startCopy(BlobTestHelper.defiddler(sasBlob)); BlobTestHelper.waitForCopy(copySas);
private CloudPageBlob setUpPageRanges() throws StorageException, URISyntaxException, IOException { int blobLengthToUse = 8 * 512; byte[] buffer = BlobTestHelper.getRandomBuffer(blobLengthToUse); String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob"); final CloudPageBlob blobRef = this.container.getPageBlobReference(blobName); blobRef.create(blobLengthToUse); // Upload page 0 ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer); blobRef.uploadPages(inputStream, 0, 512); // Upload pages 2-4 inputStream = new ByteArrayInputStream(buffer, 512, 3 * 512); blobRef.uploadPages(inputStream, 2 * 512, 3 * 512); // Upload page 6 inputStream = new ByteArrayInputStream(buffer, 3 * 512, 512); blobRef.uploadPages(inputStream, 6 * 512, 512); // Page0: 512 bytes should be the first 512 bytes of the random buffer (page 0) // Page1: 512 bytes should be 0 // Page2-4: 3 * 512 bytes should be equal to bytes (512 -> 4 * 512) of the random buffer (pages 2-4) // Page5: 512 bytes should be 0 // Page6: 512 bytes should be the 4th 512 byte segmented of the random buffer // Page7-8: 2 * 512 bytes should be 0 return blobRef; }
public static Map<String, BlockEntry> getBlockEntryList(int count) { Map<String, BlockEntry> blocks = new HashMap<String, BlockEntry>(); for (int i = 0; i < count; i++) { final String name = generateRandomBlobNameWithPrefix(null); blocks.put(name, new BlockEntry(name, BlockSearchMode.LATEST)); } return blocks; }
@Test @Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) public void testSingleBlobPutThresholdInBytes() throws URISyntaxException, StorageException, IOException { CloudBlobClient bClient = BlobTestHelper.createCloudBlobClient(); container = bClient.getContainerReference(BlobTestHelper.generateRandomContainerName()); container.createIfNotExists(); CloudBlockBlob blob = container.getBlockBlobReference(BlobTestHelper .generateRandomBlobNameWithPrefix("uploadThreshold")); blob.upload(BlobTestHelper.getRandomDataStream(maxSize - 1), maxSize - 1, null, null, sendingRequestEventContext); blob.upload(BlobTestHelper.getRandomDataStream(maxSize), maxSize, null, null, sendingRequestEventContext); blob.upload(BlobTestHelper.getRandomDataStream(maxSize + 1), maxSize + 1, null, null, sendingRequestEventContext);
@Test public void testFileCopyFromBlobWithSasAndSnapshot() throws URISyntaxException, StorageException, InterruptedException, IOException, InvalidKeyException { String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob"); CloudBlobContainer container = TestHelper.createCloudBlobClient().getContainerReference(BlobTestHelper.generateRandomContainerName()); container.createIfNotExists(); CloudBlockBlob source = container.getBlockBlobReference(blobName); source.uploadText(data, Constants.UTF8_CHARSET, null, null, null); byte[] buffer = BlobTestHelper.getRandomBuffer(512); ByteArrayInputStream stream = new ByteArrayInputStream(buffer); source.upload(stream, buffer.length); sasBlob.exists(); String copyId = copySas.startCopy(BlobTestHelper.defiddler(sasBlob)); FileTestHelper.waitForCopy(copySas);
CloudBlockBlob source = this.container.getBlockBlobReference("source"); BlobTestHelper.setBlobProperties(source); String copyId = copy.startCopy(BlobTestHelper.defiddler(source)); BlobTestHelper.waitForCopy(copy);
this.container.create(); String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testblob"); CloudPageBlob source = this.container.getPageBlobReference(blobName); source.create(1024); builder.add(Constants.QueryConstants.SNAPSHOT, sasSnapshotBlob.snapshotID); copy.startIncrementalCopy(BlobTestHelper.defiddler(sasSnapshotBlob)); BlobTestHelper.waitForCopy(copy);
@Test @Category(SlowTests.class) public void testCopyPageBlobSas() throws Exception { // Create source on server. final CloudBlobContainer container = BlobTestHelper.getRandomContainerReference(); try { container.create(); final CloudPageBlob source = container.getPageBlobReference("source"); source.getMetadata().put("Test", "value"); final int length = 512; final ByteArrayInputStream data = BlobTestHelper.getRandomDataStream(length); source.upload(data, length); final CloudFile destination = doCloudBlobCopy(source, length); final ByteArrayOutputStream copyData = new ByteArrayOutputStream(); destination.download(copyData); BlobTestHelper.assertStreamsAreEqual(data, new ByteArrayInputStream(copyData.toByteArray())); } finally { container.deleteIfExists(); } }
public void testCommitBlockListContentMd5() throws URISyntaxException, StorageException, IOException { int length = 1024; byte[] buffer = BlobTestHelper.getRandomBuffer(length); Map<String, BlockEntry> blocks = BlobTestHelper.getBlockEntryList(3); String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("blob1");
@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); }
/** * Try to list the containers to ensure maxResults validation is working. * * @throws StorageException * @throws URISyntaxException */ @Test @Category({ DevFabricTests.class, DevStoreTests.class, CloudTests.class }) public void testListContainersMaxResultsValidation() throws StorageException, URISyntaxException { CloudBlobClient bClient = BlobTestHelper.createCloudBlobClient(); String prefix = UUID.randomUUID().toString(); // Validation should cause each of these to fail. for(int i = 0; i >= -2; i--) { try { bClient.listContainersSegmented( prefix, ContainerListingDetails.ALL, i, null, null, null); fail(); } catch (IllegalArgumentException e) { assertTrue(String.format(SR.PARAMETER_SHOULD_BE_GREATER_OR_EQUAL, "maxResults", 1) .equals(e.getMessage())); } } assertNotNull(bClient.listContainersSegmented("thereshouldntbeanycontainersswiththisprefix")); }
@Before public void blobEncryptionTestMethodSetup() throws URISyntaxException, StorageException, IOException { this.container = BlobTestHelper.getRandomContainerReference(); this.container.create(); this.blob = this.container.getBlockBlobReference(BlobTestHelper.generateRandomBlobNameWithPrefix("testBlob")); this.blob.uploadText("test"); }