From 85ed233e99847cb5262f7811efa87b6fabd78f23 Mon Sep 17 00:00:00 2001 From: David Negrete Date: Mon, 23 Jan 2023 12:46:10 -0700 Subject: [PATCH] Misc renaming --- .../feature-AWSCRTHTTPClient-61e1148.json | 6 + .../http/crt/AwsCrtAsyncHttpClient.java | 34 ++--- .../ConnectionHealthChecksConfiguration.java | 118 ------------------ .../crt/ConnectionHealthConfiguration.java | 118 ++++++++++++++++++ .../AwsCrtHttpClientSpiVerificationTest.java | 4 +- ...nnectionHealthChecksConfigurationTest.java | 64 ---------- .../ConnectionHealthConfigurationTest.java | 64 ++++++++++ 7 files changed, 207 insertions(+), 201 deletions(-) create mode 100644 .changes/next-release/feature-AWSCRTHTTPClient-61e1148.json delete mode 100644 http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/ConnectionHealthChecksConfiguration.java create mode 100644 http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/ConnectionHealthConfiguration.java delete mode 100644 http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/ConnectionHealthChecksConfigurationTest.java create mode 100644 http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/ConnectionHealthConfigurationTest.java diff --git a/.changes/next-release/feature-AWSCRTHTTPClient-61e1148.json b/.changes/next-release/feature-AWSCRTHTTPClient-61e1148.json new file mode 100644 index 000000000000..10a19a1ea0ed --- /dev/null +++ b/.changes/next-release/feature-AWSCRTHTTPClient-61e1148.json @@ -0,0 +1,6 @@ +{ + "category": "AWS CRT HTTP Client", + "contributor": "", + "type": "feature", + "description": "Renamed: `ConnectionHealthChecksConfiguration` -> `ConnectionHealthConfiguration`\nRenamed: `allowableThroughputFailureInterval` -> `minimumThroughputTimeout`\nRenamed: `minThroughputInBytesPerSecond` -> `minimumThroughputInBps`\nRenamed: `AwsCrtAsyncHttpClient.builder().connectionHealthChecksConfiguration` -> `AwsCrtAsyncHttpClient.builder().connectionHealthConfiguration`" +} diff --git a/http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/AwsCrtAsyncHttpClient.java b/http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/AwsCrtAsyncHttpClient.java index 08c7e89d9f4b..ae7f2374770a 100644 --- a/http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/AwsCrtAsyncHttpClient.java +++ b/http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/AwsCrtAsyncHttpClient.java @@ -111,20 +111,20 @@ private AwsCrtAsyncHttpClient(DefaultBuilder builder, AttributeMap config) { this.tlsContext = registerOwnedResource(clientTlsContext); this.readBufferSize = builder.readBufferSize == null ? DEFAULT_STREAM_WINDOW_SIZE : builder.readBufferSize; this.maxConnectionsPerEndpoint = config.get(SdkHttpConfigurationOption.MAX_CONNECTIONS); - this.monitoringOptions = revolveHttpMonitoringOptions(builder.connectionHealthChecksConfiguration); + this.monitoringOptions = revolveHttpMonitoringOptions(builder.connectionHealthConfiguration); this.maxConnectionIdleInMilliseconds = config.get(SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT).toMillis(); this.proxyOptions = buildProxyOptions(builder.proxyConfiguration); } } - private HttpMonitoringOptions revolveHttpMonitoringOptions(ConnectionHealthChecksConfiguration config) { + private HttpMonitoringOptions revolveHttpMonitoringOptions(ConnectionHealthConfiguration config) { if (config == null) { return null; } HttpMonitoringOptions httpMonitoringOptions = new HttpMonitoringOptions(); - httpMonitoringOptions.setMinThroughputBytesPerSecond(config.minThroughputInBytesPerSecond()); - int seconds = (int) config.allowableThroughputFailureInterval().getSeconds(); + httpMonitoringOptions.setMinThroughputBytesPerSecond(config.minimumThroughputInBps()); + int seconds = (int) config.minimumThroughputTimeout().getSeconds(); httpMonitoringOptions.setAllowableThroughputFailureIntervalSeconds(seconds); return httpMonitoringOptions; } @@ -355,25 +355,25 @@ public interface Builder extends SdkAsyncHttpClient.Builder * You can set a throughput threshold for a connection to be considered healthy. - * If a connection falls below this threshold ({@link ConnectionHealthChecksConfiguration#minThroughputInBytesPerSecond() + * If a connection falls below this threshold ({@link ConnectionHealthConfiguration#minimumThroughputInBps() * }) for the configurable amount - * of time ({@link ConnectionHealthChecksConfiguration#allowableThroughputFailureInterval()}), + * of time ({@link ConnectionHealthConfiguration#minimumThroughputTimeout()}), * then the connection is considered unhealthy and will be shut down. * * @param healthChecksConfiguration The health checks config to use * @return The builder of the method chaining. */ - Builder connectionHealthChecksConfiguration(ConnectionHealthChecksConfiguration healthChecksConfiguration); + Builder connectionHealthConfiguration(ConnectionHealthConfiguration healthChecksConfiguration); /** - * A convenience method that creates an instance of the {@link ConnectionHealthChecksConfiguration} builder, avoiding the - * need to create one manually via {@link ConnectionHealthChecksConfiguration#builder()}. + * A convenience method that creates an instance of the {@link ConnectionHealthConfiguration} builder, avoiding the + * need to create one manually via {@link ConnectionHealthConfiguration#builder()}. * * @param healthChecksConfigurationBuilder The health checks config builder to use * @return The builder of the method chaining. - * @see #connectionHealthChecksConfiguration(ConnectionHealthChecksConfiguration) + * @see #connectionHealthConfiguration(ConnectionHealthConfiguration) */ - Builder connectionHealthChecksConfiguration(Consumer + Builder connectionHealthConfiguration(Consumer healthChecksConfigurationBuilder); /** @@ -428,7 +428,7 @@ private static final class DefaultBuilder implements Builder { private final AttributeMap.Builder standardOptions = AttributeMap.builder(); private Integer readBufferSize; private ProxyConfiguration proxyConfiguration; - private ConnectionHealthChecksConfiguration connectionHealthChecksConfiguration; + private ConnectionHealthConfiguration connectionHealthConfiguration; private TcpKeepAliveConfiguration tcpKeepAliveConfiguration; private DefaultBuilder() { @@ -470,17 +470,17 @@ public Builder proxyConfiguration(ProxyConfiguration proxyConfiguration) { } @Override - public Builder connectionHealthChecksConfiguration(ConnectionHealthChecksConfiguration monitoringOptions) { - this.connectionHealthChecksConfiguration = monitoringOptions; + public Builder connectionHealthConfiguration(ConnectionHealthConfiguration monitoringOptions) { + this.connectionHealthConfiguration = monitoringOptions; return this; } @Override - public Builder connectionHealthChecksConfiguration(Consumer + public Builder connectionHealthConfiguration(Consumer configurationBuilder) { - ConnectionHealthChecksConfiguration.Builder builder = ConnectionHealthChecksConfiguration.builder(); + ConnectionHealthConfiguration.Builder builder = ConnectionHealthConfiguration.builder(); configurationBuilder.accept(builder); - return connectionHealthChecksConfiguration(builder.build()); + return connectionHealthConfiguration(builder.build()); } @Override diff --git a/http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/ConnectionHealthChecksConfiguration.java b/http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/ConnectionHealthChecksConfiguration.java deleted file mode 100644 index e9df57bb44db..000000000000 --- a/http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/ConnectionHealthChecksConfiguration.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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.http.crt; - -import java.time.Duration; -import software.amazon.awssdk.annotations.SdkPreviewApi; -import software.amazon.awssdk.annotations.SdkPublicApi; -import software.amazon.awssdk.utils.Validate; - -/** - * Configuration that defines health checks for all connections established by - * the {@link ConnectionHealthChecksConfiguration}. - * - * NOTE: This is a Preview API and is subject to change so it should not be used in production. - */ -@SdkPublicApi -@SdkPreviewApi -public final class ConnectionHealthChecksConfiguration { - private final long minThroughputInBytesPerSecond; - private final Duration allowableThroughputFailureInterval; - - private ConnectionHealthChecksConfiguration(DefaultConnectionHealthChecksConfigurationBuilder builder) { - this.minThroughputInBytesPerSecond = Validate.paramNotNull(builder.minThroughputInBytesPerSecond, - "minThroughputInBytesPerSecond"); - this.allowableThroughputFailureInterval = Validate.isPositive(builder.allowableThroughputFailureIntervalSeconds, - "allowableThroughputFailureIntervalSeconds"); - } - - /** - * @return the minimum amount of throughput, in bytes per second, for a connection to be considered healthy. - */ - public long minThroughputInBytesPerSecond() { - return minThroughputInBytesPerSecond; - } - - /** - * @return How long a connection is allowed to be unhealthy before getting shut down. - */ - public Duration allowableThroughputFailureInterval() { - return allowableThroughputFailureInterval; - } - - public static Builder builder() { - return new DefaultConnectionHealthChecksConfigurationBuilder(); - } - - /** - * A builder for {@link ConnectionHealthChecksConfiguration}. - * - *

All implementations of this interface are mutable and not thread safe.

- */ - public interface Builder { - - /** - * Sets a throughput threshold for connections. Throughput below this value will be considered unhealthy. - * - * @param minThroughputInBytesPerSecond minimum amount of throughput, in bytes per second, for a connection to be - * considered healthy. - * @return Builder - */ - Builder minThroughputInBytesPerSecond(Long minThroughputInBytesPerSecond); - - /** - * Sets how long a connection is allowed to be unhealthy before getting shut down. - * - *

- * It only supports seconds precision - * - * @param allowableThroughputFailureIntervalSeconds How long a connection is allowed to be unhealthy - * before getting shut down. - * @return Builder - */ - Builder allowableThroughputFailureInterval(Duration allowableThroughputFailureIntervalSeconds); - - ConnectionHealthChecksConfiguration build(); - } - - /** - * An SDK-internal implementation of {@link Builder}. - */ - private static final class DefaultConnectionHealthChecksConfigurationBuilder implements Builder { - private Long minThroughputInBytesPerSecond; - private Duration allowableThroughputFailureIntervalSeconds; - - private DefaultConnectionHealthChecksConfigurationBuilder() { - } - - @Override - public Builder minThroughputInBytesPerSecond(Long minThroughputInBytesPerSecond) { - this.minThroughputInBytesPerSecond = minThroughputInBytesPerSecond; - return this; - } - - @Override - public Builder allowableThroughputFailureInterval(Duration allowableThroughputFailureIntervalSeconds) { - this.allowableThroughputFailureIntervalSeconds = allowableThroughputFailureIntervalSeconds; - return this; - } - - @Override - public ConnectionHealthChecksConfiguration build() { - return new ConnectionHealthChecksConfiguration(this); - } - } -} diff --git a/http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/ConnectionHealthConfiguration.java b/http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/ConnectionHealthConfiguration.java new file mode 100644 index 000000000000..a1215acdacc7 --- /dev/null +++ b/http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/ConnectionHealthConfiguration.java @@ -0,0 +1,118 @@ +/* + * 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.http.crt; + +import java.time.Duration; +import software.amazon.awssdk.annotations.SdkPreviewApi; +import software.amazon.awssdk.annotations.SdkPublicApi; +import software.amazon.awssdk.utils.Validate; + +/** + * Configuration that defines health checks for all connections established by + * the {@link ConnectionHealthConfiguration}. + * + * NOTE: This is a Preview API and is subject to change so it should not be used in production. + */ +@SdkPublicApi +@SdkPreviewApi +public final class ConnectionHealthConfiguration { + private final long minimumThroughputInBps; + private final Duration minimumThroughputTimeout; + + private ConnectionHealthConfiguration(DefaultConnectionHealthConfigurationBuilder builder) { + this.minimumThroughputInBps = Validate.paramNotNull(builder.minimumThroughputInBps, + "minimumThroughputInBps"); + this.minimumThroughputTimeout = Validate.isPositive(builder.minimumThroughputTimeout, + "minimumThroughputTimeout"); + } + + /** + * @return the minimum amount of throughput, in bytes per second, for a connection to be considered healthy. + */ + public long minimumThroughputInBps() { + return minimumThroughputInBps; + } + + /** + * @return How long a connection is allowed to be unhealthy before getting shut down. + */ + public Duration minimumThroughputTimeout() { + return minimumThroughputTimeout; + } + + public static Builder builder() { + return new DefaultConnectionHealthConfigurationBuilder(); + } + + /** + * A builder for {@link ConnectionHealthConfiguration}. + * + *

All implementations of this interface are mutable and not thread safe.

+ */ + public interface Builder { + + /** + * Sets a throughput threshold for connections. Throughput below this value will be considered unhealthy. + * + * @param minimumThroughputInBps minimum amount of throughput, in bytes per second, for a connection to be + * considered healthy. + * @return Builder + */ + Builder minimumThroughputInBps(Long minimumThroughputInBps); + + /** + * Sets how long a connection is allowed to be unhealthy before getting shut down. + * + *

+ * It only supports seconds precision + * + * @param minimumThroughputTimeout How long a connection is allowed to be unhealthy + * before getting shut down. + * @return Builder + */ + Builder minimumThroughputTimeout(Duration minimumThroughputTimeout); + + ConnectionHealthConfiguration build(); + } + + /** + * An SDK-internal implementation of {@link Builder}. + */ + private static final class DefaultConnectionHealthConfigurationBuilder implements Builder { + private Long minimumThroughputInBps; + private Duration minimumThroughputTimeout; + + private DefaultConnectionHealthConfigurationBuilder() { + } + + @Override + public Builder minimumThroughputInBps(Long minimumThroughputInBps) { + this.minimumThroughputInBps = minimumThroughputInBps; + return this; + } + + @Override + public Builder minimumThroughputTimeout(Duration minimumThroughputTimeout) { + this.minimumThroughputTimeout = minimumThroughputTimeout; + return this; + } + + @Override + public ConnectionHealthConfiguration build() { + return new ConnectionHealthConfiguration(this); + } + } +} diff --git a/http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/AwsCrtHttpClientSpiVerificationTest.java b/http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/AwsCrtHttpClientSpiVerificationTest.java index 5594f82d827b..3d0ccab3fd7c 100644 --- a/http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/AwsCrtHttpClientSpiVerificationTest.java +++ b/http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/AwsCrtHttpClientSpiVerificationTest.java @@ -76,8 +76,8 @@ public class AwsCrtHttpClientSpiVerificationTest { @BeforeClass public static void setup() throws Exception { client = AwsCrtAsyncHttpClient.builder() - .connectionHealthChecksConfiguration(b -> b.minThroughputInBytesPerSecond(4068L) - .allowableThroughputFailureInterval(Duration.ofSeconds(3))) + .connectionHealthConfiguration(b -> b.minimumThroughputInBps(4068L) + .minimumThroughputTimeout(Duration.ofSeconds(3))) .build(); } diff --git a/http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/ConnectionHealthChecksConfigurationTest.java b/http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/ConnectionHealthChecksConfigurationTest.java deleted file mode 100644 index a0b642d844e3..000000000000 --- a/http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/ConnectionHealthChecksConfigurationTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.http.crt; - - - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import java.time.Duration; -import org.junit.jupiter.api.Test; - -public class ConnectionHealthChecksConfigurationTest { - - @Test - public void builder_allPropertiesSet() { - ConnectionHealthChecksConfiguration connectionHealthChecksConfiguration = - ConnectionHealthChecksConfiguration.builder() - .minThroughputInBytesPerSecond(123l) - .allowableThroughputFailureInterval(Duration.ofSeconds(1)) - .build(); - - assertThat(connectionHealthChecksConfiguration.minThroughputInBytesPerSecond()).isEqualTo(123); - assertThat(connectionHealthChecksConfiguration.allowableThroughputFailureInterval()).isEqualTo(Duration.ofSeconds(1)); - } - - @Test - public void builder_nullMinThroughputInBytesPerSecond_shouldThrowException() { - assertThatThrownBy(() -> - ConnectionHealthChecksConfiguration.builder() - .allowableThroughputFailureInterval(Duration.ofSeconds(1)) - .build()).hasMessageContaining("minThroughputInBytesPerSecond"); - } - - @Test - public void builder_nullAllowableThroughputFailureInterval() { - assertThatThrownBy(() -> - ConnectionHealthChecksConfiguration.builder() - .minThroughputInBytesPerSecond(1L) - .build()).hasMessageContaining("allowableThroughputFailureIntervalSeconds"); - } - - @Test - public void builder_negativeAllowableThroughputFailureInterval() { - assertThatThrownBy(() -> - ConnectionHealthChecksConfiguration.builder() - .minThroughputInBytesPerSecond(1L) - .allowableThroughputFailureInterval(Duration.ofSeconds(-1)) - .build()).hasMessageContaining("allowableThroughputFailureIntervalSeconds"); - } -} diff --git a/http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/ConnectionHealthConfigurationTest.java b/http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/ConnectionHealthConfigurationTest.java new file mode 100644 index 000000000000..d7cde8992d90 --- /dev/null +++ b/http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/ConnectionHealthConfigurationTest.java @@ -0,0 +1,64 @@ +/* + * 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.http.crt; + + + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.time.Duration; +import org.junit.jupiter.api.Test; + +class ConnectionHealthConfigurationTest { + + @Test + void builder_allPropertiesSet() { + ConnectionHealthConfiguration connectionHealthConfiguration = + ConnectionHealthConfiguration.builder() + .minimumThroughputInBps(123l) + .minimumThroughputTimeout(Duration.ofSeconds(1)) + .build(); + + assertThat(connectionHealthConfiguration.minimumThroughputInBps()).isEqualTo(123); + assertThat(connectionHealthConfiguration.minimumThroughputTimeout()).isEqualTo(Duration.ofSeconds(1)); + } + + @Test + void builder_nullMinimumThroughputInBps_shouldThrowException() { + assertThatThrownBy(() -> + ConnectionHealthConfiguration.builder() + .minimumThroughputTimeout(Duration.ofSeconds(1)) + .build()).hasMessageContaining("minimumThroughputInBps"); + } + + @Test + void builder_nullMinimumThroughputTimeout() { + assertThatThrownBy(() -> + ConnectionHealthConfiguration.builder() + .minimumThroughputInBps(1L) + .build()).hasMessageContaining("minimumThroughputTimeout"); + } + + @Test + void builder_negativeMinimumThroughputTimeout() { + assertThatThrownBy(() -> + ConnectionHealthConfiguration.builder() + .minimumThroughputInBps(1L) + .minimumThroughputTimeout(Duration.ofSeconds(-1)) + .build()).hasMessageContaining("minimumThroughputTimeout"); + } +}