|
33 | 33 | import com.microsoft.azure.storage.file.SharedAccessFilePermissions; |
34 | 34 | import com.microsoft.azure.storage.file.SharedAccessFilePolicy; |
35 | 35 |
|
36 | | -import junit.framework.Assert; |
37 | | - |
38 | 36 | import org.junit.After; |
39 | 37 | import org.junit.Before; |
40 | 38 | import org.junit.Test; |
|
60 | 58 | import java.util.Random; |
61 | 59 | import java.util.TimeZone; |
62 | 60 |
|
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; |
76 | 61 | import com.microsoft.azure.storage.StorageErrorCodeStrings; |
77 | | -import com.microsoft.azure.storage.StorageEvent; |
78 | | -import com.microsoft.azure.storage.StorageException; |
79 | 62 | import com.microsoft.azure.storage.TestRunners.CloudTests; |
80 | 63 | import com.microsoft.azure.storage.TestRunners.DevFabricTests; |
81 | 64 | import com.microsoft.azure.storage.TestRunners.DevStoreTests; |
82 | 65 | 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; |
90 | 66 |
|
91 | 67 | import static org.junit.Assert.*; |
92 | 68 |
|
@@ -1018,6 +994,44 @@ public void testLargeBlobUploadFromStreamTest() throws URISyntaxException, Stora |
1018 | 994 | blockBlobRef.download(dstStream); |
1019 | 995 | BlobTestHelper.assertStreamsAreEqual(srcStream, new ByteArrayInputStream(dstStream.toByteArray())); |
1020 | 996 | } |
| 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 | + } |
1021 | 1035 |
|
1022 | 1036 | @Test |
1023 | 1037 | @Category({ DevFabricTests.class, DevStoreTests.class }) |
@@ -1159,6 +1173,29 @@ public void testBlobUploadWithoutMD5Validation() throws URISyntaxException, Stor |
1159 | 1173 | assertEquals("MDAwMDAwMDA=", blockBlobRef2.properties.getContentMD5()); |
1160 | 1174 | } |
1161 | 1175 |
|
| 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 | + |
1162 | 1199 | @Test |
1163 | 1200 | @Category({ DevFabricTests.class, DevStoreTests.class }) |
1164 | 1201 | public void testBlockBlobUploadContentMD5() throws URISyntaxException, StorageException, IOException { |
@@ -1198,7 +1235,7 @@ public void eventOccurred(SendingRequestEvent eventArg) { |
1198 | 1235 | } |
1199 | 1236 | }; |
1200 | 1237 |
|
1201 | | - length = 33 * Constants.MB; |
| 1238 | + length = BlobConstants.DEFAULT_SINGLE_BLOB_PUT_THRESHOLD_IN_BYTES + 1; |
1202 | 1239 | srcStream = BlobTestHelper.getRandomDataStream(length); |
1203 | 1240 |
|
1204 | 1241 | sendingRequestEventContext.getSendingRequestEventHandler().addListener(event); |
@@ -1709,6 +1746,23 @@ public void testBlobConditionalAccess() throws StorageException, IOException, UR |
1709 | 1746 | newETag = blob.getProperties().getEtag(); |
1710 | 1747 | assertFalse("ETage should be modified on write metadata", newETag.equals(currentETag)); |
1711 | 1748 | } |
| 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 | + } |
1712 | 1766 |
|
1713 | 1767 | @Test |
1714 | 1768 | @Category({ DevFabricTests.class, DevStoreTests.class }) |
|
0 commit comments