Skip to content

Commit cf628de

Browse files
authored
test: Adding Integration tests for custom crc32 in uploadPart
2 parents 763293b + 6b14271 commit cf628de

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITMultipartUploadClientTest.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import java.io.OutputStream;
5555
import java.nio.ByteBuffer;
5656
import java.nio.channels.FileChannel;
57+
import java.nio.charset.StandardCharsets;
5758
import java.nio.file.Files;
5859
import java.nio.file.Path;
5960
import java.nio.file.StandardOpenOption;
@@ -246,6 +247,59 @@ public void testComplete_wrongETag() {
246247
}
247248
}
248249

250+
@Test
251+
public void testUploadPart_withCustomChecksum() throws IOException {
252+
BlobInfo info = BlobInfo.newBuilder(bucket, generator.randomObjectName()).build();
253+
CreateMultipartUploadResponse createResponse = createMultipartUpload(info);
254+
String uploadId = createResponse.uploadId();
255+
256+
ChecksummedTestContent content =
257+
ChecksummedTestContent.of("hello world".getBytes(StandardCharsets.UTF_8));
258+
259+
UploadPartRequest request =
260+
UploadPartRequest.builder()
261+
.bucket(info.getBucket())
262+
.key(info.getName())
263+
.uploadId(uploadId)
264+
.partNumber(1)
265+
.crc32c(content.getCrc32cBase64())
266+
.build();
267+
UploadPartResponse response =
268+
multipartUploadClient.uploadPart(request, RequestBody.of(content.asByteBuffer()));
269+
assertThat(response).isNotNull();
270+
assertThat(response.eTag()).isNotNull();
271+
272+
abortMultipartUpload(info, uploadId);
273+
}
274+
275+
@Test
276+
public void testUploadPart_withCustomChecksum_fail() throws IOException {
277+
BlobInfo info = BlobInfo.newBuilder(bucket, generator.randomObjectName()).build();
278+
CreateMultipartUploadResponse createResponse = createMultipartUpload(info);
279+
String uploadId = createResponse.uploadId();
280+
281+
ChecksummedTestContent content =
282+
ChecksummedTestContent.of("hello world".getBytes(StandardCharsets.UTF_8));
283+
284+
UploadPartRequest request =
285+
UploadPartRequest.builder()
286+
.bucket(info.getBucket())
287+
.key(info.getName())
288+
.uploadId(uploadId)
289+
.partNumber(1)
290+
.crc32c("1234") // Invalid checksum
291+
.build();
292+
try {
293+
multipartUploadClient.uploadPart(request, RequestBody.of(content.asByteBuffer()));
294+
fail("Expected StorageException");
295+
} catch (StorageException e) {
296+
assertThat(e.getMessage())
297+
.contains("The CRC32C you specified did not match what we computed.");
298+
} finally {
299+
abortMultipartUpload(info, uploadId);
300+
}
301+
}
302+
249303
private void doTest(int objectSizeBytes) throws IOException {
250304
BlobInfo info = BlobInfo.newBuilder(bucket, generator.randomObjectName()).build();
251305

0 commit comments

Comments
 (0)