Skip to content

Commit 9ba0b85

Browse files
author
Anirav Kareddy
committed
making a baseline
1 parent bb898d1 commit 9ba0b85

File tree

2 files changed

+126
-98
lines changed

2 files changed

+126
-98
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
export AWS_S3EC_TEST_KMS_KEY_ID=arn:aws:kms:${{ vars.CI_AWS_REGION }}:${{ secrets.CI_AWS_ACCOUNT_ID }}:key/${{ vars.CI_KMS_KEY_ID }}
5454
export AWS_S3EC_TEST_KMS_KEY_ALIAS=arn:aws:kms:${{ vars.CI_AWS_REGION }}:${{ secrets.CI_AWS_ACCOUNT_ID }}:alias/${{ vars.CI_KMS_KEY_ALIAS }}
5555
export AWS_REGION=${{ vars.CI_AWS_REGION }}
56-
mvn -B -ntp test -DskipCompile
56+
mvn -B -ntp test -DskipCompile -Dtest=S3EncryptionClientStreamTest#customSetBufferSizeWithLargeObject,S3EncryptionClientStreamTest#customSetBufferSizeWithLargeObjectAsyncClient
5757
shell: bash
5858

5959
- name: Package JAR

src/test/java/software/amazon/encryption/s3/S3EncryptionClientStreamTest.java

Lines changed: 125 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.security.NoSuchAlgorithmException;
4040
import java.security.Provider;
4141
import java.security.Security;
42+
import java.util.ArrayList;
4243
import java.util.concurrent.CompletableFuture;
4344
import java.util.concurrent.CompletionException;
4445
import java.util.concurrent.ExecutorService;
@@ -308,114 +309,141 @@ public void failsWhenBothBufferSizeAndDelayedAuthModeEnabled() {
308309

309310
@Test
310311
public void customSetBufferSizeWithLargeObject() throws IOException {
311-
final String objectKey = appendTestSuffix("large-object-test-custom-buffer-size");
312-
313-
Security.addProvider(new BouncyCastleProvider());
314-
Provider provider = Security.getProvider("BC");
315-
316-
// V3 Client with custom max buffer size 32 MiB.
317-
S3Client v3ClientWithBuffer32MiB = S3EncryptionClient.builder()
318-
.aesKey(AES_KEY)
319-
.cryptoProvider(provider)
320-
.setBufferSize(32 * 1024 * 1024)
321-
.build();
322-
323-
// V3 Client with default buffer size (i.e. 64MiB)
324-
// When enableDelayedAuthenticationMode is set to true, delayed authentication mode always takes priority over buffered mode.
325-
S3Client v3ClientWithDelayedAuth = S3EncryptionClient.builder()
326-
.aesKey(AES_KEY)
327-
.cryptoProvider(provider)
328-
.enableDelayedAuthenticationMode(true)
329-
.build();
330-
331-
// Tight bound on the custom buffer size limit of 32MiB
332-
final long fileSizeExceedingDefaultLimit = 1024 * 1024 * 32 + 1;
333-
final InputStream largeObjectStream = new BoundedInputStream(fileSizeExceedingDefaultLimit);
334-
v3ClientWithBuffer32MiB.putObject(PutObjectRequest.builder()
335-
.bucket(BUCKET)
336-
.key(objectKey)
337-
.build(), RequestBody.fromInputStream(largeObjectStream, fileSizeExceedingDefaultLimit));
338-
339-
largeObjectStream.close();
340-
341-
// Object is larger than Buffer, so getObject fails
342-
assertThrows(S3EncryptionClientException.class, () -> v3ClientWithBuffer32MiB.getObjectAsBytes(builder -> builder
343-
.bucket(BUCKET)
344-
.key(objectKey)));
345-
346-
// You have to either enable the delayed auth mode or increase max buffer size (but in allowed bounds)
347-
ResponseInputStream<GetObjectResponse> response = v3ClientWithDelayedAuth.getObject(builder -> builder
348-
.bucket(BUCKET)
349-
.key(objectKey));
350-
351-
352-
assertTrue(IOUtils.contentEquals(new BoundedInputStream(fileSizeExceedingDefaultLimit), response));
353-
response.close();
312+
ArrayList<Exception> failures = new ArrayList<>();
313+
int success=0, fails = 0;
314+
for(int i=0; i < 50; i++) {
315+
try {
316+
final String objectKey = appendTestSuffix("large-object-test-custom-buffer-size");
317+
318+
Security.addProvider(new BouncyCastleProvider());
319+
Provider provider = Security.getProvider("BC");
320+
321+
// V3 Client with custom max buffer size 32 MiB.
322+
S3Client v3ClientWithBuffer32MiB = S3EncryptionClient.builder()
323+
.aesKey(AES_KEY)
324+
.cryptoProvider(provider)
325+
.setBufferSize(32 * 1024 * 1024)
326+
.build();
327+
328+
// V3 Client with default buffer size (i.e. 64MiB)
329+
// When enableDelayedAuthenticationMode is set to true, delayed authentication mode always takes priority over buffered mode.
330+
S3Client v3ClientWithDelayedAuth = S3EncryptionClient.builder()
331+
.aesKey(AES_KEY)
332+
.cryptoProvider(provider)
333+
.enableDelayedAuthenticationMode(true)
334+
.build();
335+
336+
// Tight bound on the custom buffer size limit of 32MiB
337+
final long fileSizeExceedingDefaultLimit = 1024 * 1024 * 32 + 1;
338+
final InputStream largeObjectStream = new BoundedInputStream(fileSizeExceedingDefaultLimit);
339+
v3ClientWithBuffer32MiB.putObject(PutObjectRequest.builder()
340+
.bucket(BUCKET)
341+
.key(objectKey)
342+
.build(), RequestBody.fromInputStream(largeObjectStream, fileSizeExceedingDefaultLimit));
343+
344+
largeObjectStream.close();
345+
346+
// Object is larger than Buffer, so getObject fails
347+
assertThrows(S3EncryptionClientException.class, () -> v3ClientWithBuffer32MiB.getObjectAsBytes(builder -> builder
348+
.bucket(BUCKET)
349+
.key(objectKey)));
350+
351+
// You have to either enable the delayed auth mode or increase max buffer size (but in allowed bounds)
352+
ResponseInputStream<GetObjectResponse> response = v3ClientWithDelayedAuth.getObject(builder -> builder
353+
.bucket(BUCKET)
354+
.key(objectKey));
355+
356+
357+
assertTrue(IOUtils.contentEquals(new BoundedInputStream(fileSizeExceedingDefaultLimit), response));
358+
response.close();
359+
360+
// Cleanup
361+
deleteObject(BUCKET, objectKey, v3ClientWithBuffer32MiB);
362+
v3ClientWithBuffer32MiB.close();
363+
v3ClientWithDelayedAuth.close();
364+
365+
success++;
366+
} catch(Exception e) {
367+
fails++;
368+
failures.add(e);
369+
}
370+
System.out.println("Success: " + success + " Fails: " + fails);
371+
failures.forEach(e -> e.printStackTrace());
354372

355-
// Cleanup
356-
deleteObject(BUCKET, objectKey, v3ClientWithBuffer32MiB);
357-
v3ClientWithBuffer32MiB.close();
358-
v3ClientWithDelayedAuth.close();
373+
}
359374
}
360375

361376
@Test
362377
public void customSetBufferSizeWithLargeObjectAsyncClient() throws IOException {
363-
final String objectKey = appendTestSuffix("large-object-test-custom-buffer-size-async");
378+
ArrayList<Exception> failures = new ArrayList<>();
379+
int success=0, fails = 0;
380+
for(int i=0; i < 50; i++) {
381+
try {
382+
final String objectKey = appendTestSuffix("large-object-test-custom-buffer-size-async");
383+
384+
Security.addProvider(new BouncyCastleProvider());
385+
Provider provider = Security.getProvider("BC");
386+
387+
// V3 Client with custom max buffer size 32 MiB.
388+
S3AsyncClient v3ClientWithBuffer32MiB = S3AsyncEncryptionClient.builder()
389+
.aesKey(AES_KEY)
390+
.cryptoProvider(provider)
391+
.setBufferSize(32 * 1024 * 1024)
392+
.build();
393+
394+
// V3 Client with default buffer size (i.e. 64MiB)
395+
// When enableDelayedAuthenticationMode is set to true, delayed authentication mode always takes priority over buffered mode.
396+
S3AsyncClient v3ClientWithDelayedAuth = S3AsyncEncryptionClient.builder()
397+
.aesKey(AES_KEY)
398+
.cryptoProvider(provider)
399+
.enableDelayedAuthenticationMode(true)
400+
.build();
401+
402+
// Tight bound on the custom buffer size limit of 32MiB
403+
final long fileSizeExceedingDefaultLimit = 1024 * 1024 * 32 + 1;
404+
final InputStream largeObjectStream = new BoundedInputStream(fileSizeExceedingDefaultLimit);
405+
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
406+
CompletableFuture<PutObjectResponse> futurePut = v3ClientWithBuffer32MiB.putObject(PutObjectRequest.builder()
407+
.bucket(BUCKET)
408+
.key(objectKey)
409+
.build(), AsyncRequestBody.fromInputStream(largeObjectStream, fileSizeExceedingDefaultLimit, singleThreadExecutor));
410+
411+
futurePut.join();
412+
largeObjectStream.close();
413+
singleThreadExecutor.shutdown();
364414

365-
Security.addProvider(new BouncyCastleProvider());
366-
Provider provider = Security.getProvider("BC");
415+
try {
416+
// Object is larger than Buffer, so getObject fails
417+
CompletableFuture<ResponseInputStream<GetObjectResponse>> futureResponse = v3ClientWithBuffer32MiB.getObject(builder -> builder
418+
.bucket(BUCKET)
419+
.key(objectKey), AsyncResponseTransformer.toBlockingInputStream());
420+
futureResponse.join();
421+
} catch (CompletionException e) {
422+
assertEquals(S3EncryptionClientException.class, e.getCause().getClass());
423+
}
367424

368-
// V3 Client with custom max buffer size 32 MiB.
369-
S3AsyncClient v3ClientWithBuffer32MiB = S3AsyncEncryptionClient.builder()
370-
.aesKey(AES_KEY)
371-
.cryptoProvider(provider)
372-
.setBufferSize(32 * 1024 * 1024)
373-
.build();
425+
// You have to either enable the delayed auth mode or increase max buffer size (but in allowed bounds)
426+
CompletableFuture<ResponseInputStream<GetObjectResponse>> futureGet = v3ClientWithDelayedAuth.getObject(builder -> builder
427+
.bucket(BUCKET)
428+
.key(objectKey), AsyncResponseTransformer.toBlockingInputStream());
429+
ResponseInputStream<GetObjectResponse> output = futureGet.join();
374430

375-
// V3 Client with default buffer size (i.e. 64MiB)
376-
// When enableDelayedAuthenticationMode is set to true, delayed authentication mode always takes priority over buffered mode.
377-
S3AsyncClient v3ClientWithDelayedAuth = S3AsyncEncryptionClient.builder()
378-
.aesKey(AES_KEY)
379-
.cryptoProvider(provider)
380-
.enableDelayedAuthenticationMode(true)
381-
.build();
431+
assertTrue(IOUtils.contentEquals(new BoundedInputStream(fileSizeExceedingDefaultLimit), output));
432+
output.close();
382433

383-
// Tight bound on the custom buffer size limit of 32MiB
384-
final long fileSizeExceedingDefaultLimit = 1024 * 1024 * 32 + 1;
385-
final InputStream largeObjectStream = new BoundedInputStream(fileSizeExceedingDefaultLimit);
386-
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
387-
CompletableFuture<PutObjectResponse> futurePut = v3ClientWithBuffer32MiB.putObject(PutObjectRequest.builder()
388-
.bucket(BUCKET)
389-
.key(objectKey)
390-
.build(), AsyncRequestBody.fromInputStream(largeObjectStream, fileSizeExceedingDefaultLimit, singleThreadExecutor));
391-
392-
futurePut.join();
393-
largeObjectStream.close();
394-
singleThreadExecutor.shutdown();
434+
// Cleanup
435+
deleteObject(BUCKET, objectKey, v3ClientWithBuffer32MiB);
436+
v3ClientWithBuffer32MiB.close();
437+
v3ClientWithDelayedAuth.close();
395438

396-
try {
397-
// Object is larger than Buffer, so getObject fails
398-
CompletableFuture<ResponseInputStream<GetObjectResponse>> futureResponse = v3ClientWithBuffer32MiB.getObject(builder -> builder
399-
.bucket(BUCKET)
400-
.key(objectKey), AsyncResponseTransformer.toBlockingInputStream());
401-
futureResponse.join();
402-
} catch (CompletionException e) {
403-
assertEquals(S3EncryptionClientException.class, e.getCause().getClass());
439+
success++;
440+
} catch (Exception e) {
441+
fails++;
442+
failures.add(e);
443+
}
444+
System.out.println("Success: " + success + " Fails: " + fails);
445+
failures.forEach(e -> e.printStackTrace());
404446
}
405-
406-
// You have to either enable the delayed auth mode or increase max buffer size (but in allowed bounds)
407-
CompletableFuture<ResponseInputStream<GetObjectResponse>> futureGet = v3ClientWithDelayedAuth.getObject(builder -> builder
408-
.bucket(BUCKET)
409-
.key(objectKey), AsyncResponseTransformer.toBlockingInputStream());
410-
ResponseInputStream<GetObjectResponse> output = futureGet.join();
411-
412-
assertTrue(IOUtils.contentEquals(new BoundedInputStream(fileSizeExceedingDefaultLimit), output));
413-
output.close();
414-
415-
// Cleanup
416-
deleteObject(BUCKET, objectKey, v3ClientWithBuffer32MiB);
417-
v3ClientWithBuffer32MiB.close();
418-
v3ClientWithDelayedAuth.close();
419447
}
420448

421449
@Test

0 commit comments

Comments
 (0)