Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit 4c61a4d

Browse files
authored
Allow openInputStream to succeed on blob snapshots (#255)
Allow openInputStream to succeed on blob snapshots
1 parent 7c26405 commit 4c61a4d

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

ChangeLog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ XXXX.XX.XX Version X.X.X
22
* Improved performance of blob uploadFromFile APIs to avoid unnecessary buffering.
33
* Improved performance when streaming directly from a FileInputStream to avoid unnecessary buffering.
44
* Switched to using fixed length streaming mode in the HTTP client to avoid unnecessary buffering.
5+
* Fixed a bug preventing openInputStream from working on a blob snapshot.
56

67
2017.11.01 Version 6.1.0
78
* Added support for the last time the tier was modified.

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlockBlobTests.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.io.FileInputStream;
4545
import java.io.FileOutputStream;
4646
import java.io.IOException;
47+
import java.io.InputStream;
4748
import java.net.HttpURLConnection;
4849
import java.net.URI;
4950
import java.net.URISyntaxException;
@@ -657,6 +658,10 @@ public void testBlobSnapshotValidationTest() throws StorageException, URISyntaxE
657658
byte[] retrievedBuff = outStream.toByteArray();
658659
assertEquals(length, retrievedBuff.length);
659660

661+
InputStream inputStream = blobSnapshot.openInputStream();
662+
retrievedBuff = inputStream.readAllBytes();
663+
assertEquals(length, retrievedBuff.length);
664+
660665
// Read operation should work fine.
661666
blobSnapshot.downloadAttributes();
662667

@@ -667,6 +672,11 @@ public void testBlobSnapshotValidationTest() throws StorageException, URISyntaxE
667672
blobSnapshotUsingRootUri.download(outStream);
668673
retrievedBuff = outStream.toByteArray();
669674
assertEquals(length, retrievedBuff.length);
675+
676+
inputStream = blobSnapshotUsingRootUri.openInputStream();
677+
retrievedBuff = inputStream.readAllBytes();
678+
assertEquals(length, retrievedBuff.length);
679+
670680
assertEquals(blobSnapshot.getSnapshotID(), blobSnapshotUsingRootUri.getSnapshotID());
671681

672682
// Expect an IllegalArgumentException from upload.
@@ -707,6 +717,33 @@ public void testBlobSnapshotValidationTest() throws StorageException, URISyntaxE
707717
catch (IllegalArgumentException e) {
708718
assertEquals("Cannot perform this operation on a blob representing a snapshot.", e.getMessage());
709719
}
720+
721+
// Expect an IllegalArgumentException from openOutputStream.
722+
try {
723+
blobSnapshotUsingRootUri.openOutputStream();
724+
fail("Expect an IllegalArgumentException from openOutputStream");
725+
}
726+
catch (IllegalArgumentException e) {
727+
assertEquals("Cannot perform this operation on a blob representing a snapshot.", e.getMessage());
728+
}
729+
730+
// Expect an IllegalArgumentException from uploadBlock.
731+
try {
732+
blobSnapshotUsingRootUri.uploadBlock("foo", new ByteArrayInputStream(new byte[0]), 0);
733+
fail("Expect an IllegalArgumentException from uploadBlock");
734+
}
735+
catch (IllegalArgumentException e) {
736+
assertEquals("Cannot perform this operation on a blob representing a snapshot.", e.getMessage());
737+
}
738+
739+
// Expect an IllegalArgumentException from commitBlockList.
740+
try {
741+
blobSnapshotUsingRootUri.commitBlockList(new ArrayList<BlockEntry>());
742+
fail("Expect an IllegalArgumentException from commitBlockList");
743+
}
744+
catch (IllegalArgumentException e) {
745+
assertEquals("Cannot perform this operation on a blob representing a snapshot.", e.getMessage());
746+
}
710747
}
711748

712749
/**

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlob.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,8 +2375,6 @@ public final BlobInputStream openInputStream(final AccessCondition accessConditi
23752375
opContext = new OperationContext();
23762376
}
23772377

2378-
assertNoWriteOperationForSnapshot();
2379-
23802378
options = BlobRequestOptions.populateAndApplyDefaults(options, this.properties.getBlobType(), this.blobServiceClient,
23812379
false /* setStartTime */);
23822380

0 commit comments

Comments
 (0)