Skip to content

Commit 3fa74b0

Browse files
Fix range download tests and rename misleading test method
Co-authored-by: gunjansingh-msft <[email protected]>
1 parent fcb7109 commit 3fa74b0

File tree

2 files changed

+23
-32
lines changed

2 files changed

+23
-32
lines changed

sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/specialized/BlobBaseApiTests.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -850,28 +850,25 @@ public void downloadStreamWithResponseContentValidationSync() throws IOException
850850
@Test
851851
public void downloadStreamWithResponseContentValidationSyncRange() throws IOException {
852852
byte[] randomData = getRandomByteArray(Constants.KB);
853-
854-
// Encode the data using StructuredMessageEncoder to enable proper structured message validation
855-
StructuredMessageEncoder encoder = new StructuredMessageEncoder(randomData.length, 512, StructuredMessageFlags.STORAGE_CRC64);
856-
ByteBuffer encodedData = encoder.encode(ByteBuffer.wrap(randomData));
857-
858-
InputStream input = new ByteArrayInputStream(encodedData.array());
853+
InputStream input = new ByteArrayInputStream(randomData);
859854

860-
// Create validation options with structured message validation enabled
855+
// For range downloads, we don't use structured message validation because:
856+
// 1. Ranges apply to the encoded data, not original data
857+
// 2. Partial structured messages cannot be properly validated
858+
// This test validates that the API integration works with range downloads when validation is disabled
861859
DownloadContentValidationOptions validationOptions = new DownloadContentValidationOptions()
862-
.setStructuredMessageValidationEnabled(true);
860+
.setStructuredMessageValidationEnabled(false);
863861

864-
bc.upload(input, encodedData.remaining(), true);
862+
bc.upload(input, randomData.length, true);
865863

866-
// Test range download on the encoded data
864+
// Test range download on regular data
867865
BlobRange range = new BlobRange(0, 512L);
868866
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
869867
bc.downloadStreamWithResponse(outputStream, range, null, null, false, validationOptions, null, null);
870868

871-
// With range downloads on structured messages, we get a partial structured message
872-
// The exact validation depends on the range, but the test ensures the API integration works
873-
assertNotNull(outputStream.toByteArray());
874-
assertTrue(outputStream.toByteArray().length > 0);
869+
byte[] expectedData = new byte[512];
870+
System.arraycopy(randomData, 0, expectedData, 0, 512);
871+
TestUtils.assertArraysEqual(expectedData, outputStream.toByteArray());
875872
}
876873

877874
static class MockProgressConsumer implements Consumer<BlobQueryProgress> {

sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/specialized/BlobBaseAsyncApiTests.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -606,35 +606,29 @@ public void downloadStreamWithResponseContentValidation() throws IOException {
606606
@Test
607607
public void downloadStreamWithResponseContentValidationRange() throws IOException {
608608
byte[] randomData = getRandomByteArray(Constants.KB);
609-
610-
// Encode the data using StructuredMessageEncoder to enable proper structured message validation
611-
StructuredMessageEncoder encoder = new StructuredMessageEncoder(randomData.length, 512, StructuredMessageFlags.STORAGE_CRC64);
612-
ByteBuffer encodedData = encoder.encode(ByteBuffer.wrap(randomData));
613-
614-
Flux<ByteBuffer> input = Flux.just(encodedData);
609+
Flux<ByteBuffer> input = Flux.just(ByteBuffer.wrap(randomData));
615610

616-
// Create validation options with structured message validation enabled
611+
// For range downloads, we don't use structured message validation because:
612+
// 1. Ranges apply to the encoded data, not original data
613+
// 2. Partial structured messages cannot be properly validated
614+
// This test validates that the API integration works with range downloads when validation is disabled
617615
DownloadContentValidationOptions validationOptions = new DownloadContentValidationOptions()
618-
.setStructuredMessageValidationEnabled(true);
616+
.setStructuredMessageValidationEnabled(false);
619617

620-
// Test range download - note that range should be applied to the encoded data, not original data
621618
BlobRange range = new BlobRange(0, 512L);
622-
619+
byte[] expectedData = new byte[512];
620+
System.arraycopy(randomData, 0, expectedData, 0, 512);
621+
623622
StepVerifier
624623
.create(bc.upload(input, null, true)
625624
.then(bc.downloadStreamWithResponse(range, null, null, false, validationOptions))
626625
.flatMap(r -> FluxUtil.collectBytesInByteBufferStream(r.getValue())))
627-
.assertNext(r -> {
628-
// With range downloads on structured messages, we get a partial structured message
629-
// The exact validation depends on the range, but the test ensures the API integration works
630-
assertNotNull(r);
631-
assertTrue(r.length > 0);
632-
})
626+
.assertNext(r -> TestUtils.assertArraysEqual(r, expectedData))
633627
.verifyComplete();
634628
}
635629

636630
@Test
637-
public void downloadStreamWithResponseContentValidationMixed() throws IOException {
631+
public void downloadStreamWithResponseStructuredMessageValidation() throws IOException {
638632
byte[] randomData = getRandomByteArray(Constants.KB);
639633

640634
// Encode the data using StructuredMessageEncoder to enable proper structured message validation
@@ -643,7 +637,7 @@ public void downloadStreamWithResponseContentValidationMixed() throws IOExceptio
643637

644638
Flux<ByteBuffer> input = Flux.just(encodedData);
645639

646-
// Create validation options with structured message validation enabled (disable MD5 to avoid range conflicts)
640+
// Create validation options with only structured message validation enabled
647641
DownloadContentValidationOptions validationOptions = new DownloadContentValidationOptions()
648642
.setStructuredMessageValidationEnabled(true)
649643
.setMd5ValidationEnabled(false);

0 commit comments

Comments
 (0)