Skip to content

Commit 5581092

Browse files
committed
Add tests in DownloadDirectoryHelperTest and UploadDirectoryHelperTest to verify DIRECTORY_TRANSFER_MAX_CONCURRENCY
Signed-off-by: Andre Kurait <[email protected]>
1 parent be0a85b commit 5581092

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

services-custom/s3-transfer-manager/src/test/java/software/amazon/awssdk/transfer/s3/internal/DownloadDirectoryHelperTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,47 @@ void downloadDirectory_withListObjectsRequestTransformer_transformerThrows_fails
522522
assertThatThrownBy(downloadDirectory.completionFuture()::join).hasCause(exception);
523523
}
524524

525+
@Test
526+
void downloadDirectory_customMaxConcurrency_shouldRespectConfiguration() throws Exception {
527+
// Create configuration with custom concurrency
528+
TransferManagerConfiguration customConfig = TransferManagerConfiguration.builder()
529+
.directoryTransferMaxConcurrency(75) // Custom value
530+
.build();
531+
532+
DownloadDirectoryHelper customHelper = new DownloadDirectoryHelper(
533+
customConfig, listObjectsHelper, singleDownloadFunction);
534+
535+
// Set up mocks
536+
stubSuccessfulListObjects(listObjectsHelper, "key1", "key2");
537+
FileDownload fileDownload = newSuccessfulDownload();
538+
when(singleDownloadFunction.apply(any(DownloadFileRequest.class)))
539+
.thenReturn(fileDownload);
540+
541+
// Execute download
542+
DirectoryDownload downloadDirectory = customHelper.downloadDirectory(
543+
DownloadDirectoryRequest.builder()
544+
.destination(directory)
545+
.bucket("bucket")
546+
.build()
547+
);
548+
549+
// Verify it completes successfully
550+
downloadDirectory.completionFuture().get(5, TimeUnit.SECONDS);
551+
552+
// Verify the configuration value
553+
assertThat(customConfig.option(TransferConfigurationOption.DIRECTORY_TRANSFER_MAX_CONCURRENCY))
554+
.isEqualTo(75);
555+
}
556+
557+
@Test
558+
void downloadDirectory_defaultConfiguration_shouldUseDefaultConcurrency() {
559+
TransferManagerConfiguration defaultConfig = TransferManagerConfiguration.builder().build();
560+
561+
// Verify default value is 100
562+
assertThat(defaultConfig.option(TransferConfigurationOption.DIRECTORY_TRANSFER_MAX_CONCURRENCY))
563+
.isEqualTo(100);
564+
}
565+
525566
private static DefaultFileDownload completedDownload() {
526567
return new DefaultFileDownload(CompletableFuture.completedFuture(CompletedFileDownload.builder()
527568
.response(GetObjectResponse.builder().build())

services-custom/s3-transfer-manager/src/test/java/software/amazon/awssdk/transfer/s3/internal/UploadDirectoryHelperTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,44 @@ public void uploadDirectory_requestTransformFunctionThrows_failsUpload() {
458458
assertThatThrownBy(uploadFuture::join).getCause().hasCause(exception);
459459
}
460460

461+
@Test
462+
void uploadDirectory_customMaxConcurrency_shouldRespectConfiguration() {
463+
// Create configuration with custom concurrency
464+
TransferManagerConfiguration customConfig = TransferManagerConfiguration.builder()
465+
.directoryTransferMaxConcurrency(50) // Custom value
466+
.build();
467+
468+
UploadDirectoryHelper customHelper = new UploadDirectoryHelper(customConfig, singleUploadFunction);
469+
470+
// Set up mock responses
471+
when(singleUploadFunction.apply(any(UploadFileRequest.class)))
472+
.thenReturn(completedUpload());
473+
474+
// Execute upload
475+
DirectoryUpload uploadDirectory = customHelper.uploadDirectory(
476+
UploadDirectoryRequest.builder()
477+
.source(directory)
478+
.bucket("bucket")
479+
.build()
480+
);
481+
482+
// Verify it completes successfully
483+
uploadDirectory.completionFuture().join();
484+
485+
// Verify the configuration value
486+
assertThat(customConfig.option(TransferConfigurationOption.DIRECTORY_TRANSFER_MAX_CONCURRENCY))
487+
.isEqualTo(50);
488+
}
489+
490+
@Test
491+
void uploadDirectory_defaultConfiguration_shouldUseDefaultConcurrency() {
492+
TransferManagerConfiguration defaultConfig = TransferManagerConfiguration.builder().build();
493+
494+
// Verify default value is 100
495+
assertThat(defaultConfig.option(TransferConfigurationOption.DIRECTORY_TRANSFER_MAX_CONCURRENCY))
496+
.isEqualTo(100);
497+
}
498+
461499

462500
private DefaultFileUpload completedUpload() {
463501
return new DefaultFileUpload(CompletableFuture.completedFuture(CompletedFileUpload.builder()

0 commit comments

Comments
 (0)