|
20 | 20 | import software.amazon.awssdk.core.async.AsyncRequestBody; |
21 | 21 | import software.amazon.awssdk.core.async.AsyncResponseTransformer; |
22 | 22 | import software.amazon.awssdk.core.async.BlockingInputStreamAsyncRequestBody; |
| 23 | +import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; |
| 24 | +import software.amazon.awssdk.core.retry.RetryMode; |
23 | 25 | import software.amazon.awssdk.core.sync.RequestBody; |
24 | 26 | import software.amazon.awssdk.services.s3.S3AsyncClient; |
25 | 27 | import software.amazon.awssdk.services.s3.S3Client; |
|
42 | 44 | import java.security.NoSuchAlgorithmException; |
43 | 45 | import java.security.Provider; |
44 | 46 | import java.security.Security; |
| 47 | +import java.time.Duration; |
45 | 48 | import java.util.concurrent.CompletableFuture; |
46 | 49 | import java.util.concurrent.CompletionException; |
47 | 50 | import java.util.concurrent.ExecutorService; |
@@ -315,64 +318,66 @@ public void failsWhenBothBufferSizeAndDelayedAuthModeEnabled() { |
315 | 318 | .build()); |
316 | 319 | } |
317 | 320 |
|
318 | | - @RepeatedTest(3) |
| 321 | + @Test |
319 | 322 | public void customSetBufferSizeWithLargeObject() throws IOException { |
320 | | - if (testCasePassed) { |
321 | | - return; |
322 | | - } |
323 | | - |
324 | | - final String objectKey = appendTestSuffix("large-object-test-custom-buffer-size"); |
325 | | - |
326 | | - Security.addProvider(new BouncyCastleProvider()); |
327 | | - Provider provider = Security.getProvider("BC"); |
328 | | - |
329 | | - // V3 Client with custom max buffer size 32 MiB. |
330 | | - S3Client v3ClientWithBuffer32MiB = S3EncryptionClient.builder() |
331 | | - .aesKey(AES_KEY) |
332 | | - .cryptoProvider(provider) |
333 | | - .setBufferSize(32 * 1024 * 1024) |
334 | | - .build(); |
335 | | - |
336 | | - // V3 Client with default buffer size (i.e. 64MiB) |
337 | | - // When enableDelayedAuthenticationMode is set to true, delayed authentication mode always takes priority over buffered mode. |
338 | | - S3Client v3ClientWithDelayedAuth = S3EncryptionClient.builder() |
339 | | - .aesKey(AES_KEY) |
340 | | - .cryptoProvider(provider) |
341 | | - .enableDelayedAuthenticationMode(true) |
342 | | - .build(); |
343 | | - |
344 | | - // Tight bound on the custom buffer size limit of 32MiB |
345 | | - final long fileSizeExceedingDefaultLimit = 1024 * 1024 * 32 + 1; |
346 | | - final InputStream rawStream = new BoundedInputStream(fileSizeExceedingDefaultLimit); |
347 | | - final BufferedInputStream largeObjectStream = new BufferedInputStream(rawStream); |
348 | | - |
349 | | - v3ClientWithBuffer32MiB.putObject(PutObjectRequest.builder() |
350 | | - .bucket(BUCKET) |
351 | | - .key(objectKey) |
352 | | - .build(), RequestBody.fromInputStream(largeObjectStream, fileSizeExceedingDefaultLimit)); |
353 | | - |
354 | | - largeObjectStream.close(); |
| 323 | + for(int i=0; i < 5; i++) { |
| 324 | + final String objectKey = appendTestSuffix("large-object-test-custom-buffer-size"); |
| 325 | + |
| 326 | + Security.addProvider(new BouncyCastleProvider()); |
| 327 | + Provider provider = Security.getProvider("BC"); |
| 328 | + |
| 329 | + // V3 Client with custom max buffer size 32 MiB. |
| 330 | + S3Client v3ClientWithBuffer32MiB = S3EncryptionClient.builder() |
| 331 | + .aesKey(AES_KEY) |
| 332 | + .cryptoProvider(provider) |
| 333 | + .setBufferSize(32 * 1024 * 1024) |
| 334 | + .overrideConfiguration(ClientOverrideConfiguration.builder() |
| 335 | + .apiCallTimeout(Duration.ofMinutes(3)) |
| 336 | + .apiCallAttemptTimeout(Duration.ofSeconds(55)) |
| 337 | + .retryStrategy(RetryMode.STANDARD) |
| 338 | + .build()) |
| 339 | + .build(); |
| 340 | + |
| 341 | + // V3 Client with default buffer size (i.e. 64MiB) |
| 342 | + // When enableDelayedAuthenticationMode is set to true, delayed authentication mode always takes priority over buffered mode. |
| 343 | + S3Client v3ClientWithDelayedAuth = S3EncryptionClient.builder() |
| 344 | + .aesKey(AES_KEY) |
| 345 | + .cryptoProvider(provider) |
| 346 | + .enableDelayedAuthenticationMode(true) |
| 347 | + .build(); |
| 348 | + |
| 349 | + // Tight bound on the custom buffer size limit of 32MiB |
| 350 | + final long fileSizeExceedingDefaultLimit = 1024 * 1024 * 32 + 1; |
| 351 | + final InputStream rawStream = new BoundedInputStream(fileSizeExceedingDefaultLimit); |
| 352 | + final BufferedInputStream largeObjectStream = new BufferedInputStream(rawStream); |
| 353 | + |
| 354 | + v3ClientWithBuffer32MiB.putObject(PutObjectRequest.builder() |
| 355 | + .bucket(BUCKET) |
| 356 | + .key(objectKey) |
| 357 | + .build(), RequestBody.fromInputStream(largeObjectStream, fileSizeExceedingDefaultLimit)); |
| 358 | + |
| 359 | + largeObjectStream.close(); |
355 | 360 |
|
356 | | - // Object is larger than Buffer, so getObject fails |
357 | | - assertThrows(S3EncryptionClientException.class, () -> v3ClientWithBuffer32MiB.getObjectAsBytes(builder -> builder |
358 | | - .bucket(BUCKET) |
359 | | - .key(objectKey))); |
| 361 | + // Object is larger than Buffer, so getObject fails |
| 362 | + assertThrows(S3EncryptionClientException.class, () -> v3ClientWithBuffer32MiB.getObjectAsBytes(builder -> builder |
| 363 | + .bucket(BUCKET) |
| 364 | + .key(objectKey))); |
360 | 365 |
|
361 | | - // You have to either enable the delayed auth mode or increase max buffer size (but in allowed bounds) |
362 | | - ResponseInputStream<GetObjectResponse> response = v3ClientWithDelayedAuth.getObject(builder -> builder |
363 | | - .bucket(BUCKET) |
364 | | - .key(objectKey)); |
| 366 | + // You have to either enable the delayed auth mode or increase max buffer size (but in allowed bounds) |
| 367 | + ResponseInputStream<GetObjectResponse> response = v3ClientWithDelayedAuth.getObject(builder -> builder |
| 368 | + .bucket(BUCKET) |
| 369 | + .key(objectKey)); |
365 | 370 |
|
366 | 371 |
|
367 | | - assertTrue(IOUtils.contentEquals(new BufferedInputStream(new BoundedInputStream(fileSizeExceedingDefaultLimit)), response)); |
368 | | - response.close(); |
| 372 | + assertTrue(IOUtils.contentEquals(new BufferedInputStream(new BoundedInputStream(fileSizeExceedingDefaultLimit)), response)); |
| 373 | + response.close(); |
369 | 374 |
|
370 | | - // Cleanup |
371 | | - deleteObject(BUCKET, objectKey, v3ClientWithBuffer32MiB); |
372 | | - v3ClientWithBuffer32MiB.close(); |
373 | | - v3ClientWithDelayedAuth.close(); |
| 375 | + // Cleanup |
| 376 | + deleteObject(BUCKET, objectKey, v3ClientWithBuffer32MiB); |
| 377 | + v3ClientWithBuffer32MiB.close(); |
| 378 | + v3ClientWithDelayedAuth.close(); |
| 379 | + } |
374 | 380 |
|
375 | | - testCasePassed = true; |
376 | 381 | } |
377 | 382 |
|
378 | 383 | @RepeatedTest(3) |
|
0 commit comments