Skip to content

Commit 2bd587b

Browse files
authored
Fixed an issue where the clientName was not overridden for unmanaged async client (#2974)
1 parent 3bd1e2c commit 2bd587b

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"category": "AWS SDK for Java v2",
3+
"contributor": "",
4+
"type": "bugfix",
5+
"description": "Fixed an issue where the clientName was not overridden if an SdkAsyncHttpClient instance was provided"
6+
}

core/aws-core/src/test/java/software/amazon/awssdk/awscore/client/builder/DefaultAwsClientBuilderTest.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,39 @@ public void asyncHttpClientFactoryProvided_ClientIsManagedBySdk() {
160160

161161
@Test
162162
public void explicitClientProvided_ClientIsNotManagedBySdk() {
163+
String clientName = "foobarsync";
164+
SdkHttpClient sdkHttpClient = mock(SdkHttpClient.class);
163165
TestClient client = testClientBuilder()
164166
.region(Region.US_WEST_2)
165-
.httpClient(mock(SdkHttpClient.class))
167+
.httpClient(sdkHttpClient)
166168
.build();
169+
when(sdkHttpClient.clientName()).thenReturn(clientName);
167170
assertThat(client.clientConfiguration.option(SdkClientOption.SYNC_HTTP_CLIENT))
168171
.isInstanceOf(AwsDefaultClientBuilder.NonManagedSdkHttpClient.class);
172+
173+
assertThat(client.clientConfiguration.option(SdkClientOption.SYNC_HTTP_CLIENT).clientName())
174+
.isEqualTo(clientName);
169175
verify(defaultHttpClientBuilder, never()).buildWithDefaults(any());
170176
}
171177

172178
@Test
173179
public void explicitAsyncHttpClientProvided_ClientIsNotManagedBySdk() {
180+
String clientName = "foobarasync";
181+
SdkAsyncHttpClient sdkAsyncHttpClient = mock(SdkAsyncHttpClient.class);
174182
TestAsyncClient client = testAsyncClientBuilder()
175183
.region(Region.US_WEST_2)
176-
.httpClient(mock(SdkAsyncHttpClient.class))
184+
.httpClient(sdkAsyncHttpClient)
177185
.build();
178186
assertThat(client.clientConfiguration.option(SdkClientOption.ASYNC_HTTP_CLIENT))
179187
.isInstanceOf(AwsDefaultClientBuilder.NonManagedSdkAsyncHttpClient.class);
188+
189+
when(sdkAsyncHttpClient.clientName()).thenReturn(clientName);
190+
191+
assertThat(client.clientConfiguration.option(SdkClientOption.ASYNC_HTTP_CLIENT))
192+
.isInstanceOf(AwsDefaultClientBuilder.NonManagedSdkAsyncHttpClient.class);
193+
194+
assertThat(client.clientConfiguration.option(SdkClientOption.ASYNC_HTTP_CLIENT).clientName())
195+
.isEqualTo(clientName);
180196
verify(defaultAsyncHttpClientFactory, never()).buildWithDefaults(any());
181197
}
182198

core/sdk-core/src/main/java/software/amazon/awssdk/core/client/builder/SdkDefaultClientBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,11 @@ public CompletableFuture<Void> execute(AsyncExecuteRequest request) {
493493
return delegate.execute(request);
494494
}
495495

496+
@Override
497+
public String clientName() {
498+
return delegate.clientName();
499+
}
500+
496501
@Override
497502
public void close() {
498503
// Do nothing, this client is managed by the customer.

0 commit comments

Comments
 (0)