Skip to content

Commit f1a6a8b

Browse files
committed
updating tests
1 parent 72d5ee9 commit f1a6a8b

File tree

6 files changed

+200
-102
lines changed

6 files changed

+200
-102
lines changed

sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/contentValidation/BlobMessageEncoderUploadTests.java

Lines changed: 69 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818
import reactor.core.publisher.Flux;
1919

2020
import java.io.ByteArrayInputStream;
21+
import java.io.ByteArrayOutputStream;
22+
import java.nio.ByteBuffer;
2123

2224
import static com.azure.storage.common.implementation.Constants.HeaderConstants.CONTENT_CRC64_HEADER_NAME;
2325
import static com.azure.storage.common.implementation.Constants.HeaderConstants.STRUCTURED_BODY_TYPE_HEADER_NAME;
24-
import static com.azure.storage.common.implementation.structuredmessage.StructuredMessageConstants.STRUCTUED_BODY_TYPE;
26+
import static com.azure.storage.common.implementation.structuredmessage.StructuredMessageConstants.STRUCTURED_BODY_TYPE_VALUE;
27+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
2528
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2629
import static org.junit.jupiter.api.Assertions.assertEquals;
2730
import static org.junit.jupiter.api.Assertions.assertNotNull;
31+
import static org.junit.jupiter.api.Assertions.assertNull;
2832

2933
public class BlobMessageEncoderUploadTests extends BlobTestBase {
3034
private BlobClient bc;
@@ -41,32 +45,43 @@ public void uploadBinaryDataFullCRCHeader() {
4145

4246
Response<BlockBlobItem> response = bc.uploadWithResponse(options, null, Context.NONE);
4347
assertNotNull(response.getRequest().getHeaders().getValue(CONTENT_CRC64_HEADER_NAME));
48+
assertNull(response.getRequest().getHeaders().getValue(STRUCTURED_BODY_TYPE_HEADER_NAME));
4449
}
4550

4651
@Test
4752
public void uploadBinaryDataFullStructMess() {
48-
BlobParallelUploadOptions options
49-
= new BlobParallelUploadOptions(BinaryData.fromBytes(getRandomByteArray(Constants.MB * 5)))
50-
.setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO);
53+
byte[] data = getRandomByteArray(Constants.MB * 5);
54+
55+
BlobParallelUploadOptions options = new BlobParallelUploadOptions(BinaryData.fromBytes(data))
56+
.setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO);
5157

5258
Response<BlockBlobItem> response = bc.uploadWithResponse(options, null, Context.NONE);
53-
assertEquals(STRUCTUED_BODY_TYPE,
59+
60+
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
61+
bc.downloadStream(outStream);
62+
63+
assertArrayEquals(data, outStream.toByteArray());
64+
65+
assertEquals(STRUCTURED_BODY_TYPE_VALUE,
5466
response.getRequest().getHeaders().getValue(STRUCTURED_BODY_TYPE_HEADER_NAME));
5567
}
5668

5769
@Test
5870
public void uploadBinaryDataChunkedStructMess() {
59-
BlobParallelUploadOptions options
60-
= new BlobParallelUploadOptions(BinaryData.fromBytes(getRandomByteArray(Constants.MB * 8)))
61-
.setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO)
62-
.setParallelTransferOptions(
63-
new ParallelTransferOptions().setMaxSingleUploadSizeLong((long) Constants.MB * 4));
71+
byte[] data = getRandomByteArray(Constants.MB * 10);
72+
73+
BlobParallelUploadOptions options = new BlobParallelUploadOptions(BinaryData.fromBytes(data))
74+
.setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO)
75+
.setParallelTransferOptions(
76+
new ParallelTransferOptions().setMaxSingleUploadSizeLong((long) Constants.MB * 2)
77+
.setBlockSizeLong((long) Constants.MB * 2));
6478

6579
assertDoesNotThrow(() -> bc.uploadWithResponse(options, null, Context.NONE));
6680

67-
// Response<BlockBlobItem> response = bc.uploadWithResponse(options, null, Context.NONE);
68-
// assertEquals(STRUCTURED_BODY_TYPE,
69-
// response.getRequest().getHeaders().getValue(STRUCTURED_BODY_TYPE_HEADER_NAME));
81+
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
82+
bc.downloadStream(outStream);
83+
84+
assertArrayEquals(data, outStream.toByteArray());
7085
}
7186

7287
@Test
@@ -76,33 +91,45 @@ public void uploadInputStreamFullCRCHeader() {
7691

7792
Response<BlockBlobItem> response = bc.uploadWithResponse(options, null, Context.NONE);
7893
assertNotNull(response.getRequest().getHeaders().getValue(CONTENT_CRC64_HEADER_NAME));
94+
assertNull(response.getRequest().getHeaders().getValue(STRUCTURED_BODY_TYPE_HEADER_NAME));
7995
}
8096

8197
@Test
8298
public void uploadInputStreamFullStructMess() {
83-
byte[] randomData = getRandomByteArray(Constants.MB * 5);
84-
ByteArrayInputStream input = new ByteArrayInputStream(randomData);
99+
byte[] data = getRandomByteArray(Constants.MB * 5);
100+
101+
ByteArrayInputStream input = new ByteArrayInputStream(data);
85102
BlobParallelUploadOptions options
86103
= new BlobParallelUploadOptions(input).setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO);
87104

88105
Response<BlockBlobItem> response = bc.uploadWithResponse(options, null, Context.NONE);
89-
assertEquals(STRUCTUED_BODY_TYPE,
106+
107+
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
108+
bc.downloadStream(outStream);
109+
110+
assertArrayEquals(data, outStream.toByteArray());
111+
112+
assertEquals(STRUCTURED_BODY_TYPE_VALUE,
90113
response.getRequest().getHeaders().getValue(STRUCTURED_BODY_TYPE_HEADER_NAME));
91114
}
92115

93116
@Test
94117
public void uploadInputStreamChunkedStructMess() {
95-
byte[] randomData = getRandomByteArray(Constants.MB * 8);
96-
ByteArrayInputStream input = new ByteArrayInputStream(randomData);
118+
byte[] data = getRandomByteArray(Constants.MB * 10);
119+
120+
ByteArrayInputStream input = new ByteArrayInputStream(data);
97121
BlobParallelUploadOptions options
98122
= new BlobParallelUploadOptions(input).setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO)
99123
.setParallelTransferOptions(
100-
new ParallelTransferOptions().setMaxSingleUploadSizeLong((long) Constants.MB * 4));
124+
new ParallelTransferOptions().setMaxSingleUploadSizeLong((long) Constants.MB * 2)
125+
.setBlockSizeLong((long) Constants.MB * 2));
101126

102127
assertDoesNotThrow(() -> bc.uploadWithResponse(options, null, Context.NONE));
103-
// Response<BlockBlobItem> response = bc.uploadWithResponse(options, null, Context.NONE);
104-
// assertEquals(STRUCTURED_BODY_TYPE,
105-
// response.getRequest().getHeaders().getValue(STRUCTURED_BODY_TYPE_HEADER_NAME));
128+
129+
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
130+
bc.downloadStream(outStream);
131+
132+
assertArrayEquals(data, outStream.toByteArray());
106133
}
107134

108135
@Test
@@ -112,28 +139,41 @@ public void uploadFluxFullCRCHeader() {
112139

113140
Response<BlockBlobItem> response = bc.uploadWithResponse(options, null, Context.NONE);
114141
assertNotNull(response.getRequest().getHeaders().getValue(CONTENT_CRC64_HEADER_NAME));
142+
assertNull(response.getRequest().getHeaders().getValue(STRUCTURED_BODY_TYPE_HEADER_NAME));
115143
}
116144

117145
@Test
118146
public void uploadFluxFullStructMess() {
119-
BlobParallelUploadOptions options = new BlobParallelUploadOptions(Flux.just(getRandomData(Constants.MB * 5)))
147+
byte[] data = getRandomByteArray(Constants.MB * 5);
148+
149+
BlobParallelUploadOptions options = new BlobParallelUploadOptions(Flux.just(ByteBuffer.wrap(data)))
120150
.setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO);
121151

122152
Response<BlockBlobItem> response = bc.uploadWithResponse(options, null, Context.NONE);
123-
assertEquals(STRUCTUED_BODY_TYPE,
153+
154+
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
155+
bc.downloadStream(outStream);
156+
157+
assertArrayEquals(data, outStream.toByteArray());
158+
159+
assertEquals(STRUCTURED_BODY_TYPE_VALUE,
124160
response.getRequest().getHeaders().getValue(STRUCTURED_BODY_TYPE_HEADER_NAME));
125161
}
126162

127163
@Test
128164
public void uploadFluxChunkedStructMess() {
129-
BlobParallelUploadOptions options = new BlobParallelUploadOptions(Flux.just(getRandomData(Constants.MB * 8)))
165+
byte[] data = getRandomByteArray(Constants.MB * 10);
166+
167+
BlobParallelUploadOptions options = new BlobParallelUploadOptions(Flux.just(ByteBuffer.wrap(data)))
130168
.setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO)
131169
.setParallelTransferOptions(
132-
new ParallelTransferOptions().setMaxSingleUploadSizeLong((long) Constants.MB * 4));
170+
new ParallelTransferOptions().setMaxSingleUploadSizeLong((long) Constants.MB * 2)
171+
.setBlockSizeLong((long) Constants.MB * 2));
133172

134173
assertDoesNotThrow(() -> bc.uploadWithResponse(options, null, Context.NONE));
135-
// Response<BlockBlobItem> response = bc.uploadWithResponse(options, null, Context.NONE);
136-
// assertEquals(STRUCTURED_BODY_TYPE,
137-
// response.getRequest().getHeaders().getValue(STRUCTURED_BODY_TYPE_HEADER_NAME));
174+
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
175+
bc.downloadStream(outStream);
176+
177+
assertArrayEquals(data, outStream.toByteArray());
138178
}
139179
}

sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/implementation/structuredmessage/StructuredMessageConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ public final class StructuredMessageConstants {
4040
/**
4141
* The header name for the CRC64 checksum.
4242
*/
43-
public static final String STRUCTUED_BODY_TYPE = "XSM/1.0; properties=crc64";
43+
public static final String STRUCTURED_BODY_TYPE_VALUE = "XSM/1.0; properties=crc64";
4444
}

sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/policy/StorageContentValidationPolicy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import static com.azure.storage.common.implementation.Constants.USE_CRC64_CHECKSUM_HEADER_CONTEXT;
2727
import static com.azure.storage.common.implementation.Constants.USE_STRUCTURED_MESSAGE_CONTEXT;
2828
import static com.azure.storage.common.implementation.structuredmessage.StructuredMessageConstants.STATIC_MAXIMUM_ENCODED_DATA_LENGTH;
29-
import static com.azure.storage.common.implementation.structuredmessage.StructuredMessageConstants.STRUCTUED_BODY_TYPE;
29+
import static com.azure.storage.common.implementation.structuredmessage.StructuredMessageConstants.STRUCTURED_BODY_TYPE_VALUE;
3030
import static com.azure.storage.common.implementation.structuredmessage.StructuredMessageConstants.V1_DEFAULT_SEGMENT_CONTENT_LENGTH;
3131

3232
/**
@@ -111,7 +111,7 @@ private void applyStructuredMessage(HttpPipelineCallContext context) {
111111
context.getHttpRequest()
112112
.setHeader(HttpHeaderName.CONTENT_LENGTH, structuredMessageEncoder.getEncodedMessageLength());
113113
// x-ms-structured-body
114-
context.getHttpRequest().setHeader(STRUCTURED_BODY_TYPE_HEADER_NAME, STRUCTUED_BODY_TYPE);
114+
context.getHttpRequest().setHeader(STRUCTURED_BODY_TYPE_HEADER_NAME, STRUCTURED_BODY_TYPE_VALUE);
115115
// x-ms-structured-content-length
116116
context.getHttpRequest()
117117
.setHeader(STRUCTURED_CONTENT_LENGTH_HEADER_NAME, String.valueOf(unencodedContentLength));

sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/contentValidation/DataLakeMessageEncoderUploadTests.java

Lines changed: 66 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
import reactor.core.publisher.Flux;
1717

1818
import java.io.ByteArrayInputStream;
19+
import java.io.ByteArrayOutputStream;
20+
import java.nio.ByteBuffer;
1921

22+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
2023
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2124

2225
public class DataLakeMessageEncoderUploadTests extends DataLakeTestBase {
@@ -32,103 +35,121 @@ public void uploadBinaryDataFullCRCHeader() {
3235
FileParallelUploadOptions options = new FileParallelUploadOptions(DATA.getDefaultBinaryData())
3336
.setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO);
3437

35-
// viewed crc64 header through httptoolkit, unable to retrieve header through the response object
36-
// due to the response object containing the request and response of the flush operation, not the append
37-
// Response<PathInfo> response = fc.uploadWithResponse(options, null, Context.NONE);
38-
// assertNotNull(response.getRequest().getHeaders().getValue(CONTENT_CRC64_HEADER_NAME));
38+
// viewed crc header through httptoolkit, unable to retrieve it through the response object
3939
assertDoesNotThrow(() -> fc.uploadWithResponse(options, null, Context.NONE));
4040
}
4141

4242
@Test
4343
public void uploadBinaryDataFullStructMess() {
44-
FileParallelUploadOptions options
45-
= new FileParallelUploadOptions(BinaryData.fromBytes(getRandomByteArray(Constants.MB * 5)))
46-
.setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO);
44+
byte[] data = getRandomByteArray(Constants.MB * 5);
4745

48-
// viewed structured body type header through httptoolkit, unable to retrieve it through the response object
49-
// Response<PathInfo> response = fc.uploadWithResponse(options, null, Context.NONE);
50-
// assertEquals(STRUCTUED_BODY_TYPE, response.getRequest().getHeaders().getValue(STRUCTURED_BODY_TYPE_HEADER_NAME));
51-
assertDoesNotThrow(() -> fc.uploadWithResponse(options, null, Context.NONE));
46+
FileParallelUploadOptions options = new FileParallelUploadOptions(BinaryData.fromBytes(data))
47+
.setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO);
48+
49+
fc.uploadWithResponse(options, null, Context.NONE);
50+
51+
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
52+
fc.read(outStream);
53+
54+
assertArrayEquals(data, outStream.toByteArray());
5255
}
5356

5457
@Test
5558
public void uploadBinaryDataChunkedStructMess() {
56-
FileParallelUploadOptions options
57-
= new FileParallelUploadOptions(BinaryData.fromBytes(getRandomByteArray(Constants.MB * 8)))
58-
.setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO)
59-
.setParallelTransferOptions(
60-
new ParallelTransferOptions().setMaxSingleUploadSizeLong((long) Constants.MB * 4));
59+
byte[] data = getRandomByteArray(Constants.MB * 10);
6160

62-
assertDoesNotThrow(() -> fc.uploadWithResponse(options, null, Context.NONE));
61+
FileParallelUploadOptions options = new FileParallelUploadOptions(BinaryData.fromBytes(data))
62+
.setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO)
63+
.setParallelTransferOptions(
64+
new ParallelTransferOptions().setMaxSingleUploadSizeLong((long) Constants.MB * 2)
65+
.setBlockSizeLong((long) Constants.MB * 2));
66+
67+
fc.uploadWithResponse(options, null, Context.NONE);
68+
69+
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
70+
fc.read(outStream);
71+
72+
assertArrayEquals(data, outStream.toByteArray());
6373
}
6474

6575
@Test
6676
public void uploadInputStreamFullCRCHeader() {
6777
FileParallelUploadOptions options = new FileParallelUploadOptions(DATA.getDefaultInputStream())
6878
.setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO);
6979

70-
// viewed structured body type header through httptoolkit, unable to retrieve it through the response object
71-
//Response<PathInfo> response = fc.uploadWithResponse(options, null, Context.NONE);
72-
//assertNotNull(response.getRequest().getHeaders().getValue(CONTENT_CRC64_HEADER_NAME));
80+
// viewed crc header through httptoolkit, unable to retrieve it through the response object
7381
assertDoesNotThrow(() -> fc.uploadWithResponse(options, null, Context.NONE));
7482
}
7583

7684
@Test
7785
public void uploadInputStreamFullStructMess() {
78-
byte[] randomData = getRandomByteArray(Constants.MB * 5);
79-
ByteArrayInputStream input = new ByteArrayInputStream(randomData);
80-
FileParallelUploadOptions options
81-
= new FileParallelUploadOptions(input).setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO);
86+
byte[] data = getRandomByteArray(Constants.MB * 5);
87+
FileParallelUploadOptions options = new FileParallelUploadOptions(new ByteArrayInputStream(data))
88+
.setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO);
8289

83-
// viewed structured body type header through httptoolkit, unable to retrieve it through the response object
84-
//Response<PathInfo> response = fc.uploadWithResponse(options, null, Context.NONE);
85-
//assertEquals(STRUCTUED_BODY_TYPE,
86-
// response.getRequest().getHeaders().getValue(STRUCTURED_BODY_TYPE_HEADER_NAME));
87-
assertDoesNotThrow(() -> fc.uploadWithResponse(options, null, Context.NONE));
90+
fc.uploadWithResponse(options, null, Context.NONE);
91+
92+
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
93+
fc.read(outStream);
94+
95+
assertArrayEquals(data, outStream.toByteArray());
8896
}
8997

9098
@Test
9199
public void uploadInputStreamChunkedStructMess() {
92-
byte[] randomData = getRandomByteArray(Constants.MB * 8);
93-
ByteArrayInputStream input = new ByteArrayInputStream(randomData);
100+
byte[] data = getRandomByteArray(Constants.MB * 10);
101+
ByteArrayInputStream input = new ByteArrayInputStream(data);
94102
FileParallelUploadOptions options
95103
= new FileParallelUploadOptions(input).setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO)
96104
.setParallelTransferOptions(
97-
new ParallelTransferOptions().setMaxSingleUploadSizeLong((long) Constants.MB * 4));
105+
new ParallelTransferOptions().setMaxSingleUploadSizeLong((long) Constants.MB * 2)
106+
.setBlockSizeLong((long) Constants.MB * 2));
98107

99-
assertDoesNotThrow(() -> fc.uploadWithResponse(options, null, Context.NONE));
108+
fc.uploadWithResponse(options, null, Context.NONE);
109+
110+
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
111+
fc.read(outStream);
112+
113+
assertArrayEquals(data, outStream.toByteArray());
100114
}
101115

102116
@Test
103117
public void uploadFluxFullCRCHeader() {
104118
FileParallelUploadOptions options = new FileParallelUploadOptions(DATA.getDefaultFlux())
105119
.setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO);
106120

107-
// viewed structured body type header through httptoolkit, unable to retrieve it through the response object
108-
// Response<PathInfo> response = fc.uploadWithResponse(options, null, Context.NONE);
109-
// assertNotNull(response.getRequest().getHeaders().getValue(CONTENT_CRC64_HEADER_NAME));
121+
// viewed crc header through httptoolkit, unable to retrieve it through the response object
110122
assertDoesNotThrow(() -> fc.uploadWithResponse(options, null, Context.NONE));
111123
}
112124

113125
@Test
114126
public void uploadFluxFullStructMess() {
115-
FileParallelUploadOptions options = new FileParallelUploadOptions(Flux.just(getRandomData(Constants.MB * 5)))
127+
byte[] data = getRandomByteArray(Constants.MB * 5);
128+
FileParallelUploadOptions options = new FileParallelUploadOptions(Flux.just(ByteBuffer.wrap(data)))
116129
.setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO);
117130

118-
// viewed structured body type header through httptoolkit, unable to retrieve it through the response object
119-
//Response<PathInfo> response = fc.uploadWithResponse(options, null, Context.NONE);
120-
//assertEquals(STRUCTUED_BODY_TYPE,
121-
//response.getRequest().getHeaders().getValue(STRUCTURED_BODY_TYPE_HEADER_NAME));
122-
assertDoesNotThrow(() -> fc.uploadWithResponse(options, null, Context.NONE));
131+
fc.uploadWithResponse(options, null, Context.NONE);
132+
133+
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
134+
fc.read(outStream);
135+
136+
assertArrayEquals(data, outStream.toByteArray());
123137
}
124138

125139
@Test
126140
public void uploadFluxChunkedStructMess() {
127-
FileParallelUploadOptions options = new FileParallelUploadOptions(Flux.just(getRandomData(Constants.MB * 8)))
141+
byte[] data = getRandomByteArray(Constants.MB * 10);
142+
FileParallelUploadOptions options = new FileParallelUploadOptions(Flux.just(ByteBuffer.wrap(data)))
128143
.setStorageChecksumAlgorithm(StorageChecksumAlgorithm.AUTO)
129144
.setParallelTransferOptions(
130-
new ParallelTransferOptions().setMaxSingleUploadSizeLong((long) Constants.MB * 4));
145+
new ParallelTransferOptions().setMaxSingleUploadSizeLong((long) Constants.MB * 2)
146+
.setBlockSizeLong((long) Constants.MB * 2));
131147

132-
assertDoesNotThrow(() -> fc.uploadWithResponse(options, null, Context.NONE));
148+
fc.uploadWithResponse(options, null, Context.NONE);
149+
150+
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
151+
fc.read(outStream);
152+
153+
assertArrayEquals(data, outStream.toByteArray());
133154
}
134155
}

0 commit comments

Comments
 (0)