diff --git a/.changes/next-release/feature-AWSS3-1be6ddd.json b/.changes/next-release/feature-AWSS3-1be6ddd.json new file mode 100644 index 000000000000..b1300cf9016a --- /dev/null +++ b/.changes/next-release/feature-AWSS3-1be6ddd.json @@ -0,0 +1,6 @@ +{ + "type": "feature", + "category": "AWS S3", + "contributor": "benarnao", + "description": "allow user to configure subscriber timeout for input stream" +} diff --git a/core/sdk-core/src/main/java/software/amazon/awssdk/core/async/AsyncRequestBody.java b/core/sdk-core/src/main/java/software/amazon/awssdk/core/async/AsyncRequestBody.java index cde394b6ed42..2e55918ed3de 100644 --- a/core/sdk-core/src/main/java/software/amazon/awssdk/core/async/AsyncRequestBody.java +++ b/core/sdk-core/src/main/java/software/amazon/awssdk/core/async/AsyncRequestBody.java @@ -384,6 +384,8 @@ static AsyncRequestBody fromInputStream(ConsumerBy default, it will time out if streaming hasn't started within 10 seconds, and you can configure the timeout + * via {@link BlockingInputStreamAsyncRequestBody#builder()} *

Example Usage * *

@@ -408,7 +410,9 @@ static AsyncRequestBody fromInputStream(ConsumerYou may want to increase it if the request may not be executed right away. + * + * @param subscribeTimeout the timeout + * @return Returns a reference to this object so that method calls can be chained together. + */ + public Builder subscribeTimeout(Duration subscribeTimeout) { + this.subscribeTimeout = subscribeTimeout; + return this; + } + + /** + * The content length of the output stream. + * + * @param contentLength the content length + * @return Returns a reference to this object so that method calls can be chained together. + */ + public Builder contentLength(Long contentLength) { + this.contentLength = contentLength; + return this; + } + + public BlockingInputStreamAsyncRequestBody build() { + return new BlockingInputStreamAsyncRequestBody(this); + } + } +} } diff --git a/core/sdk-core/src/test/java/software/amazon/awssdk/core/async/BlockingInputStreamAsyncRequestBodyTest.java b/core/sdk-core/src/test/java/software/amazon/awssdk/core/async/BlockingInputStreamAsyncRequestBodyTest.java index 70f91aefdbbf..d0d8ef761bf0 100644 --- a/core/sdk-core/src/test/java/software/amazon/awssdk/core/async/BlockingInputStreamAsyncRequestBodyTest.java +++ b/core/sdk-core/src/test/java/software/amazon/awssdk/core/async/BlockingInputStreamAsyncRequestBodyTest.java @@ -47,9 +47,9 @@ public void doBlockingWrite_waitsForSubscription() { @Test @Timeout(10) - public void doBlockingWrite_failsIfSubscriptionNeverComes() { + public void doBlockingWrite_overrideSubscribeTimeout_failsIfSubscriptionNeverComes() { BlockingInputStreamAsyncRequestBody requestBody = - new BlockingInputStreamAsyncRequestBody(0L, Duration.ofSeconds(1)); + BlockingInputStreamAsyncRequestBody.builder().contentLength(0L).subscribeTimeout(Duration.ofSeconds(1)).build(); assertThatThrownBy(() -> requestBody.writeInputStream(new StringInputStream(""))) .hasMessageContaining("The service request was not made"); }