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

Commit 35124bb

Browse files
Ram BJosh Friedman
authored andcommitted
Constant fixes + testcases fo range md5.
1 parent 465e8b6 commit 35124bb

File tree

6 files changed

+62
-3
lines changed

6 files changed

+62
-3
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,26 @@ public void testBlobConditionalAccess() throws StorageException, IOException, UR
17101710
assertFalse("ETage should be modified on write metadata", newETag.equals(currentETag));
17111711
}
17121712

1713+
@Test
1714+
@Category({ DevFabricTests.class, DevStoreTests.class })
1715+
public void testBlobGetRangeContentMD5Bounds() throws StorageException, IOException, URISyntaxException {
1716+
{
1717+
CloudBlockBlob blob = (CloudBlockBlob) BlobTestHelper.uploadNewBlob(this.container, BlobType.BLOCK_BLOB,
1718+
"test", 5 * Constants.MB, null);
1719+
BlobRequestOptions options = new BlobRequestOptions();
1720+
OperationContext opContext = new OperationContext();
1721+
try {
1722+
BlobRequest.getBlob(blob.getUri(), options, opContext, null, "", 0L, 4L * Constants.MB, true);
1723+
BlobRequest.getBlob(blob.getUri(), options, opContext, null, "", 0L, 4L * Constants.MB + 1, true);
1724+
fail("The request for range ContentMD5 should have thrown an Exception for exceeding the limit.");
1725+
}
1726+
catch (IllegalArgumentException e)
1727+
{
1728+
assertEquals(e.getMessage(), String.format("The value of the parameter 'count' should be between 1 and %1d.", Constants.MAX_RANGE_CONTENT_MD5));
1729+
}
1730+
}
1731+
}
1732+
17131733
private void doUploadDownloadStringTest(CloudBlockBlob blob, int length) throws StorageException, IOException {
17141734
String stringToUse = this.getRandomUNCString(length);
17151735
blob.uploadText(stringToUse, Constants.UTF8_CHARSET, null, null, null);

microsoft-azure-storage-test/src/com/microsoft/azure/storage/file/CloudFileTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,26 @@ public void testFileNamePlusEncoding() throws StorageException, URISyntaxExcepti
13871387
assertEquals(prop1.getContentMD5(), prop2.getContentMD5());
13881388
assertEquals(prop1.getContentType(), prop2.getContentType());
13891389
}
1390+
1391+
@Test
1392+
@Category({ DevFabricTests.class, DevStoreTests.class })
1393+
public void testFileGetRangeContentMD5Bounds() throws StorageException, IOException, URISyntaxException {
1394+
{
1395+
CloudFile file = FileTestHelper.uploadNewFile(this.share, 5 * Constants.MB, null);
1396+
1397+
FileRequestOptions options = new FileRequestOptions();
1398+
OperationContext opContext = new OperationContext();
1399+
try {
1400+
FileRequest.getFile(file.getUri(), options, opContext, null, 0L, 4L * Constants.MB, true);
1401+
FileRequest.getFile(file.getUri(), options, opContext, null, 0L, 4L * Constants.MB + 1, true);
1402+
fail("The request for range ContentMD5 should have thrown an Exception for exceeding the limit.");
1403+
}
1404+
catch (IllegalArgumentException e)
1405+
{
1406+
assertEquals(e.getMessage(), String.format("The value of the parameter 'count' should be between 1 and %1d.", Constants.MAX_RANGE_CONTENT_MD5));
1407+
}
1408+
}
1409+
}
13901410

13911411
private CloudFile doCloudBlobCopy(CloudBlob source, int length) throws Exception {
13921412
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));

microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,11 @@ public static class QueryConstants {
11091109
*/
11101110
public static final String MARKER_ELEMENT = "Marker";
11111111

1112+
/**
1113+
* The maximum size for Range ContentMD5.
1114+
*/
1115+
public static int MAX_RANGE_CONTENT_MD5 = 4 * MB;
1116+
11121117
/**
11131118
* The maximum size of a BlockBlob block.
11141119
*/
@@ -1167,7 +1172,7 @@ public static class QueryConstants {
11671172
/**
11681173
* The default minimum read size, in bytes, for a {@link BlobInputStream} or {@link FileInputStream}.
11691174
*/
1170-
public static final int DEFAULT_MINIMUM_READ_SIZE_IN_BYTES = Constants.MAX_BLOCK_SIZE;
1175+
public static final int DEFAULT_MINIMUM_READ_SIZE_IN_BYTES = 4 * Constants.MB;
11711176

11721177
/**
11731178
* The maximum size, in bytes, of a given stream mark operation.

microsoft-azure-storage/src/com/microsoft/azure/storage/SubStreamGenerator.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/**
2+
* Copyright Microsoft Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
115
package com.microsoft.azure.storage;
216

317
import com.microsoft.azure.storage.blob.SubStream;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ public static HttpURLConnection getBlob(final URI uri, final BlobRequestOptions
489489

490490
if (offset != null && requestRangeContentMD5) {
491491
Utility.assertNotNull("count", count);
492-
Utility.assertInBounds("count", count, 1, Constants.MAX_BLOCK_SIZE);
492+
Utility.assertInBounds("count", count, 1, Constants.MAX_RANGE_CONTENT_MD5);
493493
}
494494

495495
final UriQueryBuilder builder = new UriQueryBuilder();

microsoft-azure-storage/src/com/microsoft/azure/storage/file/FileRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public static HttpURLConnection getFile(final URI uri, final FileRequestOptions
350350

351351
if (offset != null && requestRangeContentMD5) {
352352
Utility.assertNotNull("count", count);
353-
Utility.assertInBounds("count", count, 1, Constants.MAX_BLOCK_SIZE);
353+
Utility.assertInBounds("count", count, 1, Constants.MAX_RANGE_CONTENT_MD5);
354354
}
355355

356356
final UriQueryBuilder builder = new UriQueryBuilder();

0 commit comments

Comments
 (0)