|
6 | 6 | import com.azure.core.http.rest.Response; |
7 | 7 | import com.azure.core.util.BinaryData; |
8 | 8 | import com.azure.core.util.Context; |
| 9 | +import com.azure.core.util.ProgressListener; |
9 | 10 | import com.azure.storage.blob.BlobClient; |
10 | 11 | import com.azure.storage.blob.BlobTestBase; |
11 | 12 | import com.azure.storage.blob.models.BlockBlobItem; |
|
30 | 31 | import static org.junit.jupiter.api.Assertions.assertEquals; |
31 | 32 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
32 | 33 | import static org.junit.jupiter.api.Assertions.assertNull; |
| 34 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
33 | 35 |
|
34 | 36 | @LiveOnly |
35 | 37 | public class BlobMessageEncoderUploadTests extends BlobTestBase { |
@@ -86,6 +88,44 @@ public void uploadBinaryDataChunkedStructMess() { |
86 | 88 | assertArrayEquals(data, outStream.toByteArray()); |
87 | 89 | } |
88 | 90 |
|
| 91 | + @Test |
| 92 | + public void uploadBinaryDataChunkedStructMessProgressListener() { |
| 93 | + long size = Constants.MB * 10; |
| 94 | + byte[] data = getRandomByteArray((int) size); |
| 95 | + long blockSize = (long) Constants.MB * 2; |
| 96 | + |
| 97 | + Listener uploadListenerChecksum = new Listener(blockSize); |
| 98 | + |
| 99 | + Listener uploadListenerNoChecksum = new Listener(blockSize); |
| 100 | + |
| 101 | + BlobParallelUploadOptions optionsChecksum = new BlobParallelUploadOptions(BinaryData.fromBytes(data)) |
| 102 | + .setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO) |
| 103 | + .setParallelTransferOptions( |
| 104 | + new ParallelTransferOptions().setMaxSingleUploadSizeLong((long) Constants.MB * 2) |
| 105 | + .setBlockSizeLong(blockSize) |
| 106 | + .setProgressListener(uploadListenerChecksum)); |
| 107 | + |
| 108 | + BlobParallelUploadOptions optionsNoChecksum = new BlobParallelUploadOptions(BinaryData.fromBytes(data)) |
| 109 | + .setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO) |
| 110 | + .setParallelTransferOptions( |
| 111 | + new ParallelTransferOptions().setMaxSingleUploadSizeLong((long) Constants.MB * 2) |
| 112 | + .setBlockSizeLong(blockSize) |
| 113 | + .setProgressListener(uploadListenerNoChecksum)); |
| 114 | + |
| 115 | + bc.uploadWithResponse(optionsChecksum, null, Context.NONE); |
| 116 | + bc.uploadWithResponse(optionsNoChecksum, null, Context.NONE); |
| 117 | + |
| 118 | + assertTrue(uploadListenerChecksum.getReportingCount() >= (size / blockSize)); |
| 119 | + assertTrue(uploadListenerNoChecksum.getReportingCount() >= (size / blockSize)); |
| 120 | + |
| 121 | + assertEquals(uploadListenerNoChecksum.getReportingCount(), uploadListenerChecksum.getReportingCount()); |
| 122 | + assertEquals(uploadListenerNoChecksum.getReportedByteCount(), uploadListenerChecksum.getReportedByteCount()); |
| 123 | + |
| 124 | + System.out.println( |
| 125 | + uploadListenerChecksum.getReportingCount() + " " + uploadListenerChecksum.getReportedByteCount() + " " |
| 126 | + + uploadListenerNoChecksum.getReportingCount() + " " + uploadListenerNoChecksum.getReportedByteCount()); |
| 127 | + } |
| 128 | + |
89 | 129 | @Test |
90 | 130 | public void uploadInputStreamFullCRCHeader() { |
91 | 131 | BlobParallelUploadOptions options = new BlobParallelUploadOptions(DATA.getDefaultInputStream()) |
@@ -178,4 +218,29 @@ public void uploadFluxChunkedStructMess() { |
178 | 218 |
|
179 | 219 | assertArrayEquals(data, outStream.toByteArray()); |
180 | 220 | } |
| 221 | + |
| 222 | + static class Listener implements ProgressListener { |
| 223 | + private final long blockSize; |
| 224 | + private long reportingCount; |
| 225 | + private long reportedByteCount; |
| 226 | + |
| 227 | + Listener(long blockSize) { |
| 228 | + this.blockSize = blockSize; |
| 229 | + } |
| 230 | + |
| 231 | + @Override |
| 232 | + public void handleProgress(long bytesTransferred) { |
| 233 | + assertEquals(0, bytesTransferred % blockSize); |
| 234 | + this.reportingCount += 1; |
| 235 | + this.reportedByteCount = bytesTransferred; |
| 236 | + } |
| 237 | + |
| 238 | + long getReportingCount() { |
| 239 | + return this.reportingCount; |
| 240 | + } |
| 241 | + |
| 242 | + long getReportedByteCount() { |
| 243 | + return this.reportedByteCount; |
| 244 | + } |
| 245 | + } |
181 | 246 | } |
0 commit comments