@@ -310,130 +310,126 @@ public void failsWhenBothBufferSizeAndDelayedAuthModeEnabled() {
310
310
311
311
@ Test
312
312
public void customSetBufferSizeWithLargeObject () throws IOException {
313
- for (int i =0 ; i < 10 ; i ++) {
314
- final String objectKey = appendTestSuffix ("large-object-test-custom-buffer-size" );
313
+ final String objectKey = appendTestSuffix ("large-object-test-custom-buffer-size" );
315
314
316
- Security .addProvider (new BouncyCastleProvider ());
317
- Provider provider = Security .getProvider ("BC" );
315
+ Security .addProvider (new BouncyCastleProvider ());
316
+ Provider provider = Security .getProvider ("BC" );
318
317
319
- // V3 Client with custom max buffer size 32 MiB.
320
- S3Client v3ClientWithBuffer32MiB = S3EncryptionClient .builder ()
321
- .aesKey (AES_KEY )
322
- .cryptoProvider (provider )
323
- .setBufferSize (32 * 1024 * 1024 )
324
- .build ();
318
+ // V3 Client with custom max buffer size 32 MiB.
319
+ S3Client v3ClientWithBuffer32MiB = S3EncryptionClient .builder ()
320
+ .aesKey (AES_KEY )
321
+ .cryptoProvider (provider )
322
+ .setBufferSize (32 * 1024 * 1024 )
323
+ .build ();
325
324
326
- // V3 Client with default buffer size (i.e. 64MiB)
327
- // When enableDelayedAuthenticationMode is set to true, delayed authentication mode always takes priority over buffered mode.
328
- S3Client v3ClientWithDelayedAuth = S3EncryptionClient .builder ()
329
- .aesKey (AES_KEY )
330
- .cryptoProvider (provider )
331
- .enableDelayedAuthenticationMode (true )
332
- .build ();
325
+ // V3 Client with default buffer size (i.e. 64MiB)
326
+ // When enableDelayedAuthenticationMode is set to true, delayed authentication mode always takes priority over buffered mode.
327
+ S3Client v3ClientWithDelayedAuth = S3EncryptionClient .builder ()
328
+ .aesKey (AES_KEY )
329
+ .cryptoProvider (provider )
330
+ .enableDelayedAuthenticationMode (true )
331
+ .build ();
333
332
334
- // Tight bound on the custom buffer size limit of 32MiB
335
- final long fileSizeExceedingDefaultLimit = 1024 * 1024 * 32 + 1 ;
333
+ // Tight bound on the custom buffer size limit of 32MiB
334
+ final long fileSizeExceedingDefaultLimit = 1024 * 1024 * 32 + 1 ;
336
335
337
- byte [] data = new byte [(int ) fileSizeExceedingDefaultLimit ];
338
- for (int j =0 ; j < data .length ; j ++) {
339
- data [i ] = (byte ) (j % 256 );
340
- }
341
- final InputStream largeObjectStream = new ByteArrayInputStream (data );
342
- v3ClientWithBuffer32MiB .putObject (PutObjectRequest .builder ()
343
- .bucket (BUCKET )
344
- .key (objectKey )
345
- .build (), RequestBody .fromInputStream (largeObjectStream , fileSizeExceedingDefaultLimit ));
336
+ byte [] data = new byte [(int ) fileSizeExceedingDefaultLimit ];
337
+ for (int j =0 ; j < data .length ; j ++) {
338
+ data [i ] = (byte ) (j % 256 );
339
+ }
340
+ final InputStream largeObjectStream = new ByteArrayInputStream (data );
341
+ v3ClientWithBuffer32MiB .putObject (PutObjectRequest .builder ()
342
+ .bucket (BUCKET )
343
+ .key (objectKey )
344
+ .build (), RequestBody .fromInputStream (largeObjectStream , fileSizeExceedingDefaultLimit ));
346
345
347
- largeObjectStream .close ();
346
+ largeObjectStream .close ();
348
347
349
- // Object is larger than Buffer, so getObject fails
350
- assertThrows (S3EncryptionClientException .class , () -> v3ClientWithBuffer32MiB .getObjectAsBytes (builder -> builder
351
- .bucket (BUCKET )
352
- .key (objectKey )));
348
+ // Object is larger than Buffer, so getObject fails
349
+ assertThrows (S3EncryptionClientException .class , () -> v3ClientWithBuffer32MiB .getObjectAsBytes (builder -> builder
350
+ .bucket (BUCKET )
351
+ .key (objectKey )));
353
352
354
- // You have to either enable the delayed auth mode or increase max buffer size (but in allowed bounds)
355
- ResponseInputStream <GetObjectResponse > response = v3ClientWithDelayedAuth .getObject (builder -> builder
356
- .bucket (BUCKET )
357
- .key (objectKey ));
353
+ // You have to either enable the delayed auth mode or increase max buffer size (but in allowed bounds)
354
+ ResponseInputStream <GetObjectResponse > response = v3ClientWithDelayedAuth .getObject (builder -> builder
355
+ .bucket (BUCKET )
356
+ .key (objectKey ));
358
357
359
- // Create a new ByteArrayInputStream for comparison
360
- InputStream expectedStream = new ByteArrayInputStream (data );
361
- assertTrue (IOUtils .contentEquals (expectedStream , response ));
362
- response .close ();
358
+ // Create a new ByteArrayInputStream for comparison
359
+ InputStream expectedStream = new ByteArrayInputStream (data );
360
+ assertTrue (IOUtils .contentEquals (expectedStream , response ));
361
+ response .close ();
363
362
364
- // Cleanup
365
- deleteObject (BUCKET , objectKey , v3ClientWithBuffer32MiB );
366
- v3ClientWithBuffer32MiB .close ();
367
- v3ClientWithDelayedAuth .close ();
368
- }
363
+ // Cleanup
364
+ deleteObject (BUCKET , objectKey , v3ClientWithBuffer32MiB );
365
+ v3ClientWithBuffer32MiB .close ();
366
+ v3ClientWithDelayedAuth .close ();
369
367
}
370
368
371
369
@ Test
372
370
public void customSetBufferSizeWithLargeObjectAsyncClient () throws IOException {
373
- for (int i =0 ; i < 10 ;i ++) {
374
- final String objectKey = appendTestSuffix ("large-object-test-custom-buffer-size-async" );
371
+ final String objectKey = appendTestSuffix ("large-object-test-custom-buffer-size-async" );
375
372
376
- Security .addProvider (new BouncyCastleProvider ());
377
- Provider provider = Security .getProvider ("BC" );
373
+ Security .addProvider (new BouncyCastleProvider ());
374
+ Provider provider = Security .getProvider ("BC" );
378
375
379
- // V3 Client with custom max buffer size 32 MiB.
380
- S3AsyncClient v3ClientWithBuffer32MiB = S3AsyncEncryptionClient .builder ()
381
- .aesKey (AES_KEY )
382
- .cryptoProvider (provider )
383
- .setBufferSize (32 * 1024 * 1024 )
384
- .build ();
385
-
386
- // V3 Client with default buffer size (i.e. 64MiB)
387
- // When enableDelayedAuthenticationMode is set to true, delayed authentication mode always takes priority over buffered mode.
388
- S3AsyncClient v3ClientWithDelayedAuth = S3AsyncEncryptionClient .builder ()
389
- .aesKey (AES_KEY )
390
- .cryptoProvider (provider )
391
- .enableDelayedAuthenticationMode (true )
392
- .build ();
376
+ // V3 Client with custom max buffer size 32 MiB.
377
+ S3AsyncClient v3ClientWithBuffer32MiB = S3AsyncEncryptionClient .builder ()
378
+ .aesKey (AES_KEY )
379
+ .cryptoProvider (provider )
380
+ .setBufferSize (32 * 1024 * 1024 )
381
+ .build ();
393
382
394
- // Tight bound on the custom buffer size limit of 32MiB
395
- final long fileSizeExceedingDefaultLimit = 1024 * 1024 * 32 + 1 ;
396
- byte [] data = new byte [(int ) fileSizeExceedingDefaultLimit ];
397
- for (int j =0 ; j < data .length ; j ++) {
398
- data [i ] = (byte ) (j % 256 );
399
- }
400
- final InputStream largeObjectStream = new ByteArrayInputStream (data );
401
- ExecutorService singleThreadExecutor = Executors .newSingleThreadExecutor ();
402
- CompletableFuture <PutObjectResponse > futurePut = v3ClientWithBuffer32MiB .putObject (PutObjectRequest .builder ()
403
- .bucket (BUCKET )
404
- .key (objectKey )
405
- .build (), AsyncRequestBody .fromInputStream (largeObjectStream , fileSizeExceedingDefaultLimit , singleThreadExecutor ));
383
+ // V3 Client with default buffer size (i.e. 64MiB)
384
+ // When enableDelayedAuthenticationMode is set to true, delayed authentication mode always takes priority over buffered mode.
385
+ S3AsyncClient v3ClientWithDelayedAuth = S3AsyncEncryptionClient .builder ()
386
+ .aesKey (AES_KEY )
387
+ .cryptoProvider (provider )
388
+ .enableDelayedAuthenticationMode (true )
389
+ .build ();
406
390
407
- futurePut .join ();
408
- largeObjectStream .close ();
409
- singleThreadExecutor .shutdown ();
391
+ // Tight bound on the custom buffer size limit of 32MiB
392
+ final long fileSizeExceedingDefaultLimit = 1024 * 1024 * 32 + 1 ;
393
+ byte [] data = new byte [(int ) fileSizeExceedingDefaultLimit ];
394
+ for (int j =0 ; j < data .length ; j ++) {
395
+ data [i ] = (byte ) (j % 256 );
396
+ }
397
+ final InputStream largeObjectStream = new ByteArrayInputStream (data );
398
+ ExecutorService singleThreadExecutor = Executors .newSingleThreadExecutor ();
399
+ CompletableFuture <PutObjectResponse > futurePut = v3ClientWithBuffer32MiB .putObject (PutObjectRequest .builder ()
400
+ .bucket (BUCKET )
401
+ .key (objectKey )
402
+ .build (), AsyncRequestBody .fromInputStream (largeObjectStream , fileSizeExceedingDefaultLimit , singleThreadExecutor ));
410
403
411
- try {
412
- // Object is larger than Buffer, so getObject fails
413
- CompletableFuture <ResponseInputStream <GetObjectResponse >> futureResponse = v3ClientWithBuffer32MiB .getObject (builder -> builder
414
- .bucket (BUCKET )
415
- .key (objectKey ), AsyncResponseTransformer .toBlockingInputStream ());
416
- futureResponse .join ();
417
- } catch (CompletionException e ) {
418
- assertEquals (S3EncryptionClientException .class , e .getCause ().getClass ());
419
- }
404
+ futurePut .join ();
405
+ largeObjectStream .close ();
406
+ singleThreadExecutor .shutdown ();
420
407
421
- // You have to either enable the delayed auth mode or increase max buffer size (but in allowed bounds)
422
- CompletableFuture <ResponseInputStream <GetObjectResponse >> futureGet = v3ClientWithDelayedAuth .getObject (builder -> builder
408
+ try {
409
+ // Object is larger than Buffer, so getObject fails
410
+ CompletableFuture <ResponseInputStream <GetObjectResponse >> futureResponse = v3ClientWithBuffer32MiB .getObject (builder -> builder
423
411
.bucket (BUCKET )
424
412
.key (objectKey ), AsyncResponseTransformer .toBlockingInputStream ());
425
- ResponseInputStream <GetObjectResponse > output = futureGet .join ();
413
+ futureResponse .join ();
414
+ } catch (CompletionException e ) {
415
+ assertEquals (S3EncryptionClientException .class , e .getCause ().getClass ());
416
+ }
417
+
418
+ // You have to either enable the delayed auth mode or increase max buffer size (but in allowed bounds)
419
+ CompletableFuture <ResponseInputStream <GetObjectResponse >> futureGet = v3ClientWithDelayedAuth .getObject (builder -> builder
420
+ .bucket (BUCKET )
421
+ .key (objectKey ), AsyncResponseTransformer .toBlockingInputStream ());
422
+ ResponseInputStream <GetObjectResponse > output = futureGet .join ();
426
423
427
- ByteArrayInputStream expectedStream = new ByteArrayInputStream (data );
428
- assertTrue (IOUtils .contentEquals (expectedStream , output ));
424
+ ByteArrayInputStream expectedStream = new ByteArrayInputStream (data );
425
+ assertTrue (IOUtils .contentEquals (expectedStream , output ));
429
426
430
- output .close ();
427
+ output .close ();
431
428
432
- // Cleanup
433
- deleteObject (BUCKET , objectKey , v3ClientWithBuffer32MiB );
434
- v3ClientWithBuffer32MiB .close ();
435
- v3ClientWithDelayedAuth .close ();
436
- }
429
+ // Cleanup
430
+ deleteObject (BUCKET , objectKey , v3ClientWithBuffer32MiB );
431
+ v3ClientWithBuffer32MiB .close ();
432
+ v3ClientWithDelayedAuth .close ();
437
433
}
438
434
439
435
@ Test
0 commit comments