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

Commit f31f31d

Browse files
author
jofriedm-msft
authored
Merge pull request #64 from jofriedm-msft/dev
Revert "Revert changes for version 5.1.0"
2 parents 5caeeda + 3ad35c2 commit f31f31d

31 files changed

+1403
-214
lines changed

BreakingChanges.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Changes in 5.1.1
1+
Changes in 5.1.1
22
OTHER
33
* Reverted the code from 5.1.0 because it contained a regression and an accidental change.
44

@@ -9,9 +9,9 @@ BLOB
99
* getQualifiedStorageUri() has been deprecated. Please use getSnapshotQualifiedStorageUri() instead. This new function will return the blob including the snapshot (if present) and no SAS token.
1010
* Fixed a bug where copying from a blob that included a SAS token and a snapshot did not use the SAS token.
1111

12-
FILE
12+
FILE
1313
* Fixed a bug where copying from a blob that included a SAS token and a snapshot did not use the SAS token.
14-
14+
1515
QUEUE
1616
* For addMessage() the CloudQueueMessage message passed in will be populated with the pop receipt, insertion/expiration time, and message ID.
1717

@@ -168,8 +168,8 @@ Changes in 0.5.0
168168

169169
OTHER
170170
* The packaging structure has changed to
171-
1. com.microsoft.windowsazure.storage � RetryPolicies, LocationMode, StorageException, Storage Credentials etc. Basically all public classes that are common across services.
172-
2. com.microsoft.windowsazure.storage.core � These classes are reserved for internal use and users never have to include this namespace in their projects.
171+
1. com.microsoft.windowsazure.storage � RetryPolicies, LocationMode, StorageException, Storage Credentials etc. Basically all public classes that are common across services.
172+
2. com.microsoft.windowsazure.storage.core � These classes are reserved for internal use and users never have to include this namespace in their projects.
173173
3. com.microsoft.windowsazure.storage.blob
174174
4. com.microsoft.windowsazure.storage.queue
175175
5. com.microsoft.windowsazure.storage.table

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#Microsoft Azure Storage SDK for Java
1+
# Microsoft Azure Storage SDK for Java
22

33
This project provides a client library in Java that makes it easy to consume Microsoft Azure Storage services. For documentation please see the Microsoft Azure [Java Developer Center](http://azure.microsoft.com/en-us/develop/java/) and the [JavaDocs](http://azure.github.io/azure-storage-java/).
44

55
> If you are looking for the Azure Storage Android SDK, please visit [https://github.com/Azure/azure-storage-android](https://github.com/Azure/azure-storage-android).
66
7-
#Features
7+
# Features
88
* Blob
99
* Create/Read/Update/Delete containers
1010
* Create/Read/Update/Delete blobs
@@ -19,10 +19,10 @@ This project provides a client library in Java that makes it easy to consume Mic
1919
* Batch operations
2020
* Advanced Table Operations
2121

22-
#Getting Started
22+
# Getting Started
2323

24-
##Download
25-
###Option 1: Via Maven
24+
## Download
25+
### Option 1: Via Maven
2626

2727
To get the binaries of this library as distributed by Microsoft, ready for use within your project, you can use Maven.
2828

@@ -34,19 +34,19 @@ To get the binaries of this library as distributed by Microsoft, ready for use w
3434
</dependency>
3535
```
3636

37-
###Option 2: Source Via Git
37+
### Option 2: Source Via Git
3838

3939
To get the source code of the SDK via git just type:
4040

4141
git clone git://github.com/Azure/azure-storage-java.git
42-
cd ./azure-storage-java/microsoft-azure-storage
42+
cd ./azure-storage-java
4343
mvn compile
4444

45-
###Option 3: Source Zip
45+
### Option 3: Source Zip
4646

4747
To download a copy of the source code, click "Download ZIP" on the right side of the page or click [here](https://github.com/Azure/azure-storage-java/archive/master.zip). Unzip and navigate to the microsoft-azure-storage folder.
4848

49-
##Minimum Requirements
49+
## Minimum Requirements
5050

5151
* Java 1.6+
5252
* [Jackson-Core](https://github.com/FasterXML/jackson-core) is used for JSON parsing.
@@ -58,13 +58,13 @@ The two dependencies, [Jackson-Core](https://github.com/FasterXML/jackson-core)
5858

5959
SLF4J is only needed if you enable logging through the OperationContext class. If you plan to use logging, please also download an [SLF4J binding](http://repo2.maven.org/maven2/org/slf4j/) which will link the SLF4J API with the logging implementation of your choice. Simple is a good default. See the [SLF4J user manual](http://www.slf4j.org/manual.html) for more information.
6060

61-
##Usage
61+
## Usage
6262

6363
To use this SDK to call Microsoft Azure storage services, you need to first [create an account](https://account.windowsazure.com/signup).
6464

6565
Samples are provided in the microsoft-azure-storage-samples folder. The unit tests in microsoft-azure-storage-test can also be helpful.
6666

67-
##Code Sample
67+
## Code Sample
6868

6969
The following is a quick example on how to upload a file to azure blob and download it back. You may also download and view the samples in the microsoft-azure-storage-samples folder. For additional information on using the client libraries to access Azure services see the How To guides for [blobs](http://azure.microsoft.com/en-us/documentation/articles/storage-java-how-to-use-blob-storage/), [queues](http://azure.microsoft.com/en-us/documentation/articles/storage-java-how-to-use-queue-storage/), [tables](http://azure.microsoft.com/en-us/documentation/articles/storage-java-how-to-use-table-storage/) and the [general documentation](http://azure.microsoft.com/en-us/develop/java/).
7070

@@ -117,17 +117,17 @@ public class BlobSample {
117117
}
118118
```
119119

120-
#Need Help?
120+
# Need Help?
121121

122122
Be sure to check out the Microsoft Azure [Developer Forums on MSDN](http://social.msdn.microsoft.com/Forums/windowsazure/en-US/home?forum=windowsazuredata) or the [Developer Forums on Stack Overflow](http://stackoverflow.com/questions/tagged/azure+windows-azure-storage) if you have trouble with the provided code.
123123

124-
#Contribute Code or Provide Feedback
124+
# Contribute Code or Provide Feedback
125125

126126
If you would like to become an active contributor to this project please follow the instructions provided in [Azure Projects Contribution Guidelines](http://azure.github.io/guidelines/).
127127

128128
If you encounter any bugs with the library please file an issue in the [Issues](https://github.com/Azure/azure-storage-java/issues) section of the project.
129129

130-
#Learn More
130+
# Learn More
131131

132132
* [Azure Developer Center](http://azure.microsoft.com/en-us/develop/java/)
133133
* [Azure Storage Service](http://azure.microsoft.com/en-us/documentation/services/storage/)

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.io.FileOutputStream;
2424
import java.io.IOException;
2525
import java.net.URISyntaxException;
26+
import java.nio.charset.Charset;
2627
import java.security.InvalidAlgorithmParameterException;
2728
import java.security.InvalidKeyException;
2829
import java.security.NoSuchAlgorithmException;
@@ -143,7 +144,41 @@ else if (type == BlobType.APPEND_BLOB) {
143144
TestHelper.assertStreamsAreEqualAtIndex(stream, new ByteArrayInputStream(outputStream.toByteArray()), 0, 0,
144145
size, 2 * 1024);
145146
}
146-
147+
148+
@Test
149+
public void testDownloadUnencryptedBlobWithEncryptionPolicy() throws StorageException, IOException, URISyntaxException, NoSuchAlgorithmException
150+
{
151+
String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("test");
152+
CloudBlockBlob blob = container.getBlockBlobReference(blobName);
153+
blob.deleteIfExists();
154+
155+
byte[] msg = "my message".getBytes();
156+
// Upload data without encryption
157+
blob.uploadFromByteArray(msg, 0, msg.length);
158+
159+
// Create options with encryption policy
160+
BlobRequestOptions options = new BlobRequestOptions();
161+
options.setEncryptionPolicy(new BlobEncryptionPolicy(new RsaKey("myKey", 1024), null));
162+
options.setRequireEncryption(true);
163+
164+
try {
165+
blob.downloadText(Charset.defaultCharset().name(), null, options, null);
166+
fail("Expect exception");
167+
}
168+
catch (StorageException e) {
169+
assertEquals(SR.ENCRYPTION_DATA_NOT_PRESENT_ERROR, e.getMessage());
170+
}
171+
172+
byte[] buffer = new byte[msg.length];
173+
try {
174+
blob.downloadRangeToByteArray(0, (long) buffer.length, buffer, 0, null, options, null);
175+
fail("Expect exception");
176+
}
177+
catch (StorageException e) {
178+
assertEquals(SR.ENCRYPTION_DATA_NOT_PRESENT_ERROR, e.getMessage());
179+
}
180+
}
181+
147182
@Test
148183
public void testBlobEncryptionWithFile() throws URISyntaxException, StorageException, IOException,
149184
InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,11 @@ public void testSingleBlobPutThresholdInBytes() throws URISyntaxException, Stora
247247
try {
248248
bClient.getDefaultRequestOptions().setSingleBlobPutThresholdInBytes(
249249
BlobConstants.MAX_SINGLE_UPLOAD_BLOB_SIZE_IN_BYTES + 1);
250-
fail("Cannot set upload blob threshold above 64 MB");
250+
fail("Cannot set upload blob threshold above 256 MB");
251251
}
252252
catch (IllegalArgumentException e) {
253253
assertEquals(
254-
"The argument is out of range. Argument name: singleBlobPutThresholdInBytes, Value passed: 67108865.",
254+
"The argument is out of range. Argument name: singleBlobPutThresholdInBytes, Value passed: 268435457.",
255255
e.getMessage());
256256
}
257257

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

Lines changed: 79 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import com.microsoft.azure.storage.file.SharedAccessFilePermissions;
3434
import com.microsoft.azure.storage.file.SharedAccessFilePolicy;
3535

36-
import junit.framework.Assert;
37-
3836
import org.junit.After;
3937
import org.junit.Before;
4038
import org.junit.Test;
@@ -60,33 +58,11 @@
6058
import java.util.Random;
6159
import java.util.TimeZone;
6260

63-
import org.junit.After;
64-
import org.junit.Before;
65-
import org.junit.Test;
66-
import org.junit.experimental.categories.Category;
67-
68-
import com.microsoft.azure.storage.AccessCondition;
69-
import com.microsoft.azure.storage.Constants;
70-
import com.microsoft.azure.storage.NameValidator;
71-
import com.microsoft.azure.storage.OperationContext;
72-
import com.microsoft.azure.storage.RetryNoRetry;
73-
import com.microsoft.azure.storage.SendingRequestEvent;
74-
import com.microsoft.azure.storage.StorageCredentialsAnonymous;
75-
import com.microsoft.azure.storage.StorageCredentialsSharedAccessSignature;
7661
import com.microsoft.azure.storage.StorageErrorCodeStrings;
77-
import com.microsoft.azure.storage.StorageEvent;
78-
import com.microsoft.azure.storage.StorageException;
7962
import com.microsoft.azure.storage.TestRunners.CloudTests;
8063
import com.microsoft.azure.storage.TestRunners.DevFabricTests;
8164
import com.microsoft.azure.storage.TestRunners.DevStoreTests;
8265
import com.microsoft.azure.storage.TestRunners.SlowTests;
83-
import com.microsoft.azure.storage.core.Utility;
84-
import com.microsoft.azure.storage.file.CloudFile;
85-
import com.microsoft.azure.storage.file.CloudFileShare;
86-
import com.microsoft.azure.storage.file.FileProperties;
87-
import com.microsoft.azure.storage.file.FileTestHelper;
88-
import com.microsoft.azure.storage.file.SharedAccessFilePermissions;
89-
import com.microsoft.azure.storage.file.SharedAccessFilePolicy;
9066

9167
import static org.junit.Assert.*;
9268

@@ -1018,6 +994,44 @@ public void testLargeBlobUploadFromStreamTest() throws URISyntaxException, Stora
1018994
blockBlobRef.download(dstStream);
1019995
BlobTestHelper.assertStreamsAreEqual(srcStream, new ByteArrayInputStream(dstStream.toByteArray()));
1020996
}
997+
998+
@Test
999+
@Category({ DevFabricTests.class, DevStoreTests.class, SlowTests.class })
1000+
public void testLargeSinglePutBlobTest() throws URISyntaxException, StorageException, IOException {
1001+
final String blockBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob");
1002+
final String blockBlobName2 = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob");
1003+
final String blockBlobName3 = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob");
1004+
final CloudBlockBlob blob = this.container.getBlockBlobReference(blockBlobName);
1005+
final CloudBlockBlob blob2 = this.container.getBlockBlobReference(blockBlobName2);
1006+
final CloudBlockBlob blob3 = this.container.getBlockBlobReference(blockBlobName3);
1007+
BlobRequestOptions options = new BlobRequestOptions();
1008+
options.setStoreBlobContentMD5(false);
1009+
options.setEncryptionPolicy(null);
1010+
try
1011+
{
1012+
byte[] buffer = BlobTestHelper.getRandomBuffer(256 * Constants.MB);
1013+
1014+
OperationContext operationContext = new OperationContext();
1015+
1016+
blob.uploadFromByteArray(buffer, 0, 128 * Constants.MB, null, null, operationContext);
1017+
assertEquals(1, operationContext.getRequestResults().size());
1018+
1019+
options.setSingleBlobPutThresholdInBytes(256 * Constants.MB);
1020+
blob2.uploadFromByteArray(buffer, 0, 256 * Constants.MB, null, options, operationContext);
1021+
assertEquals(1, operationContext.getRequestResults().size());
1022+
1023+
// Reduce threshold and upload data greater than the single put blob upload threshold
1024+
options.setSingleBlobPutThresholdInBytes(Constants.MB);
1025+
blob3.uploadFromByteArray(buffer, 0, 3 * Constants.MB, null, options, operationContext);
1026+
assertTrue(operationContext.getRequestResults().size() > 1);
1027+
}
1028+
finally
1029+
{
1030+
blob.delete();
1031+
blob2.delete();
1032+
blob3.delete();
1033+
}
1034+
}
10211035

10221036
@Test
10231037
@Category({ DevFabricTests.class, DevStoreTests.class })
@@ -1159,6 +1173,29 @@ public void testBlobUploadWithoutMD5Validation() throws URISyntaxException, Stor
11591173
assertEquals("MDAwMDAwMDA=", blockBlobRef2.properties.getContentMD5());
11601174
}
11611175

1176+
@Test
1177+
@Category({ DevFabricTests.class, DevStoreTests.class })
1178+
public void testVerifyTransactionalMD5ValidationMissingOverallMD5() throws URISyntaxException, StorageException, IOException {
1179+
final String blockBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testBlockBlob");
1180+
final CloudBlockBlob blockBlobRef = this.container.getBlockBlobReference(blockBlobName);
1181+
1182+
final int length = 2 * 1024 * 1024;
1183+
ByteArrayInputStream srcStream = BlobTestHelper.getRandomDataStream(length);
1184+
BlobRequestOptions options = new BlobRequestOptions();
1185+
options.setSingleBlobPutThresholdInBytes(1024*1024);
1186+
options.setDisableContentMD5Validation(true);
1187+
options.setStoreBlobContentMD5(false);
1188+
1189+
blockBlobRef.upload(srcStream, -1, null, options, null);
1190+
1191+
options.setDisableContentMD5Validation(false);
1192+
options.setStoreBlobContentMD5(true);
1193+
options.setUseTransactionalContentMD5(true);
1194+
final CloudBlockBlob blockBlobRef2 = this.container.getBlockBlobReference(blockBlobName);
1195+
blockBlobRef2.downloadRange(1024, (long)1024, new ByteArrayOutputStream(), null, options, null);
1196+
assertNull(blockBlobRef2.getProperties().getContentMD5());
1197+
}
1198+
11621199
@Test
11631200
@Category({ DevFabricTests.class, DevStoreTests.class })
11641201
public void testBlockBlobUploadContentMD5() throws URISyntaxException, StorageException, IOException {
@@ -1198,7 +1235,7 @@ public void eventOccurred(SendingRequestEvent eventArg) {
11981235
}
11991236
};
12001237

1201-
length = 33 * Constants.MB;
1238+
length = BlobConstants.DEFAULT_SINGLE_BLOB_PUT_THRESHOLD_IN_BYTES + 1;
12021239
srcStream = BlobTestHelper.getRandomDataStream(length);
12031240

12041241
sendingRequestEventContext.getSendingRequestEventHandler().addListener(event);
@@ -1709,6 +1746,23 @@ public void testBlobConditionalAccess() throws StorageException, IOException, UR
17091746
newETag = blob.getProperties().getEtag();
17101747
assertFalse("ETage should be modified on write metadata", newETag.equals(currentETag));
17111748
}
1749+
1750+
@Test
1751+
public void testBlobExceedMaxRange() throws URISyntaxException, StorageException, IOException
1752+
{
1753+
CloudBlockBlob blob = container.getBlockBlobReference("blockblob4");
1754+
blob.deleteIfExists();
1755+
1756+
byte[] msg = "my message".getBytes("UTF-8");
1757+
blob.uploadFromByteArray(msg, 0, msg.length);
1758+
1759+
byte[] buffer = new byte[msg.length + 5];
1760+
1761+
blob.downloadRangeToByteArray(0, (long) buffer.length, buffer, 0, null, null, null);
1762+
String expected = new String (msg, "UTF-8");
1763+
String actual = new String(buffer, "UTF-8").substring(0, 10);
1764+
assertEquals(expected, actual);
1765+
}
17121766

17131767
@Test
17141768
@Category({ DevFabricTests.class, DevStoreTests.class })

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,32 @@ public void testPageBlobDownloadRangeValidationTest() throws StorageException, U
211211
assertEquals(100, downloadLength);
212212
}
213213

214+
/**
215+
* Test requesting stored content MD5 with OpenWriteExisting().
216+
*
217+
* @throws URISyntaxException
218+
* @throws StorageException
219+
*/
220+
@Test
221+
public void testPageOpenWriteExistingWithMD5() throws URISyntaxException, StorageException, IOException {
222+
final String pageBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testPageBlob");
223+
final CloudPageBlob pageBlobRef = this.container.getPageBlobReference(pageBlobName);
224+
pageBlobRef.create(512);
225+
226+
BlobRequestOptions options = new BlobRequestOptions();
227+
options.setStoreBlobContentMD5(true);
228+
options.setDisableContentMD5Validation(false);
229+
230+
try
231+
{
232+
pageBlobRef.openWriteExisting(null, options, null);
233+
fail("Expect failure due to requesting MD5 calculation");
234+
}
235+
catch (IllegalArgumentException e)
236+
{
237+
}
238+
}
239+
214240
@Test
215241
public void testPageBlobUploadFromStreamTest() throws URISyntaxException, StorageException, IOException {
216242
final String pageBlobName = BlobTestHelper.generateRandomBlobNameWithPrefix("testPageBlob");

0 commit comments

Comments
 (0)