Skip to content

Commit b9452fb

Browse files
committed
PR cleanups
1 parent 2be8d80 commit b9452fb

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
/**
2929
* When the CRT Response File option is used in a request, the body is streamed directly to the file.
30+
* The S3CrtResponseHandlerAdapter in this case will never receive a response body but will call onStream
31+
* when the request is complete with a publisher that will complete immediately.
3032
* This transformer is effectively a no-op transformer that waits for the stream to complete and then
3133
* completes the future with the response.
3234
*
@@ -62,7 +64,7 @@ public void exceptionOccurred(Throwable throwable) {
6264
if (cf != null) {
6365
cf.completeExceptionally(throwable);
6466
} else {
65-
log.warn(() -> "An exception occurred before the call to prepare() was able to instantiate the CompletableFuture."
67+
log.warn(() -> "An exception occurred before the call to prepare() was able to instantiate the CompletableFuture. "
6668
+ "The future cannot be completed exceptionally because it is null");
6769
}
6870
}
@@ -85,12 +87,14 @@ public void onSubscribe(Subscription s) {
8587
return;
8688
}
8789
this.subscription = s;
88-
// Request the first chunk to start producing content
89-
s.request(1);
90+
// do not request data from the subscription since body is written directly to file
9091
}
9192

9293
@Override
9394
public void onNext(ByteBuffer byteBuffer) {
95+
// The response body is streamed directly to the file - this method should never be called.
96+
// ensure the future is completed exceptionally if this occurs
97+
onErrorMethod.accept(new IllegalStateException("OnCompleteSubscriber received unexpected call to onNext."));
9498
}
9599

96100
@Override

services/s3/src/test/java/software/amazon/awssdk/services/s3/internal/crt/CrtResponseFileResponseTransformerTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,21 @@
2424
import org.junit.jupiter.api.BeforeEach;
2525
import org.junit.jupiter.api.Test;
2626
import org.mockito.Mockito;
27+
import org.reactivestreams.Subscriber;
2728
import software.amazon.awssdk.core.SdkResponse;
2829
import software.amazon.awssdk.core.async.AsyncRequestBody;
2930
import software.amazon.awssdk.core.async.SdkPublisher;
3031

3132
public class CrtResponseFileResponseTransformerTest {
3233
private CrtResponseFileResponseTransformer<SdkResponse> transformer;
3334
private SdkResponse response;
34-
private SdkPublisher<ByteBuffer> publisher;
35+
private MockCrtPublisher publisher;
3536

3637
@BeforeEach
3738
public void setUp() throws Exception {
3839
transformer = new CrtResponseFileResponseTransformer<>();
3940
response = Mockito.mock(SdkResponse.class);
40-
publisher = AsyncRequestBody.fromString("");
41+
publisher = new MockCrtPublisher();
4142
}
4243

4344
@Test
@@ -46,6 +47,7 @@ void successfulResponseAndStream_returnsResponsePublisher() throws Exception {
4647
transformer.onResponse(response);
4748
assertThat(responseFuture.isDone()).isFalse();
4849
transformer.onStream(publisher);
50+
publisher.complete();
4951
assertThat(responseFuture.isDone()).isTrue();
5052
SdkResponse returnedResponse = responseFuture.get();
5153
assertThat(returnedResponse).isEqualTo(response);
@@ -74,4 +76,16 @@ void failedStream_completesExceptionally() {
7476
.hasCauseInstanceOf(RuntimeException.class);
7577
}
7678

79+
private static class MockCrtPublisher implements SdkPublisher<ByteBuffer> {
80+
private Subscriber<? super ByteBuffer> subscriber;
81+
@Override
82+
public void subscribe(Subscriber<? super ByteBuffer> s) {
83+
subscriber = s;
84+
}
85+
86+
public void complete() {
87+
subscriber.onComplete();
88+
}
89+
}
90+
7791
}

services/s3/src/test/java/software/amazon/awssdk/services/s3/internal/crt/S3CrtAsyncHttpClientTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,16 +571,14 @@ public void responseFilePathAndOption_shouldPassToCrt() {
571571
Path path = RandomTempFile.randomUncreatedFile().toPath();
572572

573573
AsyncExecuteRequest asyncExecuteRequest = getExecuteRequestBuilder()
574-
.putHttpExecutionAttribute(OPERATION_NAME,"GetObject")
574+
.putHttpExecutionAttribute(OPERATION_NAME, "GetObject")
575575
.putHttpExecutionAttribute(RESPONSE_FILE_PATH, path)
576576
.putHttpExecutionAttribute(RESPONSE_FILE_OPTION, S3MetaRequestOptions.ResponseFileOption.CREATE_OR_APPEND)
577577
.build();
578578

579579
S3MetaRequestOptions actual = makeRequest(asyncExecuteRequest);
580580
assertThat(actual.getResponseFilePath()).isEqualTo(path);
581581
assertThat(actual.getResponseFileOption()).isEqualTo(S3MetaRequestOptions.ResponseFileOption.CREATE_OR_APPEND);
582-
S3MetaRequestResponseHandler handler = actual.getResponseHandler();
583-
System.out.println(handler);
584582
}
585583

586584
private AsyncExecuteRequest.Builder getExecuteRequestBuilder() {

0 commit comments

Comments
 (0)