diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java index 0eab682c039d0..d4aa9c7c5a7dc 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobAsyncClient.java @@ -526,11 +526,20 @@ buffers is not a common scenario for async like it is in sync (and we already bu (stream, length) -> uploadFullBlob(blockBlobAsyncClient, stream, length, parallelTransferOptions, headers, metadata, tags, tier, requestConditions, computeMd5); - Flux data = options.getDataFlux() == null ? Utility.convertStreamToByteBuffer( - options.getDataStream(), options.getLength(), + Flux data = options.getDataFlux(); + // no specified length: use azure.core's converter + if (data == null && options.getOptionalLength() == null) { // We can only buffer up to max int due to restrictions in ByteBuffer. - (int) Math.min(Integer.MAX_VALUE, parallelTransferOptions.getBlockSizeLong()), false) - : options.getDataFlux(); + int chunkSize = (int) Math.min(Integer.MAX_VALUE, parallelTransferOptions.getBlockSizeLong()); + data = FluxUtil.toFluxByteBuffer(options.getDataStream(), chunkSize); + // specified length (legacy requirement): use custom converter. no marking because we buffer anyway. + } else if (data == null) { + // We can only buffer up to max int due to restrictions in ByteBuffer. + int chunkSize = (int) Math.min(Integer.MAX_VALUE, parallelTransferOptions.getBlockSizeLong()); + data = Utility.convertStreamToByteBuffer( + options.getDataStream(), options.getOptionalLength(), chunkSize, false); + } + return UploadUtils.uploadFullOrChunked(data, ModelHelper.wrapBlobOptions(parallelTransferOptions), uploadInChunksFunction, uploadFullBlobFunction); } catch (RuntimeException ex) { diff --git a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/options/BlobParallelUploadOptions.java b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/options/BlobParallelUploadOptions.java index b4825c1b2a0bb..ed246e2266bee 100644 --- a/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/options/BlobParallelUploadOptions.java +++ b/sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/options/BlobParallelUploadOptions.java @@ -26,7 +26,7 @@ public class BlobParallelUploadOptions { private final Flux dataFlux; private final InputStream dataStream; - private final long length; + private final Long length; private ParallelTransferOptions parallelTransferOptions; private BlobHttpHeaders headers; private Map metadata; @@ -37,7 +37,7 @@ public class BlobParallelUploadOptions { private Duration timeout; /** - * Constructs a new {@code BlobParallelUploadOptions}. + * Constructs a new {@link BlobParallelUploadOptions}. * * @param dataFlux The data to write to the blob. Unlike other upload methods, this method does not require that * the {@code Flux} be replayable. In other words, it does not have to support multiple subscribers and is not @@ -47,25 +47,48 @@ public BlobParallelUploadOptions(Flux dataFlux) { StorageImplUtils.assertNotNull("dataFlux", dataFlux); this.dataFlux = dataFlux; this.dataStream = null; - this.length = -1; + this.length = null; } /** - * Constructs a new {@code BlobParalleUploadOptions}. + * Constructs a new {@link BlobParallelUploadOptions}. + * + * Use {@link #BlobParallelUploadOptions(InputStream)} instead to supply an InputStream without knowing the exact + * length beforehand. * - * @param dataStream The data to write to the blob. The data must be markable. This is in order to support retries. - * If the data is not markable, consider opening a {@link com.azure.storage.blob.specialized.BlobOutputStream} and - * writing to the returned stream. Alternatively, consider wrapping your data source in a - * {@link java.io.BufferedInputStream} to add mark support. + * @param dataStream The data to write to the blob. * @param length The exact length of the data. It is important that this value match precisely the length of the * data provided in the {@link InputStream}. + * @deprecated length is no longer necessary; use {@link #BlobParallelUploadOptions(InputStream)} instead. */ + @Deprecated public BlobParallelUploadOptions(InputStream dataStream, long length) { + this(dataStream, Long.valueOf(length)); + } + + /** + * Constructs a new {@link BlobParallelUploadOptions}. + * + * @param dataStream The data to write to the blob. + */ + public BlobParallelUploadOptions(InputStream dataStream) { + this(dataStream, null); + } + + /** + * Common constructor for building options from InputStream. + * + * @param dataStream The data to write to the blob. + * @param length Optional known length of the data, affects reactive behavior for backwards compatibility. + */ + private BlobParallelUploadOptions(InputStream dataStream, Long length) { StorageImplUtils.assertNotNull("dataStream", dataStream); - StorageImplUtils.assertInBounds("length", length, 0, Long.MAX_VALUE); + if (length != null) { + StorageImplUtils.assertInBounds("length", length, 0, Long.MAX_VALUE); + } this.dataStream = dataStream; - this.length = length; this.dataFlux = null; + this.length = length; } /** @@ -77,7 +100,7 @@ public BlobParallelUploadOptions(BinaryData data) { StorageImplUtils.assertNotNull("data", data); this.dataFlux = Flux.just(data.toByteBuffer()); this.dataStream = null; - this.length = -1; + this.length = null; } /** @@ -103,11 +126,23 @@ public InputStream getDataStream() { * * @return The exact length of the data. It is important that this value match precisely the length of the * data provided in the {@link InputStream}. + * @deprecated use {@link #getOptionalLength()} to have safe access to a length that will not always exist. */ + @Deprecated public long getLength() { return length; } + /** + * Gets the length of the data. + * + * @return The exact length of the data. It is important that this value match precisely the length of the + * data provided in the {@link InputStream}. + */ + public Long getOptionalLength() { + return length; + } + /** * Gets the {@link ParallelTransferOptions}. * diff --git a/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/BlobAPITest.groovy b/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/BlobAPITest.groovy index a1a8db87bda51..11207b1c65d70 100644 --- a/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/BlobAPITest.groovy +++ b/sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/BlobAPITest.groovy @@ -209,6 +209,45 @@ class BlobAPITest extends APISpec { .getValue().getETag() != null } + def "Upload InputStream no length"() { + when: + bc.uploadWithResponse(new BlobParallelUploadOptions(data.defaultInputStream), null, null) + + then: + notThrown(Exception) + bc.downloadContent().toBytes() == data.defaultBytes + } + + def "Upload InputStream bad length"() { + when: + bc.uploadWithResponse(new BlobParallelUploadOptions(data.defaultInputStream, length), null, null) + + then: + thrown(Exception) + + where: + _ | length + _ | 0 + _ | -100 + _ | data.defaultDataSize - 1 + _ | data.defaultDataSize + 1 + } + + def "Upload successful retry"() { + given: + def clientWithFailure = getBlobClient( + env.primaryAccount.credential, + bc.getBlobUrl(), + new TransientFailureInjectingHttpPipelinePolicy()) + + when: + clientWithFailure.uploadWithResponse(new BlobParallelUploadOptions(data.defaultInputStream), null, null) + + then: + notThrown(Exception) + bc.downloadContent().toBytes() == data.defaultBytes + } + @LiveOnly // Reading from recordings will not allow for the timing of the test to work correctly. def "Upload timeout"() { diff --git a/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadInputStreamBadLength[0].json b/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadInputStreamBadLength[0].json new file mode 100644 index 0000000000000..0003222a371f0 --- /dev/null +++ b/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadInputStreamBadLength[0].json @@ -0,0 +1,50 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/7f5018f307f5018f3aec15131ec2a5fb9dde640e685e?restype=container", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "a3d9e138-90e1-4885-8cd7-544bce3e1fca" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92C58EF0BCAB0", + "Last-Modified" : "Thu, 10 Jun 2021 21:44:32 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "69ef6576-b01e-0019-0641-5e7a16000000", + "x-ms-client-request-id" : "a3d9e138-90e1-4885-8cd7-544bce3e1fca", + "Date" : "Thu, 10 Jun 2021 21:44:32 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/7f5018f307f5018f3aec15131ec2a5fb9dde640e685e/7f5018f317f5018f3aec68648158188ad9aa3434bb9a", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "9fe09bbf-3b98-4f30-b335-6ae82cb45011", + "Content-Type" : "application/octet-stream" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-content-crc64" : "6RYQPwaVsyQ=", + "Last-Modified" : "Thu, 10 Jun 2021 21:44:33 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "Date" : "Thu, 10 Jun 2021 21:44:32 GMT", + "Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==", + "eTag" : "0x8D92C58EF38659F", + "x-ms-request-id" : "69ef6580-b01e-0019-0b41-5e7a16000000", + "x-ms-client-request-id" : "9fe09bbf-3b98-4f30-b335-6ae82cb45011" + }, + "Exception" : null + } ], + "variables" : [ "7f5018f307f5018f3aec15131ec2a5fb9dde640e685e", "7f5018f317f5018f3aec68648158188ad9aa3434bb9a" ] +} \ No newline at end of file diff --git a/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadInputStreamBadLength[1].json b/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadInputStreamBadLength[1].json new file mode 100644 index 0000000000000..ed88960261b95 --- /dev/null +++ b/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadInputStreamBadLength[1].json @@ -0,0 +1,50 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/664b29b20664b29b2b8a39735445a8518b952493b840?restype=container", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "0a78fd58-091c-48dd-8e06-460e6d3b7b2d" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92C58EF7CCB72", + "Last-Modified" : "Thu, 10 Jun 2021 21:44:33 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "69ef6587-b01e-0019-1241-5e7a16000000", + "x-ms-client-request-id" : "0a78fd58-091c-48dd-8e06-460e6d3b7b2d", + "Date" : "Thu, 10 Jun 2021 21:44:32 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/664b29b20664b29b2b8a39735445a8518b952493b840/664b29b21664b29b2b8a255541c44a05dfa854d5d864", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "8f4270ac-e7b8-4aba-8fc1-067461d7a2f2", + "Content-Type" : "application/octet-stream" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-content-crc64" : "6RYQPwaVsyQ=", + "Last-Modified" : "Thu, 10 Jun 2021 21:44:33 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "Date" : "Thu, 10 Jun 2021 21:44:33 GMT", + "Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==", + "eTag" : "0x8D92C58EF8BA9BB", + "x-ms-request-id" : "69ef658a-b01e-0019-1441-5e7a16000000", + "x-ms-client-request-id" : "8f4270ac-e7b8-4aba-8fc1-067461d7a2f2" + }, + "Exception" : null + } ], + "variables" : [ "664b29b20664b29b2b8a39735445a8518b952493b840", "664b29b21664b29b2b8a255541c44a05dfa854d5d864" ] +} \ No newline at end of file diff --git a/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadInputStreamBadLength[2].json b/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadInputStreamBadLength[2].json new file mode 100644 index 0000000000000..1ca7cb630f954 --- /dev/null +++ b/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadInputStreamBadLength[2].json @@ -0,0 +1,50 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/4d667a7104d667a71bea6591957c250d6618b480daf9?restype=container", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "c79f5d3b-8274-4c59-ada0-c8d13da599cf" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92C58EFB6BEAF", + "Last-Modified" : "Thu, 10 Jun 2021 21:44:34 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "69ef6590-b01e-0019-1a41-5e7a16000000", + "x-ms-client-request-id" : "c79f5d3b-8274-4c59-ada0-c8d13da599cf", + "Date" : "Thu, 10 Jun 2021 21:44:33 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/4d667a7104d667a71bea6591957c250d6618b480daf9/4d667a7114d667a71bea705084c8cea16df3a446680d", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "4054dcf0-fb43-40f1-8f39-d47e1a4e5500", + "Content-Type" : "application/octet-stream" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-content-crc64" : "6RYQPwaVsyQ=", + "Last-Modified" : "Thu, 10 Jun 2021 21:44:34 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "Date" : "Thu, 10 Jun 2021 21:44:33 GMT", + "Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==", + "eTag" : "0x8D92C58EFC500F4", + "x-ms-request-id" : "69ef6593-b01e-0019-1c41-5e7a16000000", + "x-ms-client-request-id" : "4054dcf0-fb43-40f1-8f39-d47e1a4e5500" + }, + "Exception" : null + } ], + "variables" : [ "4d667a7104d667a71bea6591957c250d6618b480daf9", "4d667a7114d667a71bea705084c8cea16df3a446680d" ] +} \ No newline at end of file diff --git a/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadInputStreamBadLength[3].json b/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadInputStreamBadLength[3].json new file mode 100644 index 0000000000000..33cbbf7ef3457 --- /dev/null +++ b/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadInputStreamBadLength[3].json @@ -0,0 +1,50 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/547d4b300547d4b30f11300636363b37d2e8646149bf?restype=container", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "d7c66faa-0162-4603-98c4-6fa0af046d3d" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92C58EFEF5292", + "Last-Modified" : "Thu, 10 Jun 2021 21:44:34 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "69ef659a-b01e-0019-2241-5e7a16000000", + "x-ms-client-request-id" : "d7c66faa-0162-4603-98c4-6fa0af046d3d", + "Date" : "Thu, 10 Jun 2021 21:44:33 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/547d4b300547d4b30f11300636363b37d2e8646149bf/547d4b301547d4b30f118395439a3b957136742218ef", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "96a79c9b-ca06-4499-9825-9a7d0ba61b79", + "Content-Type" : "application/octet-stream" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-content-crc64" : "6RYQPwaVsyQ=", + "Last-Modified" : "Thu, 10 Jun 2021 21:44:34 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "Date" : "Thu, 10 Jun 2021 21:44:33 GMT", + "Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==", + "eTag" : "0x8D92C58EFFD6DF1", + "x-ms-request-id" : "69ef659c-b01e-0019-2341-5e7a16000000", + "x-ms-client-request-id" : "96a79c9b-ca06-4499-9825-9a7d0ba61b79" + }, + "Exception" : null + } ], + "variables" : [ "547d4b300547d4b30f11300636363b37d2e8646149bf", "547d4b301547d4b30f118395439a3b957136742218ef" ] +} \ No newline at end of file diff --git a/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadInputStreamExplicit-1Length.json b/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadInputStreamExplicit-1Length.json new file mode 100644 index 0000000000000..65068259896ce --- /dev/null +++ b/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadInputStreamExplicit-1Length.json @@ -0,0 +1,105 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/332cf4540332cf45456c2741680322bbc4a334d92ad5?restype=container", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "0d17e363-88e4-4d10-b58a-12af19bd8781" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92C58E8D7376E", + "Last-Modified" : "Thu, 10 Jun 2021 21:44:22 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "346052ec-401e-0021-2441-5ebb8d000000", + "x-ms-client-request-id" : "0d17e363-88e4-4d10-b58a-12af19bd8781", + "Date" : "Thu, 10 Jun 2021 21:44:21 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/332cf4540332cf45456c2741680322bbc4a334d92ad5/332cf4541332cf45456c86779ae30f7ee864a4bb3a30", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "779a0eec-b88f-4bf6-acb1-b25e5dc0218c", + "Content-Type" : "application/octet-stream" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-content-crc64" : "6RYQPwaVsyQ=", + "Last-Modified" : "Thu, 10 Jun 2021 21:44:22 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "Date" : "Thu, 10 Jun 2021 21:44:22 GMT", + "Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==", + "eTag" : "0x8D92C58E905763A", + "x-ms-request-id" : "346052f0-401e-0021-2641-5ebb8d000000", + "x-ms-client-request-id" : "779a0eec-b88f-4bf6-acb1-b25e5dc0218c" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/332cf4540332cf45456c2741680322bbc4a334d92ad5/332cf4541332cf45456c86779ae30f7ee864a4bb3a30", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "21d2ee26-805e-4469-9370-500c02302e0d", + "Content-Type" : "application/octet-stream" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-content-crc64" : "6RYQPwaVsyQ=", + "Last-Modified" : "Thu, 10 Jun 2021 21:44:22 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "Date" : "Thu, 10 Jun 2021 21:44:22 GMT", + "Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==", + "eTag" : "0x8D92C58E919BEA0", + "x-ms-request-id" : "346052f1-401e-0021-2741-5ebb8d000000", + "x-ms-client-request-id" : "21d2ee26-805e-4469-9370-500c02302e0d" + }, + "Exception" : null + }, { + "Method" : "GET", + "Uri" : "https://REDACTED.blob.core.windows.net/332cf4540332cf45456c2741680322bbc4a334d92ad5/332cf4541332cf45456c86779ae30f7ee864a4bb3a30", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "6ba8bb25-4bd8-4cdc-81e9-b1567d72efed" + }, + "Response" : { + "content-length" : "7", + "x-ms-version" : "2020-08-04", + "x-ms-lease-status" : "unlocked", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-lease-state" : "available", + "Last-Modified" : "Thu, 10 Jun 2021 21:44:22 GMT", + "retry-after" : "0", + "StatusCode" : "200", + "Date" : "Thu, 10 Jun 2021 21:44:22 GMT", + "Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==", + "x-ms-blob-type" : "BlockBlob", + "Accept-Ranges" : "bytes", + "x-ms-server-encrypted" : "true", + "x-ms-creation-time" : "Thu, 10 Jun 2021 21:44:22 GMT", + "eTag" : "0x8D92C58E919BEA0", + "x-ms-request-id" : "346052f2-401e-0021-2841-5ebb8d000000", + "Body" : "ZGVmYXVsdA==", + "x-ms-client-request-id" : "6ba8bb25-4bd8-4cdc-81e9-b1567d72efed", + "Content-Type" : "application/octet-stream" + }, + "Exception" : null + } ], + "variables" : [ "332cf4540332cf45456c2741680322bbc4a334d92ad5", "332cf4541332cf45456c86779ae30f7ee864a4bb3a30" ] +} \ No newline at end of file diff --git a/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadInputStreamNoLength.json b/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadInputStreamNoLength.json new file mode 100644 index 0000000000000..5eed27f3d3af5 --- /dev/null +++ b/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadInputStreamNoLength.json @@ -0,0 +1,105 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/b1e8e2820b1e8e282e29140322d030ee91e284e95812?restype=container", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "2b347a06-57a7-48f1-85f6-4504c37e71de" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92C58E34DA156", + "Last-Modified" : "Thu, 10 Jun 2021 21:44:13 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "3fa3b666-901e-0015-1f41-5e0902000000", + "x-ms-client-request-id" : "2b347a06-57a7-48f1-85f6-4504c37e71de", + "Date" : "Thu, 10 Jun 2021 21:44:12 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/b1e8e2820b1e8e282e29140322d030ee91e284e95812/b1e8e2821b1e8e282e296491116c5d4aec73143a4a96", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "82032c3b-037d-45a1-b175-58a820522927", + "Content-Type" : "application/octet-stream" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-content-crc64" : "6RYQPwaVsyQ=", + "Last-Modified" : "Thu, 10 Jun 2021 21:44:13 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "Date" : "Thu, 10 Jun 2021 21:44:12 GMT", + "Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==", + "eTag" : "0x8D92C58E37AE379", + "x-ms-request-id" : "3fa3b66c-901e-0015-2341-5e0902000000", + "x-ms-client-request-id" : "82032c3b-037d-45a1-b175-58a820522927" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/b1e8e2820b1e8e282e29140322d030ee91e284e95812/b1e8e2821b1e8e282e296491116c5d4aec73143a4a96", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "78ac254d-c2e3-4af9-9aeb-c22dd039cd65", + "Content-Type" : "application/octet-stream" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-content-crc64" : "6RYQPwaVsyQ=", + "Last-Modified" : "Thu, 10 Jun 2021 21:44:13 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "Date" : "Thu, 10 Jun 2021 21:44:12 GMT", + "Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==", + "eTag" : "0x8D92C58E38EDDC6", + "x-ms-request-id" : "3fa3b66d-901e-0015-2441-5e0902000000", + "x-ms-client-request-id" : "78ac254d-c2e3-4af9-9aeb-c22dd039cd65" + }, + "Exception" : null + }, { + "Method" : "GET", + "Uri" : "https://REDACTED.blob.core.windows.net/b1e8e2820b1e8e282e29140322d030ee91e284e95812/b1e8e2821b1e8e282e296491116c5d4aec73143a4a96", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "8e56e8dc-52ca-4c75-a395-07d4328efc41" + }, + "Response" : { + "content-length" : "7", + "x-ms-version" : "2020-08-04", + "x-ms-lease-status" : "unlocked", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-lease-state" : "available", + "Last-Modified" : "Thu, 10 Jun 2021 21:44:13 GMT", + "retry-after" : "0", + "StatusCode" : "200", + "Date" : "Thu, 10 Jun 2021 21:44:13 GMT", + "Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==", + "x-ms-blob-type" : "BlockBlob", + "Accept-Ranges" : "bytes", + "x-ms-server-encrypted" : "true", + "x-ms-creation-time" : "Thu, 10 Jun 2021 21:44:13 GMT", + "eTag" : "0x8D92C58E38EDDC6", + "x-ms-request-id" : "3fa3b66f-901e-0015-2641-5e0902000000", + "Body" : "ZGVmYXVsdA==", + "x-ms-client-request-id" : "8e56e8dc-52ca-4c75-a395-07d4328efc41", + "Content-Type" : "application/octet-stream" + }, + "Exception" : null + } ], + "variables" : [ "b1e8e2820b1e8e282e29140322d030ee91e284e95812", "b1e8e2821b1e8e282e296491116c5d4aec73143a4a96" ] +} \ No newline at end of file diff --git a/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadSuccessfulRetry.json b/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadSuccessfulRetry.json new file mode 100644 index 0000000000000..0fecad38c164f --- /dev/null +++ b/sdk/storage/azure-storage-blob/src/test/resources/session-records/BlobAPITestUploadSuccessfulRetry.json @@ -0,0 +1,105 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/63269e3e063269e3e36418713b5e2b94041b94ec1a4a?restype=container", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11.0.11; Windows 10; 10.0)", + "x-ms-client-request-id" : "eaeee2e8-4f01-48db-92e9-0e55e093108f" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92F8995D952C1", + "Last-Modified" : "Mon, 14 Jun 2021 23:10:22 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "b6d71204-101e-001b-6172-6145f9000000", + "x-ms-client-request-id" : "eaeee2e8-4f01-48db-92e9-0e55e093108f", + "Date" : "Mon, 14 Jun 2021 23:10:22 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/63269e3e063269e3e36418713b5e2b94041b94ec1a4a/63269e3e163269e3e36450192cd7de10ceef744cc9ee", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11.0.11; Windows 10; 10.0)", + "x-ms-client-request-id" : "d3127ec4-0523-48a2-9dd5-1da753392b77", + "Content-Type" : "application/octet-stream" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-content-crc64" : "6RYQPwaVsyQ=", + "Last-Modified" : "Mon, 14 Jun 2021 23:10:22 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "Date" : "Mon, 14 Jun 2021 23:10:22 GMT", + "Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==", + "eTag" : "0x8D92F89960E4FA5", + "x-ms-request-id" : "b6d71208-101e-001b-6272-6145f9000000", + "x-ms-client-request-id" : "d3127ec4-0523-48a2-9dd5-1da753392b77" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/63269e3e063269e3e36418713b5e2b94041b94ec1a4a/63269e3e163269e3e36450192cd7de10ceef744cc9ee", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11.0.11; Windows 10; 10.0)", + "x-ms-client-request-id" : "edb7bed9-2ea0-4b6d-bc1d-401c076c94e7", + "Content-Type" : "application/octet-stream" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-content-crc64" : "6RYQPwaVsyQ=", + "Last-Modified" : "Mon, 14 Jun 2021 23:10:43 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "Date" : "Mon, 14 Jun 2021 23:10:43 GMT", + "Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==", + "eTag" : "0x8D92F89A2B653DC", + "x-ms-request-id" : "b6d71240-101e-001b-7672-6145f9000000", + "x-ms-client-request-id" : "edb7bed9-2ea0-4b6d-bc1d-401c076c94e7" + }, + "Exception" : null + }, { + "Method" : "GET", + "Uri" : "https://REDACTED.blob.core.windows.net/63269e3e063269e3e36418713b5e2b94041b94ec1a4a/63269e3e163269e3e36450192cd7de10ceef744cc9ee", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 (11.0.11; Windows 10; 10.0)", + "x-ms-client-request-id" : "4df0ac66-633b-4992-a8d7-09e1dba21f53" + }, + "Response" : { + "content-length" : "7", + "x-ms-version" : "2020-08-04", + "x-ms-lease-status" : "unlocked", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-lease-state" : "available", + "Last-Modified" : "Mon, 14 Jun 2021 23:10:43 GMT", + "retry-after" : "0", + "StatusCode" : "200", + "Date" : "Mon, 14 Jun 2021 23:10:43 GMT", + "Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==", + "x-ms-blob-type" : "BlockBlob", + "Accept-Ranges" : "bytes", + "x-ms-server-encrypted" : "true", + "x-ms-creation-time" : "Mon, 14 Jun 2021 23:10:22 GMT", + "eTag" : "0x8D92F89A2B653DC", + "x-ms-request-id" : "b6d71241-101e-001b-7772-6145f9000000", + "Body" : "ZGVmYXVsdA==", + "x-ms-client-request-id" : "4df0ac66-633b-4992-a8d7-09e1dba21f53", + "Content-Type" : "application/octet-stream" + }, + "Exception" : null + } ], + "variables" : [ "63269e3e063269e3e36418713b5e2b94041b94ec1a4a", "63269e3e163269e3e36450192cd7de10ceef744cc9ee" ] +} \ No newline at end of file diff --git a/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/Utility.java b/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/Utility.java index cf591416ef3be..ac46406b509f9 100644 --- a/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/Utility.java +++ b/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/Utility.java @@ -232,6 +232,11 @@ public static Flux convertStreamToByteBuffer(InputStream data, long * A utility method for converting the input stream to Flux of ByteBuffer. Will check the equality of entity length * and the input length. * + * Using markAndReset=true to force a seekable stream implies a buffering strategy is not being used, in which case + * length is still needed for whatever underlying REST call is being streamed to. If markAndReset=false and data is + * being buffered, consider using {@link com.azure.core.util.FluxUtil#toFluxByteBuffer(InputStream, int)} which + * does not require a data length. + * * @param data The input data which needs to convert to ByteBuffer. * @param length The expected input data length. * @param blockSize The size of each ByteBuffer. diff --git a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/DataLakeFileAsyncClient.java b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/DataLakeFileAsyncClient.java index 68bf5e12023f2..96990c4a3bfb5 100644 --- a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/DataLakeFileAsyncClient.java +++ b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/DataLakeFileAsyncClient.java @@ -326,11 +326,19 @@ public Mono> uploadWithResponse(FileParallelUploadOptions opt .addProgressReporting(stream, validatedParallelTransferOptions.getProgressReceiver()), fileOffset, length, options.getHeaders(), validatedUploadRequestConditions); - Flux data = options.getDataFlux() == null ? Utility.convertStreamToByteBuffer( - options.getDataStream(), options.getLength(), + Flux data = options.getDataFlux(); + // no specified length: use azure.core's converter + if (data == null && options.getOptionalLength() == null) { // We can only buffer up to max int due to restrictions in ByteBuffer. - (int) Math.min(Integer.MAX_VALUE, validatedParallelTransferOptions.getBlockSizeLong()), false) - : options.getDataFlux(); + int chunkSize = (int) Math.min(Integer.MAX_VALUE, validatedParallelTransferOptions.getBlockSizeLong()); + data = FluxUtil.toFluxByteBuffer(options.getDataStream(), chunkSize); + // specified length (legacy requirement): use custom converter. no marking because we buffer anyway. + } else if (data == null) { + // We can only buffer up to max int due to restrictions in ByteBuffer. + int chunkSize = (int) Math.min(Integer.MAX_VALUE, validatedParallelTransferOptions.getBlockSizeLong()); + data = Utility.convertStreamToByteBuffer( + options.getDataStream(), options.getOptionalLength(), chunkSize, false); + } return createWithResponse(options.getPermissions(), options.getUmask(), options.getHeaders(), options.getMetadata(), validatedRequestConditions) diff --git a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/options/FileParallelUploadOptions.java b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/options/FileParallelUploadOptions.java index 73f9765ffe459..6a8190733d234 100644 --- a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/options/FileParallelUploadOptions.java +++ b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/options/FileParallelUploadOptions.java @@ -21,7 +21,7 @@ public class FileParallelUploadOptions { private final Flux dataFlux; private final InputStream dataStream; - private final long length; + private final Long length; private ParallelTransferOptions parallelTransferOptions; private PathHttpHeaders headers; private Map metadata; @@ -40,21 +40,43 @@ public FileParallelUploadOptions(Flux dataFlux) { StorageImplUtils.assertNotNull("dataFlux", dataFlux); this.dataFlux = dataFlux; this.dataStream = null; - this.length = -1; + this.length = null; } /** * Constructs a new {@code FileParallelUploadOptions}. * + * Use {@link #FileParallelUploadOptions(InputStream)} instead to supply an InputStream without knowing the exact + * length beforehand. + * * @param dataStream The data to write to the blob. The data must be markable. This is in order to support retries. * If the data is not markable, consider wrapping your data source in a {@link java.io.BufferedInputStream} to add * mark support. * @param length The exact length of the data. It is important that this value match precisely the length of the * data provided in the {@link InputStream}. + * @deprecated length is no longer necessary; use {@link #FileParallelUploadOptions(InputStream)} instead. */ + @Deprecated public FileParallelUploadOptions(InputStream dataStream, long length) { - StorageImplUtils.assertNotNull("dataStream", length); - StorageImplUtils.assertInBounds("length", length, 0, Long.MAX_VALUE); + this(dataStream, Long.valueOf(length)); + } + + /** + * Constructs a new {@code FileParallelUploadOptions}. + * + * @param dataStream The data to write to the blob. The data must be markable. This is in order to support retries. + * If the data is not markable, consider wrapping your data source in a {@link java.io.BufferedInputStream} to add + * mark support. + */ + public FileParallelUploadOptions(InputStream dataStream) { + this(dataStream, null); + } + + private FileParallelUploadOptions(InputStream dataStream, Long length) { + StorageImplUtils.assertNotNull("dataStream", dataStream); + if (length != null) { + StorageImplUtils.assertInBounds("length", length, 0, Long.MAX_VALUE); + } this.dataStream = dataStream; this.length = length; this.dataFlux = null; @@ -83,11 +105,23 @@ public InputStream getDataStream() { * * @return The exact length of the data. It is important that this value match precisely the length of the * data provided in the {@link InputStream}. + * @deprecated use {@link #getOptionalLength()} to have safe access to a length that will not always exist. */ + @Deprecated public long getLength() { return length; } + /** + * Gets the length of the data. + * + * @return The exact length of the data. It is important that this value match precisely the length of the + * data provided in the {@link InputStream}. + */ + public Long getOptionalLength() { + return length; + } + /** * Gets the {@link ParallelTransferOptions}. * diff --git a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileAPITest.groovy b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileAPITest.groovy index 06ae54733b871..b62c445ada175 100644 --- a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileAPITest.groovy +++ b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileAPITest.groovy @@ -8,6 +8,7 @@ import com.azure.identity.DefaultAzureCredentialBuilder import com.azure.storage.blob.BlobUrlParts import com.azure.storage.blob.models.BlobErrorCode import com.azure.storage.blob.models.BlobStorageException +import com.azure.storage.blob.options.BlobParallelUploadOptions import com.azure.storage.common.ParallelTransferOptions import com.azure.storage.common.ProgressReceiver import com.azure.storage.common.implementation.Constants @@ -2890,6 +2891,49 @@ class FileAPITest extends APISpec { compareFiles(file, outFile, 0, file.size()) } + def "Upload InputStream no length"() { + when: + fc.uploadWithResponse(new FileParallelUploadOptions(data.defaultInputStream), null, null) + + then: + notThrown(Exception) + ByteArrayOutputStream os = new ByteArrayOutputStream() + fc.read(os) + os.toByteArray() == data.defaultBytes + } + + def "Upload InputStream bad length"() { + when: + fc.uploadWithResponse(new FileParallelUploadOptions(data.defaultInputStream, length), null, null) + + then: + thrown(Exception) + + where: + _ | length + _ | 0 + _ | -100 + _ | data.defaultDataSize - 1 + _ | data.defaultDataSize + 1 + } + + def "Upload successful retry"() { + given: + def clientWithFailure = getFileClient( + env.dataLakeAccount.credential, + fc.getFileUrl(), + new TransientFailureInjectingHttpPipelinePolicy()) + + when: + clientWithFailure.uploadWithResponse(new FileParallelUploadOptions(data.defaultInputStream), null, null) + + then: + notThrown(Exception) + ByteArrayOutputStream os = new ByteArrayOutputStream() + fc.read(os) + os.toByteArray() == data.defaultBytes + } + /* Quick Query Tests. */ // Generates and uploads a CSV file diff --git a/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadInputStreamBadLength[0].json b/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadInputStreamBadLength[0].json new file mode 100644 index 0000000000000..03d9abc229760 --- /dev/null +++ b/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadInputStreamBadLength[0].json @@ -0,0 +1,69 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/79d711d8079d711d8fb149177f9b20542d8b446efb07?restype=container", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "badfca80-1c0f-4619-9b8e-607c09ea5c3f" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D16F280E6A3", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:43 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "e96187c0-701e-003e-71ff-5e4dbd000000", + "x-ms-client-request-id" : "badfca80-1c0f-4619-9b8e-607c09ea5c3f", + "Date" : "Fri, 11 Jun 2021 20:24:42 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.dfs.core.windows.net/79d711d8079d711d8fb149177f9b20542d8b446efb07/79d711d8179d711d8fb1337597e7e7c4e86eb4fa9863?resource=file", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "ea032a1d-87a1-4dc2-af78-ccf74efc1800" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D16F2E20DA7", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:43 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "x-ms-request-id" : "801f6e55-201f-009a-39ff-5e441b000000", + "x-ms-client-request-id" : "ea032a1d-87a1-4dc2-af78-ccf74efc1800", + "Date" : "Fri, 11 Jun 2021 20:24:43 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.dfs.core.windows.net/79d711d8079d711d8fb149177f9b20542d8b446efb07/79d711d8179d711d8fb1337597e7e7c4e86eb4fa9863?resource=file", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "dd740cf5-6b6d-43a7-91c6-201be6d9c2ef" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D16F2EF7D98", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:43 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "x-ms-request-id" : "801f6e56-201f-009a-3aff-5e441b000000", + "x-ms-client-request-id" : "dd740cf5-6b6d-43a7-91c6-201be6d9c2ef", + "Date" : "Fri, 11 Jun 2021 20:24:43 GMT" + }, + "Exception" : null + } ], + "variables" : [ "79d711d8079d711d8fb149177f9b20542d8b446efb07", "79d711d8179d711d8fb1337597e7e7c4e86eb4fa9863" ] +} \ No newline at end of file diff --git a/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadInputStreamBadLength[1].json b/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadInputStreamBadLength[1].json new file mode 100644 index 0000000000000..8d1944f0cf0c6 --- /dev/null +++ b/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadInputStreamBadLength[1].json @@ -0,0 +1,47 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/60cc2099060cc2099ed1457786ca3f6dec7fd4a5cae6?restype=container", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "18ff2347-381b-4912-a384-e425a34cf6cd" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D16F322264B", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:44 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "e96188dd-701e-003e-5fff-5e4dbd000000", + "x-ms-client-request-id" : "18ff2347-381b-4912-a384-e425a34cf6cd", + "Date" : "Fri, 11 Jun 2021 20:24:43 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.dfs.core.windows.net/60cc2099060cc2099ed1457786ca3f6dec7fd4a5cae6/60cc2099160cc2099ed19642935f2bdbc04a947e1aca?resource=file", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "7f3581b1-6614-4f77-98f6-65e105bfd02c" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D16F3343439", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:44 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "x-ms-request-id" : "801f6e5a-201f-009a-3dff-5e441b000000", + "x-ms-client-request-id" : "7f3581b1-6614-4f77-98f6-65e105bfd02c", + "Date" : "Fri, 11 Jun 2021 20:24:43 GMT" + }, + "Exception" : null + } ], + "variables" : [ "60cc2099060cc2099ed1457786ca3f6dec7fd4a5cae6", "60cc2099160cc2099ed19642935f2bdbc04a947e1aca" ] +} \ No newline at end of file diff --git a/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadInputStreamBadLength[2].json b/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadInputStreamBadLength[2].json new file mode 100644 index 0000000000000..08093bd474938 --- /dev/null +++ b/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadInputStreamBadLength[2].json @@ -0,0 +1,69 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/4be1735a04be1735a2fe6423768cdeedcc74044e786b?restype=container", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "f055a167-8e2f-4d75-8e5e-bb5d9c76d6a2" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D16F35414E9", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:44 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "e961892c-701e-003e-21ff-5e4dbd000000", + "x-ms-client-request-id" : "f055a167-8e2f-4d75-8e5e-bb5d9c76d6a2", + "Date" : "Fri, 11 Jun 2021 20:24:43 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.dfs.core.windows.net/4be1735a04be1735a2fe6423768cdeedcc74044e786b/4be1735a14be1735a2fe574805aa70aa484e2400fbd3?resource=file", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "798c0412-a6e5-411e-bc2c-0523796f6dbc" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D16F35E3206", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:44 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "x-ms-request-id" : "801f6e5b-201f-009a-3eff-5e441b000000", + "x-ms-client-request-id" : "798c0412-a6e5-411e-bc2c-0523796f6dbc", + "Date" : "Fri, 11 Jun 2021 20:24:43 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.dfs.core.windows.net/4be1735a04be1735a2fe6423768cdeedcc74044e786b/4be1735a14be1735a2fe574805aa70aa484e2400fbd3?resource=file", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "1f43825b-b32b-4266-81fd-6949d74f0bb7" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D16F3686D12", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:44 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "x-ms-request-id" : "801f6e5d-201f-009a-40ff-5e441b000000", + "x-ms-client-request-id" : "1f43825b-b32b-4266-81fd-6949d74f0bb7", + "Date" : "Fri, 11 Jun 2021 20:24:44 GMT" + }, + "Exception" : null + } ], + "variables" : [ "4be1735a04be1735a2fe6423768cdeedcc74044e786b", "4be1735a14be1735a2fe574805aa70aa484e2400fbd3" ] +} \ No newline at end of file diff --git a/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadInputStreamBadLength[3].json b/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadInputStreamBadLength[3].json new file mode 100644 index 0000000000000..967803cd713e8 --- /dev/null +++ b/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadInputStreamBadLength[3].json @@ -0,0 +1,69 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/52fa421b052fa421b68e13927b8ef6830ef284d1e8a5?restype=container", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "59e27e23-50d0-4e28-99f0-a55cf3666713" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D16F385B55A", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:44 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "e9618995-701e-003e-79ff-5e4dbd000000", + "x-ms-client-request-id" : "59e27e23-50d0-4e28-99f0-a55cf3666713", + "Date" : "Fri, 11 Jun 2021 20:24:43 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.dfs.core.windows.net/52fa421b052fa421b68e13927b8ef6830ef284d1e8a5/52fa421b152fa421b68e36284b8faf8a457dc4592806?resource=file", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "1de33af4-6ea4-4e9e-9b0c-510a2e85701b" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D16F38F842D", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:44 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "x-ms-request-id" : "801f6e5f-201f-009a-41ff-5e441b000000", + "x-ms-client-request-id" : "1de33af4-6ea4-4e9e-9b0c-510a2e85701b", + "Date" : "Fri, 11 Jun 2021 20:24:44 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.dfs.core.windows.net/52fa421b052fa421b68e13927b8ef6830ef284d1e8a5/52fa421b152fa421b68e36284b8faf8a457dc4592806?resource=file", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "cb7e9dd8-fc69-4e89-a477-1e1d2842baa6" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D16F398AD9B", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:44 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "x-ms-request-id" : "801f6e60-201f-009a-42ff-5e441b000000", + "x-ms-client-request-id" : "cb7e9dd8-fc69-4e89-a477-1e1d2842baa6", + "Date" : "Fri, 11 Jun 2021 20:24:44 GMT" + }, + "Exception" : null + } ], + "variables" : [ "52fa421b052fa421b68e13927b8ef6830ef284d1e8a5", "52fa421b152fa421b68e36284b8faf8a457dc4592806" ] +} \ No newline at end of file diff --git a/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadInputStreamExplicit-1Length.json b/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadInputStreamExplicit-1Length.json new file mode 100644 index 0000000000000..2307b8a1bebf3 --- /dev/null +++ b/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadInputStreamExplicit-1Length.json @@ -0,0 +1,142 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/d66f4c5d0d66f4c5d89291883fd07fef7fce04504adc?restype=container", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "a776d712-eee1-450b-ac62-f8417e7e38d8" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D16E68A2363", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:22 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "41a51c23-201e-0041-5cff-5e8226000000", + "x-ms-client-request-id" : "a776d712-eee1-450b-ac62-f8417e7e38d8", + "Date" : "Fri, 11 Jun 2021 20:24:22 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.dfs.core.windows.net/d66f4c5d0d66f4c5d89291883fd07fef7fce04504adc/d66f4c5d1d66f4c5d89225958d4c75ad7af9143bf80f?resource=file", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "8e9df0d0-fc81-405c-b69c-80c010cc1719" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D16E71CE551", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:23 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "x-ms-request-id" : "5b313adc-601f-0040-4dff-5eddfa000000", + "x-ms-client-request-id" : "8e9df0d0-fc81-405c-b69c-80c010cc1719", + "Date" : "Fri, 11 Jun 2021 20:24:23 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.dfs.core.windows.net/d66f4c5d0d66f4c5d89291883fd07fef7fce04504adc/d66f4c5d1d66f4c5d89225958d4c75ad7af9143bf80f?resource=file", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "f023ebbc-2061-4414-88a5-1c9a0add9df7" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D16E72AF19F", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:24 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "x-ms-request-id" : "5b313add-601f-0040-4eff-5eddfa000000", + "x-ms-client-request-id" : "f023ebbc-2061-4414-88a5-1c9a0add9df7", + "Date" : "Fri, 11 Jun 2021 20:24:23 GMT" + }, + "Exception" : null + }, { + "Method" : "PATCH", + "Uri" : "https://REDACTED.dfs.core.windows.net/d66f4c5d0d66f4c5d89291883fd07fef7fce04504adc/d66f4c5d1d66f4c5d89225958d4c75ad7af9143bf80f?action=append&position=0", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "dab14802-d3a2-40a5-ba68-a46490f8a416", + "Content-Type" : "application/octet-stream" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0", + "retry-after" : "0", + "StatusCode" : "202", + "x-ms-request-server-encrypted" : "true", + "x-ms-request-id" : "5b313ade-601f-0040-4fff-5eddfa000000", + "x-ms-client-request-id" : "dab14802-d3a2-40a5-ba68-a46490f8a416", + "Date" : "Fri, 11 Jun 2021 20:24:23 GMT" + }, + "Exception" : null + }, { + "Method" : "PATCH", + "Uri" : "https://REDACTED.dfs.core.windows.net/d66f4c5d0d66f4c5d89291883fd07fef7fce04504adc/d66f4c5d1d66f4c5d89225958d4c75ad7af9143bf80f?action=flush&position=7&retainUncommittedData=false&close=false", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "18e4c7fd-88c6-49c6-abe7-98bd6448f73e" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D16E7450E0D", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:24 GMT", + "retry-after" : "0", + "StatusCode" : "200", + "x-ms-request-server-encrypted" : "false", + "x-ms-request-id" : "5b313adf-601f-0040-50ff-5eddfa000000", + "x-ms-client-request-id" : "18e4c7fd-88c6-49c6-abe7-98bd6448f73e", + "Date" : "Fri, 11 Jun 2021 20:24:24 GMT" + }, + "Exception" : null + }, { + "Method" : "GET", + "Uri" : "https://REDACTED.blob.core.windows.net/d66f4c5d0d66f4c5d89291883fd07fef7fce04504adc/d66f4c5d1d66f4c5d89225958d4c75ad7af9143bf80f", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "5c0011ee-1083-48c6-8dc6-f867bf8fb60c" + }, + "Response" : { + "content-length" : "7", + "x-ms-last-access-time" : "Fri, 11 Jun 2021 20:24:24 GMT", + "x-ms-version" : "2020-08-04", + "x-ms-lease-status" : "unlocked", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-lease-state" : "available", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:24 GMT", + "retry-after" : "0", + "StatusCode" : "200", + "Date" : "Fri, 11 Jun 2021 20:24:24 GMT", + "x-ms-blob-type" : "BlockBlob", + "Accept-Ranges" : "bytes", + "x-ms-server-encrypted" : "true", + "x-ms-creation-time" : "Fri, 11 Jun 2021 20:24:23 GMT", + "eTag" : "0x8D92D16E7450E0D", + "x-ms-request-id" : "41a51d2c-201e-0041-3aff-5e8226000000", + "Body" : "ZGVmYXVsdA==", + "x-ms-client-request-id" : "5c0011ee-1083-48c6-8dc6-f867bf8fb60c", + "Content-Type" : "application/octet-stream" + }, + "Exception" : null + } ], + "variables" : [ "d66f4c5d0d66f4c5d89291883fd07fef7fce04504adc", "d66f4c5d1d66f4c5d89225958d4c75ad7af9143bf80f" ] +} \ No newline at end of file diff --git a/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadInputStreamNoLength.json b/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadInputStreamNoLength.json new file mode 100644 index 0000000000000..3a6e12f4807b7 --- /dev/null +++ b/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadInputStreamNoLength.json @@ -0,0 +1,142 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/23e7fffc023e7fffc44287107938bf98c605148af8a2?restype=container", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "06fff6ae-e276-4ab8-8a18-8d6aeb1b6ca9" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D16D9B2BE91", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:01 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "479535ed-801e-0067-3bff-5eca3e000000", + "x-ms-client-request-id" : "06fff6ae-e276-4ab8-8a18-8d6aeb1b6ca9", + "Date" : "Fri, 11 Jun 2021 20:24:01 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.dfs.core.windows.net/23e7fffc023e7fffc44287107938bf98c605148af8a2/23e7fffc123e7fffc44268945a1c3069fd13e4d50b27?resource=file", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "0c32be1e-0903-4ef2-bd49-9bbac7a44b2e" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D16D9F63F06", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:01 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "x-ms-request-id" : "7f2edd3f-001f-009d-07ff-5e2878000000", + "x-ms-client-request-id" : "0c32be1e-0903-4ef2-bd49-9bbac7a44b2e", + "Date" : "Fri, 11 Jun 2021 20:24:01 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.dfs.core.windows.net/23e7fffc023e7fffc44287107938bf98c605148af8a2/23e7fffc123e7fffc44268945a1c3069fd13e4d50b27?resource=file", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "949108f7-68de-4467-886c-b73d8a695e36" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D16DA050ECB", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:01 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "x-ms-request-id" : "7f2edd40-001f-009d-08ff-5e2878000000", + "x-ms-client-request-id" : "949108f7-68de-4467-886c-b73d8a695e36", + "Date" : "Fri, 11 Jun 2021 20:24:01 GMT" + }, + "Exception" : null + }, { + "Method" : "PATCH", + "Uri" : "https://REDACTED.dfs.core.windows.net/23e7fffc023e7fffc44287107938bf98c605148af8a2/23e7fffc123e7fffc44268945a1c3069fd13e4d50b27?action=append&position=0", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "dfa3e63d-cb9a-4377-9120-82c1ce78e694", + "Content-Type" : "application/octet-stream" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0", + "retry-after" : "0", + "StatusCode" : "202", + "x-ms-request-server-encrypted" : "true", + "x-ms-request-id" : "7f2edd42-001f-009d-0aff-5e2878000000", + "x-ms-client-request-id" : "dfa3e63d-cb9a-4377-9120-82c1ce78e694", + "Date" : "Fri, 11 Jun 2021 20:24:01 GMT" + }, + "Exception" : null + }, { + "Method" : "PATCH", + "Uri" : "https://REDACTED.dfs.core.windows.net/23e7fffc023e7fffc44287107938bf98c605148af8a2/23e7fffc123e7fffc44268945a1c3069fd13e4d50b27?action=flush&position=7&retainUncommittedData=false&close=false", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "72c41b70-52e4-4c0f-aff0-90c4f4b1c132" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D16DA21004B", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:02 GMT", + "retry-after" : "0", + "StatusCode" : "200", + "x-ms-request-server-encrypted" : "false", + "x-ms-request-id" : "7f2edd44-001f-009d-0cff-5e2878000000", + "x-ms-client-request-id" : "72c41b70-52e4-4c0f-aff0-90c4f4b1c132", + "Date" : "Fri, 11 Jun 2021 20:24:01 GMT" + }, + "Exception" : null + }, { + "Method" : "GET", + "Uri" : "https://REDACTED.blob.core.windows.net/23e7fffc023e7fffc44287107938bf98c605148af8a2/23e7fffc123e7fffc44268945a1c3069fd13e4d50b27", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "b1ecaa7c-eb50-462d-b286-44bec6b5492f" + }, + "Response" : { + "content-length" : "7", + "x-ms-last-access-time" : "Fri, 11 Jun 2021 20:24:02 GMT", + "x-ms-version" : "2020-08-04", + "x-ms-lease-status" : "unlocked", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-lease-state" : "available", + "Last-Modified" : "Fri, 11 Jun 2021 20:24:02 GMT", + "retry-after" : "0", + "StatusCode" : "200", + "Date" : "Fri, 11 Jun 2021 20:24:02 GMT", + "x-ms-blob-type" : "BlockBlob", + "Accept-Ranges" : "bytes", + "x-ms-server-encrypted" : "true", + "x-ms-creation-time" : "Fri, 11 Jun 2021 20:24:01 GMT", + "eTag" : "0x8D92D16DA21004B", + "x-ms-request-id" : "479536ef-801e-0067-1aff-5eca3e000000", + "Body" : "ZGVmYXVsdA==", + "x-ms-client-request-id" : "b1ecaa7c-eb50-462d-b286-44bec6b5492f", + "Content-Type" : "application/octet-stream" + }, + "Exception" : null + } ], + "variables" : [ "23e7fffc023e7fffc44287107938bf98c605148af8a2", "23e7fffc123e7fffc44268945a1c3069fd13e4d50b27" ] +} \ No newline at end of file diff --git a/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadSuccessfulRetry.json b/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadSuccessfulRetry.json new file mode 100644 index 0000000000000..cdbe08b3bbc9c --- /dev/null +++ b/sdk/storage/azure-storage-file-datalake/src/test/resources/session-records/FileAPITestUploadSuccessfulRetry.json @@ -0,0 +1,142 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.blob.core.windows.net/9113e32409113e32461527359d60977e9e2044ee89d7?restype=container", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.11; Windows 10; 10.0)", + "x-ms-client-request-id" : "fac90395-583e-4f37-9f60-75b377ee4d54" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92F8ABE4D44EE", + "Last-Modified" : "Mon, 14 Jun 2021 23:18:39 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "4e1934fc-f01e-0030-5473-61640d000000", + "x-ms-client-request-id" : "fac90395-583e-4f37-9f60-75b377ee4d54", + "Date" : "Mon, 14 Jun 2021 23:18:39 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.dfs.core.windows.net/9113e32409113e32461527359d60977e9e2044ee89d7/9113e32419113e32461506777e2361988cc6243fb8ad?resource=file", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.11; Windows 10; 10.0)", + "x-ms-client-request-id" : "c82dff25-a22c-4172-a6c5-27e362446a30" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92F8ABF2E001A", + "Last-Modified" : "Mon, 14 Jun 2021 23:18:40 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "x-ms-request-id" : "8e94ea29-201f-0041-3873-618226000000", + "x-ms-client-request-id" : "c82dff25-a22c-4172-a6c5-27e362446a30", + "Date" : "Mon, 14 Jun 2021 23:18:40 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.dfs.core.windows.net/9113e32409113e32461527359d60977e9e2044ee89d7/9113e32419113e32461506777e2361988cc6243fb8ad?resource=file", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.11; Windows 10; 10.0)", + "x-ms-client-request-id" : "85d33e89-e15f-48ab-a28b-86f7b97cb664" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92F8AC1A93751", + "Last-Modified" : "Mon, 14 Jun 2021 23:18:45 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "x-ms-request-id" : "8e94ea30-201f-0041-3b73-618226000000", + "x-ms-client-request-id" : "85d33e89-e15f-48ab-a28b-86f7b97cb664", + "Date" : "Mon, 14 Jun 2021 23:18:44 GMT" + }, + "Exception" : null + }, { + "Method" : "PATCH", + "Uri" : "https://REDACTED.dfs.core.windows.net/9113e32409113e32461527359d60977e9e2044ee89d7/9113e32419113e32461506777e2361988cc6243fb8ad?action=append&position=0", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.11; Windows 10; 10.0)", + "x-ms-client-request-id" : "948b5918-9678-4ede-bbf0-7fa524c790fa", + "Content-Type" : "application/octet-stream" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0", + "retry-after" : "0", + "StatusCode" : "202", + "x-ms-request-server-encrypted" : "true", + "x-ms-request-id" : "8e94ea69-201f-0041-7273-618226000000", + "x-ms-client-request-id" : "948b5918-9678-4ede-bbf0-7fa524c790fa", + "Date" : "Mon, 14 Jun 2021 23:18:48 GMT" + }, + "Exception" : null + }, { + "Method" : "PATCH", + "Uri" : "https://REDACTED.dfs.core.windows.net/9113e32409113e32461527359d60977e9e2044ee89d7/9113e32419113e32461506777e2361988cc6243fb8ad?action=flush&position=7&retainUncommittedData=false&close=false", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.11; Windows 10; 10.0)", + "x-ms-client-request-id" : "2d569080-d564-4da5-b2c7-4b7cf09e570a" + }, + "Response" : { + "content-length" : "0", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92F8AC6960779", + "Last-Modified" : "Mon, 14 Jun 2021 23:18:53 GMT", + "retry-after" : "0", + "StatusCode" : "200", + "x-ms-request-server-encrypted" : "false", + "x-ms-request-id" : "8e94ead7-201f-0041-5d73-618226000000", + "x-ms-client-request-id" : "2d569080-d564-4da5-b2c7-4b7cf09e570a", + "Date" : "Mon, 14 Jun 2021 23:18:52 GMT" + }, + "Exception" : null + }, { + "Method" : "GET", + "Uri" : "https://REDACTED.blob.core.windows.net/9113e32409113e32461527359d60977e9e2044ee89d7/9113e32419113e32461506777e2361988cc6243fb8ad", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-blob/12.13.0-beta.1 azsdk-java-azure-storage-file-datalake/12.7.0-beta.1 (11.0.11; Windows 10; 10.0)", + "x-ms-client-request-id" : "934efc6b-d9cc-4ae6-a1eb-6ac588700530" + }, + "Response" : { + "content-length" : "7", + "x-ms-last-access-time" : "Mon, 14 Jun 2021 23:18:53 GMT", + "x-ms-version" : "2020-08-04", + "x-ms-lease-status" : "unlocked", + "Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-lease-state" : "available", + "Last-Modified" : "Mon, 14 Jun 2021 23:18:53 GMT", + "retry-after" : "0", + "StatusCode" : "200", + "Date" : "Mon, 14 Jun 2021 23:18:53 GMT", + "x-ms-blob-type" : "BlockBlob", + "Accept-Ranges" : "bytes", + "x-ms-server-encrypted" : "true", + "x-ms-creation-time" : "Mon, 14 Jun 2021 23:18:40 GMT", + "eTag" : "0x8D92F8AC6960779", + "x-ms-request-id" : "4e193bb7-f01e-0030-0373-61640d000000", + "Body" : "ZGVmYXVsdA==", + "x-ms-client-request-id" : "934efc6b-d9cc-4ae6-a1eb-6ac588700530", + "Content-Type" : "application/octet-stream" + }, + "Exception" : null + } ], + "variables" : [ "9113e32409113e32461527359d60977e9e2044ee89d7", "9113e32419113e32461506777e2361988cc6243fb8ad" ] +} \ No newline at end of file diff --git a/sdk/storage/azure-storage-file-share/src/main/java/com/azure/storage/file/share/ShareFileAsyncClient.java b/sdk/storage/azure-storage-file-share/src/main/java/com/azure/storage/file/share/ShareFileAsyncClient.java index 192be52e0bc24..2a2492583396f 100644 --- a/sdk/storage/azure-storage-file-share/src/main/java/com/azure/storage/file/share/ShareFileAsyncClient.java +++ b/sdk/storage/azure-storage-file-share/src/main/java/com/azure/storage/file/share/ShareFileAsyncClient.java @@ -1417,11 +1417,19 @@ Mono> uploadWithResponse(ShareFileUploadOptions op stream, validatedParallelTransferOptions.getProgressReceiver()), length) .setOffset(options.getOffset()).setRequestConditions(validatedRequestConditions), context); - Flux data = options.getDataFlux() == null ? Utility.convertStreamToByteBuffer( - options.getDataStream(), options.getLength(), + Flux data = options.getDataFlux(); + // no specified length: use azure.core's converter + if (data == null && options.getLength() == null) { // We can only buffer up to max int due to restrictions in ByteBuffer. - (int) Math.min(Integer.MAX_VALUE, validatedParallelTransferOptions.getBlockSizeLong()), false) - : options.getDataFlux(); + int chunkSize = (int) Math.min(Integer.MAX_VALUE, validatedParallelTransferOptions.getBlockSizeLong()); + data = FluxUtil.toFluxByteBuffer(options.getDataStream(), chunkSize); + // specified length (legacy requirement): use custom converter. no marking because we buffer anyway. + } else if (data == null) { + // We can only buffer up to max int due to restrictions in ByteBuffer. + int chunkSize = (int) Math.min(Integer.MAX_VALUE, validatedParallelTransferOptions.getBlockSizeLong()); + data = Utility.convertStreamToByteBuffer( + options.getDataStream(), options.getLength(), chunkSize, false); + } return UploadUtils.uploadFullOrChunked(data, validatedParallelTransferOptions, uploadInChunks, uploadFull); } catch (RuntimeException ex) { diff --git a/sdk/storage/azure-storage-file-share/src/main/java/com/azure/storage/file/share/models/ShareFileUploadOptions.java b/sdk/storage/azure-storage-file-share/src/main/java/com/azure/storage/file/share/models/ShareFileUploadOptions.java index 8512f009e755c..bde670a111b7e 100644 --- a/sdk/storage/azure-storage-file-share/src/main/java/com/azure/storage/file/share/models/ShareFileUploadOptions.java +++ b/sdk/storage/azure-storage-file-share/src/main/java/com/azure/storage/file/share/models/ShareFileUploadOptions.java @@ -39,12 +39,17 @@ public ShareFileUploadOptions(Flux dataFlux) { /** * Constructs a new {@code FileParallelUploadOptions}. * + * Use {@link #ShareFileUploadOptions(InputStream)} instead to supply an InputStream without knowing the exact + * length beforehand. + * * @param dataStream The data to write to the file. The data must be markable. This is in order to support retries. * If the data is not markable, consider wrapping your data source in a {@link java.io.BufferedInputStream} to add * mark support. * @param length The exact length of the data. It is important that this value match precisely the length of the * data provided in the {@link InputStream}. + * @deprecated length is no longer necessary; use {@link #ShareFileUploadOptions(InputStream)} instead. */ + @Deprecated public ShareFileUploadOptions(InputStream dataStream, long length) { StorageImplUtils.assertNotNull("dataStream", length); StorageImplUtils.assertInBounds("length", length, 0, Long.MAX_VALUE); @@ -53,6 +58,20 @@ public ShareFileUploadOptions(InputStream dataStream, long length) { this.dataFlux = null; } + /** + * Constructs a new {@code FileParallelUploadOptions}. + * + * @param dataStream The data to write to the file. The data must be markable. This is in order to support retries. + * If the data is not markable, consider wrapping your data source in a {@link java.io.BufferedInputStream} to add + * mark support. + */ + public ShareFileUploadOptions(InputStream dataStream) { + StorageImplUtils.assertNotNull("dataStream", dataStream); + this.dataStream = dataStream; + this.dataFlux = null; + this.length = null; + } + /** * Gets the data source. * diff --git a/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/FileAPITests.groovy b/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/FileAPITests.groovy index 78d38db60c3eb..9cb617ec79ab6 100644 --- a/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/FileAPITests.groovy +++ b/sdk/storage/azure-storage-file-share/src/test/java/com/azure/storage/file/share/FileAPITests.groovy @@ -302,6 +302,52 @@ class FileAPITests extends APISpec { data.defaultBytes == stream.toByteArray() } + def "Parallel Upload InputStream no length"() { + when: + primaryFileClient.create(data.defaultDataSize) + primaryFileClient.uploadWithResponse(new ShareFileUploadOptions(data.defaultInputStream), null, null) + + then: + notThrown(Exception) + ByteArrayOutputStream os = new ByteArrayOutputStream() + primaryFileClient.download(os) + os.toByteArray() == data.defaultBytes + } + + def "Parallel Upload InputStream bad length"() { + when: + primaryFileClient.create(data.defaultDataSize) + primaryFileClient.uploadWithResponse(new ShareFileUploadOptions(data.defaultInputStream, length), null, null) + + then: + thrown(Exception) + + where: + _ | length + _ | 0 + _ | -100 + _ | data.defaultDataSize - 1 + _ | data.defaultDataSize + 1 + } + + def "Upload successful retry"() { + given: + primaryFileClient.create(data.defaultDataSize) + def clientWithFailure = getFileClient( + env.primaryAccount.credential, + primaryFileClient.getFileUrl(), + new TransientFailureInjectingHttpPipelinePolicy()) + + when: + clientWithFailure.uploadWithResponse(new ShareFileUploadOptions(data.defaultInputStream), null, null) + + then: + notThrown(Exception) + ByteArrayOutputStream os = new ByteArrayOutputStream() + primaryFileClient.download(os) + os.toByteArray() == data.defaultBytes + } + def "Upload range and download data"() { given: primaryFileClient.create(data.defaultDataSizeLong) diff --git a/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsParallelUploadInputStreamBadLength[0].json b/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsParallelUploadInputStreamBadLength[0].json new file mode 100644 index 0000000000000..7aa3c64224483 --- /dev/null +++ b/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsParallelUploadInputStreamBadLength[0].json @@ -0,0 +1,54 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.file.core.windows.net/e93acbd9e93acbd9ce6822506708873fbe8345838c?restype=share", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-share/12.11.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "201ec546-46e7-40cc-93db-65c54451915f" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D18F793F3A4", + "Last-Modified" : "Fri, 11 Jun 2021 20:39:10 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "f5cff2af-b01a-0019-3901-5f7a16000000", + "x-ms-client-request-id" : "201ec546-46e7-40cc-93db-65c54451915f", + "Date" : "Fri, 11 Jun 2021 20:39:10 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.file.core.windows.net/e93acbd9e93acbd9ce6822506708873fbe8345838c/e93acbd9e93acbd9ce68869660ed5ef85ba14e6b8b", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-share/12.11.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "767132fd-06f4-4556-afe3-d26f73ea210b" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "x-ms-file-permission-key" : "16466167399171598336*5486365400479318158", + "x-ms-file-id" : "13835128424026341376", + "Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-file-creation-time" : "2021-06-11T20:39:10.8245825Z", + "Last-Modified" : "Fri, 11 Jun 2021 20:39:10 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "Date" : "Fri, 11 Jun 2021 20:39:10 GMT", + "x-ms-file-attributes" : "Archive", + "x-ms-file-change-time" : "2021-06-11T20:39:10.8245825Z", + "x-ms-file-parent-id" : "0", + "eTag" : "0x8D92D18F7B9BD41", + "x-ms-request-id" : "f5cff2b2-b01a-0019-3a01-5f7a16000000", + "x-ms-client-request-id" : "767132fd-06f4-4556-afe3-d26f73ea210b", + "x-ms-file-last-write-time" : "2021-06-11T20:39:10.8245825Z" + }, + "Exception" : null + } ], + "variables" : [ "e93acbd9e93acbd9ce6822506708873fbe8345838c", "e93acbd9e93acbd9ce68869660ed5ef85ba14e6b8b" ] +} \ No newline at end of file diff --git a/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsParallelUploadInputStreamBadLength[1].json b/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsParallelUploadInputStreamBadLength[1].json new file mode 100644 index 0000000000000..fb18519f1b302 --- /dev/null +++ b/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsParallelUploadInputStreamBadLength[1].json @@ -0,0 +1,54 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.file.core.windows.net/f021fa98f021fa98e660836670e043ff39c24913ae?restype=share", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-share/12.11.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "b37965a0-e088-4945-93a3-b48e00cd8e3a" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D18F800D649", + "Last-Modified" : "Fri, 11 Jun 2021 20:39:11 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "f5cff2b5-b01a-0019-3d01-5f7a16000000", + "x-ms-client-request-id" : "b37965a0-e088-4945-93a3-b48e00cd8e3a", + "Date" : "Fri, 11 Jun 2021 20:39:11 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.file.core.windows.net/f021fa98f021fa98e660836670e043ff39c24913ae/f021fa98f021fa98e66823844738bf0044544a969d", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-share/12.11.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "1a77795f-eede-42b9-a6ad-ddaf598d0db1" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "x-ms-file-permission-key" : "16466167399171598336*5486365400479318158", + "x-ms-file-id" : "13835128424026341376", + "Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-file-creation-time" : "2021-06-11T20:39:11.3872662Z", + "Last-Modified" : "Fri, 11 Jun 2021 20:39:11 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "Date" : "Fri, 11 Jun 2021 20:39:11 GMT", + "x-ms-file-attributes" : "Archive", + "x-ms-file-change-time" : "2021-06-11T20:39:11.3872662Z", + "x-ms-file-parent-id" : "0", + "eTag" : "0x8D92D18F80F9916", + "x-ms-request-id" : "f5cff2b7-b01a-0019-3e01-5f7a16000000", + "x-ms-client-request-id" : "1a77795f-eede-42b9-a6ad-ddaf598d0db1", + "x-ms-file-last-write-time" : "2021-06-11T20:39:11.3872662Z" + }, + "Exception" : null + } ], + "variables" : [ "f021fa98f021fa98e660836670e043ff39c24913ae", "f021fa98f021fa98e66823844738bf0044544a969d" ] +} \ No newline at end of file diff --git a/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsParallelUploadInputStreamBadLength[2].json b/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsParallelUploadInputStreamBadLength[2].json new file mode 100644 index 0000000000000..505a3390f2f36 --- /dev/null +++ b/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsParallelUploadInputStreamBadLength[2].json @@ -0,0 +1,54 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.file.core.windows.net/db0ca95bdb0ca95b28d459251efe82d33db745218d?restype=share", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-share/12.11.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "187d7404-76b6-446c-8ce1-5bb2db9d19da" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D18F8391C14", + "Last-Modified" : "Fri, 11 Jun 2021 20:39:11 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "f5cff2ba-b01a-0019-4101-5f7a16000000", + "x-ms-client-request-id" : "187d7404-76b6-446c-8ce1-5bb2db9d19da", + "Date" : "Fri, 11 Jun 2021 20:39:11 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.file.core.windows.net/db0ca95bdb0ca95b28d459251efe82d33db745218d/db0ca95bdb0ca95b28d907773433d2149a024d3bad", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-share/12.11.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "57498ec6-09e7-4891-9cd8-011fd2d71341" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "x-ms-file-permission-key" : "16466167399171598336*5486365400479318158", + "x-ms-file-id" : "13835128424026341376", + "Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-file-creation-time" : "2021-06-11T20:39:11.7550601Z", + "Last-Modified" : "Fri, 11 Jun 2021 20:39:11 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "Date" : "Fri, 11 Jun 2021 20:39:11 GMT", + "x-ms-file-attributes" : "Archive", + "x-ms-file-change-time" : "2021-06-11T20:39:11.7550601Z", + "x-ms-file-parent-id" : "0", + "eTag" : "0x8D92D18F847B809", + "x-ms-request-id" : "f5cff2bc-b01a-0019-4201-5f7a16000000", + "x-ms-client-request-id" : "57498ec6-09e7-4891-9cd8-011fd2d71341", + "x-ms-file-last-write-time" : "2021-06-11T20:39:11.7550601Z" + }, + "Exception" : null + } ], + "variables" : [ "db0ca95bdb0ca95b28d459251efe82d33db745218d", "db0ca95bdb0ca95b28d907773433d2149a024d3bad" ] +} \ No newline at end of file diff --git a/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsParallelUploadInputStreamBadLength[3].json b/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsParallelUploadInputStreamBadLength[3].json new file mode 100644 index 0000000000000..351712d082516 --- /dev/null +++ b/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsParallelUploadInputStreamBadLength[3].json @@ -0,0 +1,54 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.file.core.windows.net/c217981ac217981af4859939d4ca79fb53c34b5b9b?restype=share", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-share/12.11.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "2edccbd3-add8-444a-beb7-07013954946e" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D18F87113CF", + "Last-Modified" : "Fri, 11 Jun 2021 20:39:12 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "f5cff2c1-b01a-0019-4501-5f7a16000000", + "x-ms-client-request-id" : "2edccbd3-add8-444a-beb7-07013954946e", + "Date" : "Fri, 11 Jun 2021 20:39:11 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.file.core.windows.net/c217981ac217981af4859939d4ca79fb53c34b5b9b/c217981ac217981af482090081988b704b4945e68e", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-share/12.11.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "b9515b6f-a241-437e-8099-57b1eb1ae14f" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "x-ms-file-permission-key" : "16466167399171598336*5486365400479318158", + "x-ms-file-id" : "13835128424026341376", + "Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-file-creation-time" : "2021-06-11T20:39:12.1198545Z", + "Last-Modified" : "Fri, 11 Jun 2021 20:39:12 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "Date" : "Fri, 11 Jun 2021 20:39:11 GMT", + "x-ms-file-attributes" : "Archive", + "x-ms-file-change-time" : "2021-06-11T20:39:12.1198545Z", + "x-ms-file-parent-id" : "0", + "eTag" : "0x8D92D18F87F61D1", + "x-ms-request-id" : "f5cff2c4-b01a-0019-4601-5f7a16000000", + "x-ms-client-request-id" : "b9515b6f-a241-437e-8099-57b1eb1ae14f", + "x-ms-file-last-write-time" : "2021-06-11T20:39:12.1198545Z" + }, + "Exception" : null + } ], + "variables" : [ "c217981ac217981af4859939d4ca79fb53c34b5b9b", "c217981ac217981af482090081988b704b4945e68e" ] +} \ No newline at end of file diff --git a/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsParallelUploadInputStreamExplicit-1Length.json b/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsParallelUploadInputStreamExplicit-1Length.json new file mode 100644 index 0000000000000..8c6edd35ccb29 --- /dev/null +++ b/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsParallelUploadInputStreamExplicit-1Length.json @@ -0,0 +1,113 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.file.core.windows.net/f512853bf512853ba5d96897ed14530f76c24af68a?restype=share", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-share/12.11.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "cba49ffc-e21a-4d9d-8664-04cabf27027e" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D18EF740D2C", + "Last-Modified" : "Fri, 11 Jun 2021 20:38:56 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "a2a96906-b01a-0006-0901-5f3a43000000", + "x-ms-client-request-id" : "cba49ffc-e21a-4d9d-8664-04cabf27027e", + "Date" : "Fri, 11 Jun 2021 20:38:56 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.file.core.windows.net/f512853bf512853ba5d96897ed14530f76c24af68a/f512853bf512853ba5d030498ecc8619dee9457ea0", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-share/12.11.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "cb66ec32-04db-4603-879b-2b678527708d" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "x-ms-file-permission-key" : "16466167399171598336*5486365400479318158", + "x-ms-file-id" : "13835128424026341376", + "Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-file-creation-time" : "2021-06-11T20:38:57.2292239Z", + "Last-Modified" : "Fri, 11 Jun 2021 20:38:57 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "Date" : "Fri, 11 Jun 2021 20:38:56 GMT", + "x-ms-file-attributes" : "Archive", + "x-ms-file-change-time" : "2021-06-11T20:38:57.2292239Z", + "x-ms-file-parent-id" : "0", + "eTag" : "0x8D92D18EF9F408F", + "x-ms-request-id" : "a2a9691c-b01a-0006-1901-5f3a43000000", + "x-ms-client-request-id" : "cb66ec32-04db-4603-879b-2b678527708d", + "x-ms-file-last-write-time" : "2021-06-11T20:38:57.2292239Z" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.file.core.windows.net/f512853bf512853ba5d96897ed14530f76c24af68a/f512853bf512853ba5d030498ecc8619dee9457ea0?comp=range", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-share/12.11.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "f0f63678-d851-41c4-a498-4ba44277f216", + "Content-Type" : "application/octet-stream" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D18EFB5AB86", + "Last-Modified" : "Fri, 11 Jun 2021 20:38:57 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "a2a96921-b01a-0006-1e01-5f3a43000000", + "x-ms-request-server-encrypted" : "true", + "x-ms-client-request-id" : "f0f63678-d851-41c4-a498-4ba44277f216", + "Date" : "Fri, 11 Jun 2021 20:38:57 GMT", + "Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==" + }, + "Exception" : null + }, { + "Method" : "GET", + "Uri" : "https://REDACTED.file.core.windows.net/f512853bf512853ba5d96897ed14530f76c24af68a/f512853bf512853ba5d030498ecc8619dee9457ea0", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-share/12.11.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "2ac16644-795c-4a1f-9fb2-84410929ded2" + }, + "Response" : { + "content-length" : "7", + "x-ms-version" : "2020-08-04", + "x-ms-lease-status" : "unlocked", + "x-ms-file-permission-key" : "16466167399171598336*5486365400479318158", + "x-ms-file-id" : "13835128424026341376", + "Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-file-creation-time" : "2021-06-11T20:38:57.2292239Z", + "x-ms-lease-state" : "available", + "Last-Modified" : "Fri, 11 Jun 2021 20:38:57 GMT", + "retry-after" : "0", + "StatusCode" : "200", + "Date" : "Fri, 11 Jun 2021 20:38:57 GMT", + "Accept-Ranges" : "bytes", + "x-ms-server-encrypted" : "true", + "x-ms-type" : "File", + "x-ms-file-attributes" : "Archive", + "x-ms-file-change-time" : "2021-06-11T20:38:57.2292239Z", + "x-ms-file-parent-id" : "0", + "eTag" : "0x8D92D18EFB5AB86", + "x-ms-request-id" : "a2a96926-b01a-0006-2301-5f3a43000000", + "Body" : "ZGVmYXVsdA==", + "x-ms-client-request-id" : "2ac16644-795c-4a1f-9fb2-84410929ded2", + "x-ms-file-last-write-time" : "2021-06-11T20:38:57.2292239Z", + "Content-Type" : "application/octet-stream" + }, + "Exception" : null + } ], + "variables" : [ "f512853bf512853ba5d96897ed14530f76c24af68a", "f512853bf512853ba5d030498ecc8619dee9457ea0" ] +} \ No newline at end of file diff --git a/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsParallelUploadInputStreamNoLength.json b/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsParallelUploadInputStreamNoLength.json new file mode 100644 index 0000000000000..3d35e8ab7776a --- /dev/null +++ b/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsParallelUploadInputStreamNoLength.json @@ -0,0 +1,113 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.file.core.windows.net/06d1f4b406d1f4b4d147241719daf300951a400f8a?restype=share", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-share/12.11.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "10855499-32ba-445e-ac81-164fa6002846" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D18E36110D8", + "Last-Modified" : "Fri, 11 Jun 2021 20:38:36 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "98342349-d01a-002c-1701-5f2fd5000000", + "x-ms-client-request-id" : "10855499-32ba-445e-ac81-164fa6002846", + "Date" : "Fri, 11 Jun 2021 20:38:36 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.file.core.windows.net/06d1f4b406d1f4b4d147241719daf300951a400f8a/06d1f4b406d1f4b4d14307476443b64ab6ef4da694", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-share/12.11.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "db6631d0-5c03-44dd-b8ea-c6211c91b877" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "x-ms-file-permission-key" : "16466167399171598336*5486365400479318158", + "x-ms-file-id" : "13835128424026341376", + "Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-file-creation-time" : "2021-06-11T20:38:36.9606164Z", + "Last-Modified" : "Fri, 11 Jun 2021 20:38:36 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "Date" : "Fri, 11 Jun 2021 20:38:36 GMT", + "x-ms-file-attributes" : "Archive", + "x-ms-file-change-time" : "2021-06-11T20:38:36.9606164Z", + "x-ms-file-parent-id" : "0", + "eTag" : "0x8D92D18E38A8214", + "x-ms-request-id" : "9834234c-d01a-002c-1801-5f2fd5000000", + "x-ms-client-request-id" : "db6631d0-5c03-44dd-b8ea-c6211c91b877", + "x-ms-file-last-write-time" : "2021-06-11T20:38:36.9606164Z" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.file.core.windows.net/06d1f4b406d1f4b4d147241719daf300951a400f8a/06d1f4b406d1f4b4d14307476443b64ab6ef4da694?comp=range", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-share/12.11.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "4527982f-a144-4947-a767-8228c864b0db", + "Content-Type" : "application/octet-stream" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92D18E3A27370", + "Last-Modified" : "Fri, 11 Jun 2021 20:38:37 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "9834234e-d01a-002c-1901-5f2fd5000000", + "x-ms-request-server-encrypted" : "true", + "x-ms-client-request-id" : "4527982f-a144-4947-a767-8228c864b0db", + "Date" : "Fri, 11 Jun 2021 20:38:36 GMT", + "Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==" + }, + "Exception" : null + }, { + "Method" : "GET", + "Uri" : "https://REDACTED.file.core.windows.net/06d1f4b406d1f4b4d147241719daf300951a400f8a/06d1f4b406d1f4b4d14307476443b64ab6ef4da694", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-share/12.11.0-beta.1 (11.0.9; Windows 10; 10.0)", + "x-ms-client-request-id" : "93b2f2c1-8bde-422c-9ab0-a17998001c21" + }, + "Response" : { + "content-length" : "7", + "x-ms-version" : "2020-08-04", + "x-ms-lease-status" : "unlocked", + "x-ms-file-permission-key" : "16466167399171598336*5486365400479318158", + "x-ms-file-id" : "13835128424026341376", + "Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-file-creation-time" : "2021-06-11T20:38:36.9606164Z", + "x-ms-lease-state" : "available", + "Last-Modified" : "Fri, 11 Jun 2021 20:38:37 GMT", + "retry-after" : "0", + "StatusCode" : "200", + "Date" : "Fri, 11 Jun 2021 20:38:36 GMT", + "Accept-Ranges" : "bytes", + "x-ms-server-encrypted" : "true", + "x-ms-type" : "File", + "x-ms-file-attributes" : "Archive", + "x-ms-file-change-time" : "2021-06-11T20:38:36.9606164Z", + "x-ms-file-parent-id" : "0", + "eTag" : "0x8D92D18E3A27370", + "x-ms-request-id" : "9834234f-d01a-002c-1a01-5f2fd5000000", + "Body" : "ZGVmYXVsdA==", + "x-ms-client-request-id" : "93b2f2c1-8bde-422c-9ab0-a17998001c21", + "x-ms-file-last-write-time" : "2021-06-11T20:38:36.9606164Z", + "Content-Type" : "application/octet-stream" + }, + "Exception" : null + } ], + "variables" : [ "06d1f4b406d1f4b4d147241719daf300951a400f8a", "06d1f4b406d1f4b4d14307476443b64ab6ef4da694" ] +} \ No newline at end of file diff --git a/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsUploadSuccessfulRetry.json b/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsUploadSuccessfulRetry.json new file mode 100644 index 0000000000000..4d68fa9eb6aef --- /dev/null +++ b/sdk/storage/azure-storage-file-share/src/test/resources/session-records/FileAPITestsUploadSuccessfulRetry.json @@ -0,0 +1,113 @@ +{ + "networkCallRecords" : [ { + "Method" : "PUT", + "Uri" : "https://REDACTED.file.core.windows.net/0fb1a1900fb1a1908191566300f0867bfd7544d9af?restype=share", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-share/12.11.0-beta.1 (11.0.11; Windows 10; 10.0)", + "x-ms-client-request-id" : "ee4bc2da-20a7-42c8-917e-77c855f7cb74" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92F8BC505CAAC", + "Last-Modified" : "Mon, 14 Jun 2021 23:26:00 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "91326dab-101a-001b-4574-6145f9000000", + "x-ms-client-request-id" : "ee4bc2da-20a7-42c8-917e-77c855f7cb74", + "Date" : "Mon, 14 Jun 2021 23:25:59 GMT" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.file.core.windows.net/0fb1a1900fb1a1908191566300f0867bfd7544d9af/0fb1a1900fb1a190819102195599961687f44d1c9c", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-share/12.11.0-beta.1 (11.0.11; Windows 10; 10.0)", + "x-ms-client-request-id" : "c858ad4c-3ee9-4b6a-b9d7-f6ad6359086c" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "x-ms-file-permission-key" : "16466167399171598336*5486365400479318158", + "x-ms-file-id" : "13835128424026341376", + "Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-file-creation-time" : "2021-06-14T23:26:00.4745078Z", + "Last-Modified" : "Mon, 14 Jun 2021 23:26:00 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-server-encrypted" : "true", + "Date" : "Mon, 14 Jun 2021 23:25:59 GMT", + "x-ms-file-attributes" : "Archive", + "x-ms-file-change-time" : "2021-06-14T23:26:00.4745078Z", + "x-ms-file-parent-id" : "0", + "eTag" : "0x8D92F8BC52E5B76", + "x-ms-request-id" : "91326dae-101a-001b-4674-6145f9000000", + "x-ms-client-request-id" : "c858ad4c-3ee9-4b6a-b9d7-f6ad6359086c", + "x-ms-file-last-write-time" : "2021-06-14T23:26:00.4745078Z" + }, + "Exception" : null + }, { + "Method" : "PUT", + "Uri" : "https://REDACTED.file.core.windows.net/0fb1a1900fb1a1908191566300f0867bfd7544d9af/0fb1a1900fb1a190819102195599961687f44d1c9c?comp=range", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-share/12.11.0-beta.1 (11.0.11; Windows 10; 10.0)", + "x-ms-client-request-id" : "a98c04ce-690c-4b43-93e9-69533d3db005", + "Content-Type" : "application/octet-stream" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2020-08-04", + "Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0", + "eTag" : "0x8D92F8BC7B8C774", + "Last-Modified" : "Mon, 14 Jun 2021 23:26:04 GMT", + "retry-after" : "0", + "StatusCode" : "201", + "x-ms-request-id" : "91326dcc-101a-001b-5f74-6145f9000000", + "x-ms-request-server-encrypted" : "true", + "x-ms-client-request-id" : "a98c04ce-690c-4b43-93e9-69533d3db005", + "Date" : "Mon, 14 Jun 2021 23:26:04 GMT", + "Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==" + }, + "Exception" : null + }, { + "Method" : "GET", + "Uri" : "https://REDACTED.file.core.windows.net/0fb1a1900fb1a1908191566300f0867bfd7544d9af/0fb1a1900fb1a190819102195599961687f44d1c9c", + "Headers" : { + "x-ms-version" : "2020-08-04", + "User-Agent" : "azsdk-java-azure-storage-file-share/12.11.0-beta.1 (11.0.11; Windows 10; 10.0)", + "x-ms-client-request-id" : "6c380518-124b-401d-933c-30b5d7e698bb" + }, + "Response" : { + "content-length" : "7", + "x-ms-version" : "2020-08-04", + "x-ms-lease-status" : "unlocked", + "x-ms-file-permission-key" : "16466167399171598336*5486365400479318158", + "x-ms-file-id" : "13835128424026341376", + "Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-file-creation-time" : "2021-06-14T23:26:00.4745078Z", + "x-ms-lease-state" : "available", + "Last-Modified" : "Mon, 14 Jun 2021 23:26:04 GMT", + "retry-after" : "0", + "StatusCode" : "200", + "Date" : "Mon, 14 Jun 2021 23:26:04 GMT", + "Accept-Ranges" : "bytes", + "x-ms-server-encrypted" : "true", + "x-ms-type" : "File", + "x-ms-file-attributes" : "Archive", + "x-ms-file-change-time" : "2021-06-14T23:26:00.4745078Z", + "x-ms-file-parent-id" : "0", + "eTag" : "0x8D92F8BC7B8C774", + "x-ms-request-id" : "91326dcd-101a-001b-6074-6145f9000000", + "Body" : "ZGVmYXVsdA==", + "x-ms-client-request-id" : "6c380518-124b-401d-933c-30b5d7e698bb", + "x-ms-file-last-write-time" : "2021-06-14T23:26:00.4745078Z", + "Content-Type" : "application/octet-stream" + }, + "Exception" : null + } ], + "variables" : [ "0fb1a1900fb1a1908191566300f0867bfd7544d9af", "0fb1a1900fb1a190819102195599961687f44d1c9c" ] +} \ No newline at end of file