Skip to content

AsyncClientBuilder cleanup #565

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 1 commit into from
Jun 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/next-release/feature-AWSSDKforJavav2-edcd48b.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"category": "AWS SDK for Java v2",
"type": "feature",
"description": "Various AsyncClient Refactors:\\n - Drop async prefix in `SdkAyncClientBuilder`: `SdkAsyncClientBuilder.asyncHttpClientBuilder() -> SdkAsyncClientBuilder.httpClientBuilder()`\\n - Create `SdkEventLoopGroup` to allow users to provide `EventLoopGroup` and `ChannelFactory`."
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void noAsyncClientProvided_DefaultAsyncHttpClientIsManagedBySdk() {
public void clientFactoryProvided_ClientIsManagedBySdk() {
TestClient client = testClientBuilder()
.region(Region.US_WEST_2)
.httpClientBuilder(serviceDefaults -> {
.httpClientBuilder((SdkHttpClient.Builder) serviceDefaults -> {
assertThat(serviceDefaults).isEqualTo(MOCK_DEFAULTS);
return mock(SdkHttpClient.class);
})
Expand All @@ -140,7 +140,7 @@ public void clientFactoryProvided_ClientIsManagedBySdk() {
public void asyncHttpClientFactoryProvided_ClientIsManagedBySdk() {
TestAsyncClient client = testAsyncClientBuilder()
.region(Region.US_WEST_2)
.asyncHttpClientBuilder(serviceDefaults -> {
.httpClientBuilder((SdkAsyncHttpClient.Builder) serviceDefaults -> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have to cast it here since SdkDefaultClientBuilder implements both SdkAsyncClientBuilder and SdkSyncClientBuilder and has overloads of httpClientBuilder for async and sync. I think this is fine as SdkDefaultClientBuilder is protected api

assertThat(serviceDefaults).isEqualTo(MOCK_DEFAULTS);
return mock(SdkAsyncHttpClient.class);
})
Expand All @@ -165,7 +165,7 @@ public void explicitClientProvided_ClientIsNotManagedBySdk() {
public void explicitAsyncHttpClientProvided_ClientIsNotManagedBySdk() {
TestAsyncClient client = testAsyncClientBuilder()
.region(Region.US_WEST_2)
.asyncHttpClient(mock(SdkAsyncHttpClient.class))
.httpClient(mock(SdkAsyncHttpClient.class))
.build();
assertThat(client.clientConfiguration.option(SdkClientOption.ASYNC_HTTP_CLIENT))
.isInstanceOf(AwsDefaultClientBuilder.NonManagedSdkAsyncHttpClient.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ default B asyncConfiguration(Consumer<ClientAsyncConfiguration.Builder> clientAs
* shared between multiple SDK service clients to share a common connection pool. To create a client you must use an
* implementation specific builder. Note that this method is only recommended when you wish to share an HTTP client across
* multiple SDK service clients. If you do not wish to share HTTP clients, it is recommended to use
* {@link #asyncHttpClientBuilder(SdkAsyncHttpClient.Builder)} so that service specific default configuration may be applied.
* {@link #httpClientBuilder(SdkAsyncHttpClient.Builder)} so that service specific default configuration may be applied.
*
* <p>
* <b>This client must be closed by the caller when it is ready to be disposed. The SDK will not close the HTTP client
Expand All @@ -59,7 +59,7 @@ default B asyncConfiguration(Consumer<ClientAsyncConfiguration.Builder> clientAs
*
* @return This builder for method chaining.
*/
B asyncHttpClient(SdkAsyncHttpClient httpClient);
B httpClient(SdkAsyncHttpClient httpClient);

/**
* Sets a custom HTTP client builder that will be used to obtain a configured instance of {@link SdkAsyncHttpClient}. Any
Expand All @@ -73,5 +73,5 @@ default B asyncConfiguration(Consumer<ClientAsyncConfiguration.Builder> clientAs
*
* @return This builder for method chaining.
*/
B asyncHttpClientBuilder(SdkAsyncHttpClient.Builder httpClientBuilder);
B httpClientBuilder(SdkAsyncHttpClient.Builder httpClientBuilder);
}
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,12 @@ public final B httpClientBuilder(SdkHttpClient.Builder httpClientBuilder) {
return thisBuilder();
}

public final B asyncHttpClient(SdkAsyncHttpClient httpClient) {
public final B httpClient(SdkAsyncHttpClient httpClient) {
clientConfiguration.option(ASYNC_HTTP_CLIENT, httpClient);
return thisBuilder();
}

public final B asyncHttpClientBuilder(SdkAsyncHttpClient.Builder httpClientBuilder) {
public final B httpClientBuilder(SdkAsyncHttpClient.Builder httpClientBuilder) {
this.asyncHttpClientBuilder = httpClientBuilder;
return thisBuilder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.time.Duration;
import java.util.Arrays;
import java.util.Optional;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -107,13 +108,10 @@ public void noAsyncClientProvided_DefaultAsyncHttpClientIsManagedBySdk() {

@Test
public void clientFactoryProvided_ClientIsManagedBySdk() {
TestClient client = testClientBuilder().httpClientBuilder(new SdkHttpClient.Builder() {
@Override
public SdkHttpClient buildWithDefaults(AttributeMap serviceDefaults) {
assertThat(serviceDefaults).isEqualTo(MOCK_DEFAULTS);
return mock(SdkHttpClient.class);
}
})
TestClient client = testClientBuilder().httpClientBuilder((SdkHttpClient.Builder) serviceDefaults -> {
Assertions.assertThat(serviceDefaults).isEqualTo(MOCK_DEFAULTS);
return mock(SdkHttpClient.class);
})
.build();
assertThat(client.clientConfiguration.option(SdkClientOption.SYNC_HTTP_CLIENT))
.isNotInstanceOf(SdkDefaultClientBuilder.NonManagedSdkHttpClient.class);
Expand All @@ -123,7 +121,7 @@ public SdkHttpClient buildWithDefaults(AttributeMap serviceDefaults) {
@Test
public void asyncHttpClientFactoryProvided_ClientIsManagedBySdk() {
TestAsyncClient client = testAsyncClientBuilder()
.asyncHttpClientBuilder(serviceDefaults -> {
.httpClientBuilder((SdkAsyncHttpClient.Builder) serviceDefaults -> {
assertThat(serviceDefaults).isEqualTo(MOCK_DEFAULTS);
return mock(SdkAsyncHttpClient.class);
})
Expand All @@ -147,7 +145,7 @@ public void explicitClientProvided_ClientIsNotManagedBySdk() {
@Test
public void explicitAsyncHttpClientProvided_ClientIsNotManagedBySdk() {
TestAsyncClient client = testAsyncClientBuilder()
.asyncHttpClient(mock(SdkAsyncHttpClient.class))
.httpClient(mock(SdkAsyncHttpClient.class))
.build();
assertThat(client.clientConfiguration.option(SdkClientOption.ASYNC_HTTP_CLIENT))
.isInstanceOf(SdkDefaultClientBuilder.NonManagedSdkAsyncHttpClient.class);
Expand Down

This file was deleted.

This file was deleted.

Loading