-
Notifications
You must be signed in to change notification settings - Fork 912
Create a configuration class for SdkPublisher#split #4236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
...e/src/main/java/software/amazon/awssdk/core/async/AsyncRequestBodySplitConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.awssdk.core.async; | ||
|
||
import java.util.Objects; | ||
import software.amazon.awssdk.annotations.SdkPublicApi; | ||
import software.amazon.awssdk.utils.Validate; | ||
import software.amazon.awssdk.utils.builder.CopyableBuilder; | ||
import software.amazon.awssdk.utils.builder.ToCopyableBuilder; | ||
|
||
/** | ||
* Configuration options for {@link AsyncRequestBody#split} to configure how the SDK | ||
* should split an {@link SdkPublisher}. | ||
*/ | ||
@SdkPublicApi | ||
public final class AsyncRequestBodySplitConfiguration implements ToCopyableBuilder<AsyncRequestBodySplitConfiguration.Builder, | ||
AsyncRequestBodySplitConfiguration> { | ||
private final Long chunkSizeInBytes; | ||
private final Long bufferSizeInBytes; | ||
|
||
private AsyncRequestBodySplitConfiguration(DefaultBuilder builder) { | ||
this.chunkSizeInBytes = Validate.isPositiveOrNull(builder.chunkSizeInBytes, "chunkSizeInBytes"); | ||
this.bufferSizeInBytes = Validate.isPositiveOrNull(builder.bufferSizeInBytes, "bufferSizeInBytes"); | ||
} | ||
|
||
/** | ||
* The configured chunk size for each divided {@link AsyncRequestBody}. | ||
*/ | ||
public Long chunkSizeInBytes() { | ||
return chunkSizeInBytes; | ||
} | ||
|
||
/** | ||
* The configured maximum buffer size the SDK will use to buffer the content from the source {@link SdkPublisher}. | ||
*/ | ||
public Long bufferSizeInBytes() { | ||
return bufferSizeInBytes; | ||
} | ||
|
||
/** | ||
* Create a {@link Builder}, used to create a {@link AsyncRequestBodySplitConfiguration}. | ||
*/ | ||
public static Builder builder() { | ||
return new DefaultBuilder(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
AsyncRequestBodySplitConfiguration that = (AsyncRequestBodySplitConfiguration) o; | ||
|
||
if (!Objects.equals(chunkSizeInBytes, that.chunkSizeInBytes)) { | ||
return false; | ||
} | ||
return Objects.equals(bufferSizeInBytes, that.bufferSizeInBytes); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = chunkSizeInBytes != null ? chunkSizeInBytes.hashCode() : 0; | ||
result = 31 * result + (bufferSizeInBytes != null ? bufferSizeInBytes.hashCode() : 0); | ||
return result; | ||
} | ||
|
||
@Override | ||
public AsyncRequestBodySplitConfiguration.Builder toBuilder() { | ||
return new DefaultBuilder(this); | ||
} | ||
|
||
public interface Builder extends CopyableBuilder<AsyncRequestBodySplitConfiguration.Builder, | ||
AsyncRequestBodySplitConfiguration> { | ||
|
||
/** | ||
* Configures the size for each divided chunk. The last chunk may be smaller than the configured size. The default value | ||
* is 2MB. | ||
* | ||
* @param chunkSizeInBytes the chunk size in bytes | ||
* @return This object for method chaining. | ||
*/ | ||
Builder chunkSizeInBytes(Long chunkSizeInBytes); | ||
|
||
/** | ||
* The maximum buffer size the SDK will use to buffer the content from the source {@link SdkPublisher}. The default value | ||
* is 8MB. | ||
* | ||
* @param bufferSizeInBytes the buffer size in bytes | ||
* @return This object for method chaining. | ||
*/ | ||
Builder bufferSizeInBytes(Long bufferSizeInBytes); | ||
} | ||
|
||
private static final class DefaultBuilder implements Builder { | ||
private Long chunkSizeInBytes; | ||
private Long bufferSizeInBytes; | ||
|
||
private DefaultBuilder(AsyncRequestBodySplitConfiguration asyncRequestBodySplitConfiguration) { | ||
this.chunkSizeInBytes = asyncRequestBodySplitConfiguration.chunkSizeInBytes; | ||
this.bufferSizeInBytes = asyncRequestBodySplitConfiguration.bufferSizeInBytes; | ||
} | ||
|
||
private DefaultBuilder() { | ||
|
||
} | ||
|
||
@Override | ||
public Builder chunkSizeInBytes(Long chunkSizeInBytes) { | ||
this.chunkSizeInBytes = chunkSizeInBytes; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Builder bufferSizeInBytes(Long bufferSizeInBytes) { | ||
this.bufferSizeInBytes = bufferSizeInBytes; | ||
return this; | ||
} | ||
|
||
@Override | ||
public AsyncRequestBodySplitConfiguration build() { | ||
return new AsyncRequestBodySplitConfiguration(this); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...re/src/test/java/software/amazon/awssdk/core/async/AsyncRequestBodyConfigurationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.awssdk.core.async; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import nl.jqno.equalsverifier.EqualsVerifier; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
public class AsyncRequestBodyConfigurationTest { | ||
|
||
@Test | ||
void equalsHashCode() { | ||
EqualsVerifier.forClass(AsyncRequestBodySplitConfiguration.class) | ||
.verify(); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(longs = {0, -1}) | ||
void nonPositiveValue_shouldThrowException(long size) { | ||
assertThatThrownBy(() -> | ||
AsyncRequestBodySplitConfiguration.builder() | ||
.chunkSizeInBytes(size) | ||
.build()) | ||
.hasMessageContaining("must be positive"); | ||
assertThatThrownBy(() -> | ||
AsyncRequestBodySplitConfiguration.builder() | ||
.bufferSizeInBytes(size) | ||
.build()) | ||
.hasMessageContaining("must be positive"); | ||
} | ||
|
||
@Test | ||
void toBuilder_shouldCopyAllFields() { | ||
AsyncRequestBodySplitConfiguration config = AsyncRequestBodySplitConfiguration.builder() | ||
.bufferSizeInBytes(1L) | ||
.chunkSizeInBytes(2L) | ||
.build(); | ||
|
||
assertThat(config.toBuilder().build()).isEqualTo(config); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.