|
3 | 3 |
|
4 | 4 | package com.azure.storage.blob.contentValidation; |
5 | 5 |
|
| 6 | +import com.azure.core.http.HttpMethod; |
| 7 | +import com.azure.core.http.HttpRequest; |
6 | 8 | import com.azure.core.http.rest.Response; |
7 | 9 | import com.azure.core.util.BinaryData; |
8 | 10 | import com.azure.core.util.Context; |
9 | 11 | import com.azure.core.util.ProgressListener; |
10 | 12 | import com.azure.storage.blob.BlobClient; |
| 13 | +import com.azure.storage.blob.BlobClientBuilder; |
11 | 14 | import com.azure.storage.blob.BlobTestBase; |
12 | 15 | import com.azure.storage.blob.models.BlockBlobItem; |
13 | 16 | import com.azure.storage.blob.models.ParallelTransferOptions; |
14 | 17 | import com.azure.storage.blob.options.BlobParallelUploadOptions; |
15 | 18 | import com.azure.storage.common.implementation.Constants; |
16 | 19 | import com.azure.storage.common.implementation.structuredmessage.StorageChecksumAlgorithm; |
| 20 | +import com.azure.storage.common.test.shared.StorageCommonTestUtils; |
17 | 21 | import com.azure.storage.common.test.shared.extensions.LiveOnly; |
18 | 22 | import org.junit.jupiter.api.BeforeEach; |
19 | 23 | import org.junit.jupiter.api.Disabled; |
|
23 | 27 | import java.io.ByteArrayInputStream; |
24 | 28 | import java.io.ByteArrayOutputStream; |
25 | 29 | import java.nio.ByteBuffer; |
| 30 | +import java.util.List; |
| 31 | +import java.util.stream.Collectors; |
26 | 32 |
|
27 | 33 | import static com.azure.storage.common.implementation.Constants.HeaderConstants.CONTENT_CRC64_HEADER_NAME; |
28 | 34 | import static com.azure.storage.common.implementation.Constants.HeaderConstants.STRUCTURED_BODY_TYPE_HEADER_NAME; |
|
32 | 38 | import static org.junit.jupiter.api.Assertions.assertEquals; |
33 | 39 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
34 | 40 | import static org.junit.jupiter.api.Assertions.assertNull; |
| 41 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
35 | 42 |
|
36 | 43 | @LiveOnly |
37 | 44 | public class BlobMessageEncoderUploadTests extends BlobTestBase { |
@@ -88,6 +95,40 @@ public void uploadBinaryDataChunkedStructMess() { |
88 | 95 | assertArrayEquals(data, outStream.toByteArray()); |
89 | 96 | } |
90 | 97 |
|
| 98 | + @Test |
| 99 | + void verifyUploadUsingChunkedStructMess() { |
| 100 | + byte[] data = getRandomByteArray(Constants.MB * 10); |
| 101 | + |
| 102 | + BlobParallelUploadOptions options = new BlobParallelUploadOptions(BinaryData.fromBytes(data)) |
| 103 | + .setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO) |
| 104 | + .setParallelTransferOptions( |
| 105 | + new ParallelTransferOptions().setMaxSingleUploadSizeLong((long) Constants.MB * 2) |
| 106 | + .setBlockSizeLong((long) Constants.MB * 2)); |
| 107 | + |
| 108 | + StorageCommonTestUtils.CaptureAllRequestsHttpClient httpClient |
| 109 | + = new StorageCommonTestUtils.CaptureAllRequestsHttpClient( |
| 110 | + StorageCommonTestUtils.getHttpClient(interceptorManager)); |
| 111 | + BlobClient capturingBlobClient = new BlobClientBuilder().endpoint(bc.getBlobUrl()) |
| 112 | + .credential(ENVIRONMENT.getPrimaryAccount().getCredential()) |
| 113 | + .httpClient(httpClient) |
| 114 | + .buildClient(); |
| 115 | + |
| 116 | + capturingBlobClient.uploadWithResponse(options, null, Context.NONE); |
| 117 | + |
| 118 | + List<HttpRequest> putRequests = httpClient.getCapturedRequests() |
| 119 | + .stream() |
| 120 | + .filter(r -> r.getHttpMethod() == HttpMethod.PUT) |
| 121 | + .collect(Collectors.toList()); |
| 122 | + |
| 123 | + // Multipart upload should have at least 2 PUTs (staged + final) |
| 124 | + assertTrue(putRequests.size() >= 2, "Expected multipart upload with multiple PUT requests."); |
| 125 | + |
| 126 | + for (int i = 0; i < putRequests.size() - 1; i++) { |
| 127 | + String headerValue = putRequests.get(i).getHeaders().getValue(STRUCTURED_BODY_TYPE_HEADER_NAME); |
| 128 | + assertNotNull(headerValue, "Missing structured body header on staged PUT index " + i); |
| 129 | + } |
| 130 | + } |
| 131 | + |
91 | 132 | @Test |
92 | 133 | @Disabled |
93 | 134 | public void uploadBinaryDataChunkedStructMessProgressListenerBehavior() { |
|
0 commit comments