Skip to content

Commit 1a9fc3d

Browse files
committed
Fix build and address feedback
1 parent 91eee4c commit 1a9fc3d

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

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

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import software.amazon.awssdk.crt.s3.ResumeToken;
4141
import software.amazon.awssdk.crt.s3.S3MetaRequest;
4242
import software.amazon.awssdk.services.s3.internal.crt.S3MetaRequestPauseObservable;
43+
import software.amazon.awssdk.services.s3.internal.crt.S3MetaRequestWrapper;
4344
import software.amazon.awssdk.services.s3.model.PutObjectResponse;
4445
import software.amazon.awssdk.transfer.s3.internal.model.CrtFileUpload;
4546
import software.amazon.awssdk.transfer.s3.internal.progress.DefaultTransferProgressSnapshot;
@@ -53,7 +54,7 @@ class CrtFileUploadTest {
5354
private static final int NUM_OF_PARTS_COMPLETED = 5;
5455
private static final long PART_SIZE_IN_BYTES = 8 * MB;
5556
private static final String MULTIPART_UPLOAD_ID = "someId";
56-
private S3MetaRequest metaRequest;
57+
private S3MetaRequestPauseObservable observable;
5758
private static FileSystem fileSystem;
5859
private static File file;
5960
private static ResumeToken token;
@@ -77,7 +78,7 @@ public static void tearDown() throws IOException {
7778

7879
@BeforeEach
7980
void setUpBeforeEachTest() {
80-
metaRequest = Mockito.mock(S3MetaRequest.class);
81+
observable = Mockito.mock(S3MetaRequestPauseObservable.class);
8182
}
8283

8384
@Test
@@ -102,17 +103,13 @@ void pause_futureCompleted_shouldReturnNormally() {
102103
.sdkResponse(putObjectResponse)
103104
.transferredBytes(0L)
104105
.build());
105-
S3MetaRequestPauseObservable observable = new S3MetaRequestPauseObservable();
106-
107106
UploadFileRequest request = uploadFileRequest();
108107

109108
CrtFileUpload fileUpload =
110109
new CrtFileUpload(future, transferProgress, observable, request);
111110

112-
observable.subscribe(metaRequest);
113-
114111
ResumableFileUpload resumableFileUpload = fileUpload.pause();
115-
Mockito.verify(metaRequest, Mockito.never()).pause();
112+
Mockito.verify(observable, Mockito.never()).pause();
116113
assertThat(resumableFileUpload.totalParts()).isEmpty();
117114
assertThat(resumableFileUpload.partSizeInBytes()).isEmpty();
118115
assertThat(resumableFileUpload.multipartUploadId()).isEmpty();
@@ -130,10 +127,7 @@ void pauseTwice_shouldReturnTheSame() {
130127
.transferredBytes(1000L)
131128
.build());
132129
UploadFileRequest request = uploadFileRequest();
133-
134-
S3MetaRequestPauseObservable observable = new S3MetaRequestPauseObservable();
135-
when(metaRequest.pause()).thenReturn(token);
136-
observable.subscribe(metaRequest);
130+
when(observable.pause()).thenReturn(token);
137131

138132
CrtFileUpload fileUpload =
139133
new CrtFileUpload(future, transferProgress, observable, request);
@@ -154,10 +148,8 @@ void pause_crtThrowException_shouldPropogate() {
154148
.build());
155149
UploadFileRequest request = uploadFileRequest();
156150

157-
S3MetaRequestPauseObservable observable = new S3MetaRequestPauseObservable();
158151
CrtRuntimeException exception = new CrtRuntimeException("exception");
159-
when(metaRequest.pause()).thenThrow(exception);
160-
observable.subscribe(metaRequest);
152+
when(observable.pause()).thenThrow(exception);
161153

162154
CrtFileUpload fileUpload =
163155
new CrtFileUpload(future, transferProgress, observable, request);
@@ -173,17 +165,14 @@ void pause_futureNotComplete_shouldPause() {
173165
when(transferProgress.snapshot()).thenReturn(DefaultTransferProgressSnapshot.builder()
174166
.transferredBytes(0L)
175167
.build());
176-
S3MetaRequestPauseObservable observable = new S3MetaRequestPauseObservable();
177-
when(metaRequest.pause()).thenReturn(token);
168+
when(observable.pause()).thenReturn(token);
178169
UploadFileRequest request = uploadFileRequest();
179170

180171
CrtFileUpload fileUpload =
181172
new CrtFileUpload(future, transferProgress, observable, request);
182173

183-
observable.subscribe(metaRequest);
184-
185174
ResumableFileUpload resumableFileUpload = fileUpload.pause();
186-
Mockito.verify(metaRequest).pause();
175+
Mockito.verify(observable).pause();
187176
assertThat(resumableFileUpload.totalParts()).hasValue(TOTAL_PARTS);
188177
assertThat(resumableFileUpload.partSizeInBytes()).hasValue(PART_SIZE_IN_BYTES);
189178
assertThat(resumableFileUpload.multipartUploadId()).hasValue(MULTIPART_UPLOAD_ID);
@@ -204,17 +193,14 @@ void pause_singlePart_shouldPause() {
204193
.sdkResponse(putObjectResponse)
205194
.transferredBytes(0L)
206195
.build());
207-
S3MetaRequestPauseObservable observable = new S3MetaRequestPauseObservable();
208-
when(metaRequest.pause()).thenThrow(new CrtRuntimeException(6));
196+
when(observable.pause()).thenThrow(new CrtRuntimeException(6));
209197
UploadFileRequest request = uploadFileRequest();
210198

211199
CrtFileUpload fileUpload =
212200
new CrtFileUpload(future, transferProgress, observable, request);
213201

214-
observable.subscribe(metaRequest);
215-
216202
ResumableFileUpload resumableFileUpload = fileUpload.pause();
217-
Mockito.verify(metaRequest).pause();
203+
Mockito.verify(observable).pause();
218204
assertThat(resumableFileUpload.totalParts()).isEmpty();
219205
assertThat(resumableFileUpload.partSizeInBytes()).isEmpty();
220206
assertThat(resumableFileUpload.multipartUploadId()).isEmpty();

services/s3/src/main/java/software/amazon/awssdk/services/s3/internal/crt/S3CrtResponseHandlerAdapter.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public S3CrtResponseHandlerAdapter(CompletableFuture<Void> executeFuture,
6363
return;
6464
}
6565

66-
if (executeFuture.isCancelled()) {
66+
if (t != null) {
6767
s3MetaRequest.cancel();
6868
}
6969
s3MetaRequest.close();
@@ -108,6 +108,13 @@ public int onResponseBody(ByteBuffer bodyBytesIn, long objectRangeStart, long ob
108108
failResponseHandlerAndFuture(failure);
109109
return;
110110
}
111+
112+
if (s3MetaRequest() == null) {
113+
// should not happen
114+
failResponseHandlerAndFuture(SdkClientException.create("Unexpected exception occurred: s3metaRequest is not "
115+
+ "initialized yet"));
116+
return;
117+
}
111118
s3MetaRequest().incrementReadWindow(bytesReceived);
112119
});
113120

0 commit comments

Comments
 (0)