Skip to content

Commit 083499a

Browse files
committed
Add changelog + tests
1 parent d945a0c commit 083499a

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "S3 Transfer Manager",
4+
"contributor": "",
5+
"description": "Fix bug in progress reporting in upload when using the CRT client."
6+
}

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

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@
3737
import org.junit.jupiter.api.extension.ExtendWith;
3838
import org.mockito.ArgumentCaptor;
3939
import org.mockito.Mock;
40+
import org.mockito.exceptions.verification.WantedButNotInvoked;
4041
import org.mockito.junit.jupiter.MockitoExtension;
42+
import software.amazon.awssdk.core.async.AsyncRequestBody;
4143
import software.amazon.awssdk.http.SdkHttpExecutionAttributes;
4244
import software.amazon.awssdk.services.s3.S3AsyncClient;
4345
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
4446
import software.amazon.awssdk.services.s3.model.PutObjectResponse;
4547
import software.amazon.awssdk.transfer.s3.model.UploadDirectoryRequest;
4648
import software.amazon.awssdk.transfer.s3.model.UploadFileRequest;
49+
import software.amazon.awssdk.transfer.s3.model.UploadRequest;
4750

4851
@ExtendWith(MockitoExtension.class)
4952
public class CrtS3TransferManagerTest {
@@ -81,7 +84,7 @@ void uploadDirectory_shouldUseCrtUploadFile() {
8184
.completionFuture()
8285
.join();
8386

84-
verifyCrtInRequestAttributes();
87+
verifyCrtInRequestAttributes(true);
8588
}
8689

8790
@Test
@@ -94,18 +97,38 @@ void uploadFile_shouldUseCrtUploadFile() {
9497
.completionFuture()
9598
.join();
9699

97-
verifyCrtInRequestAttributes();
100+
verifyCrtInRequestAttributes(true);
98101
}
99102

100-
private void verifyCrtInRequestAttributes() {
101-
ArgumentCaptor<PutObjectRequest> requestArgumentCaptor = ArgumentCaptor.forClass(PutObjectRequest.class);
102103

103-
verify(s3AsyncClient).putObject(requestArgumentCaptor.capture(), ArgumentCaptor.forClass(Path.class).capture());
104+
@Test
105+
void upload_shouldUseCrtUpload() {
106+
when(s3AsyncClient.putObject(any(PutObjectRequest.class), any(AsyncRequestBody.class))).thenReturn(CompletableFuture.completedFuture(PutObjectResponse.builder().build()));
107+
transferManager.upload(UploadRequest.builder()
108+
.putObjectRequest(PutObjectRequest.builder().bucket("test").key("test").build())
109+
.requestBody(AsyncRequestBody.fromString("test"))
110+
.build())
111+
.completionFuture()
112+
.join();
113+
114+
verifyCrtInRequestAttributes(false);
115+
}
116+
117+
private void verifyCrtInRequestAttributes(boolean verifyObservable) {
118+
ArgumentCaptor<PutObjectRequest> requestArgumentCaptor = ArgumentCaptor.forClass(PutObjectRequest.class);
104119

120+
try {
121+
verify(s3AsyncClient).putObject(requestArgumentCaptor.capture(), ArgumentCaptor.forClass(Path.class).capture());
122+
} catch (WantedButNotInvoked e) {
123+
verify(s3AsyncClient).putObject(requestArgumentCaptor.capture(), ArgumentCaptor.forClass(AsyncRequestBody.class).capture());
124+
}
105125
PutObjectRequest actual = requestArgumentCaptor.getValue();
106126
assertThat(actual.overrideConfiguration()).isPresent();
107127
SdkHttpExecutionAttributes attribute = actual.overrideConfiguration().get().executionAttributes().getAttribute(SDK_HTTP_EXECUTION_ATTRIBUTES);
108128
assertThat(attribute).isNotNull();
109129
assertThat(attribute.getAttribute(CRT_PROGRESS_LISTENER)).isNotNull();
130+
if (verifyObservable) {
131+
assertThat(attribute.getAttribute(METAREQUEST_PAUSE_OBSERVABLE)).isNotNull();
132+
}
110133
}
111134
}

0 commit comments

Comments
 (0)