Skip to content

Commit 7a94bc5

Browse files
committed
Bump up crt version adn remove elg and host resolver configs
1 parent 82bb676 commit 7a94bc5

File tree

15 files changed

+135
-152
lines changed

15 files changed

+135
-152
lines changed

http-clients/aws-crt-client/src/it/java/software/amazon/awssdk/http/crt/AwsCrtClientCallingPatternIntegrationTest.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,7 @@ private boolean testWithClient(KmsAsyncClient asyncKMSClient, int numberOfReques
9898

9999
private boolean testWithNewClient(int eventLoopSize, int numberOfRequests) {
100100

101-
try (EventLoopGroup eventLoopGroup = new EventLoopGroup(eventLoopSize);
102-
HostResolver hostResolver = new HostResolver(eventLoopGroup);
103-
SdkAsyncHttpClient newAwsCrtHttpClient = AwsCrtAsyncHttpClient.builder()
104-
.eventLoopGroup(eventLoopGroup)
105-
.hostResolver(hostResolver)
101+
try (SdkAsyncHttpClient newAwsCrtHttpClient = AwsCrtAsyncHttpClient.builder()
106102
.build()) {
107103
try (KmsAsyncClient newAsyncKMSClient = KmsAsyncClient.builder()
108104
.region(REGION)
@@ -162,12 +158,7 @@ public void checkAllCombinations(@FromDataPoints("EventLoop") int eventLoopSize,
162158
.put(SdkHttpConfigurationOption.MAX_CONNECTIONS, connectionPoolSize)
163159
.build();
164160

165-
EventLoopGroup eventLoopGroup = new EventLoopGroup(eventLoopSize);
166-
HostResolver hostResolver = new HostResolver(eventLoopGroup);
167-
168161
SdkAsyncHttpClient awsCrtHttpClient = AwsCrtAsyncHttpClient.builder()
169-
.eventLoopGroup(eventLoopGroup)
170-
.hostResolver(hostResolver)
171162
.buildWithDefaults(attributes);
172163

173164
KmsAsyncClient sharedAsyncKMSClient = KmsAsyncClient.builder()
@@ -203,9 +194,6 @@ public void checkAllCombinations(@FromDataPoints("EventLoop") int eventLoopSize,
203194
awsCrtHttpClient.close();
204195
Assert.assertFalse(failed.get());
205196

206-
hostResolver.close();
207-
eventLoopGroup.close();
208-
209197
CrtResource.waitForNoResources();
210198

211199
float numSeconds = (float) ((System.currentTimeMillis() - start) / 1000.0);

http-clients/aws-crt-client/src/it/java/software/amazon/awssdk/http/crt/AwsCrtClientKmsIntegrationTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ public void setup() {
5252
hostResolver = new HostResolver(eventLoopGroup);
5353

5454
SdkAsyncHttpClient awsCrtHttpClient = AwsCrtAsyncHttpClient.builder()
55-
.eventLoopGroup(eventLoopGroup)
56-
.hostResolver(hostResolver)
5755
.build();
5856

5957
awsCrtHttpClients.add(awsCrtHttpClient);

http-clients/aws-crt-client/src/it/java/software/amazon/awssdk/http/crt/AwsCrtClientS3IntegrationTest.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,7 @@ public class AwsCrtClientS3IntegrationTest {
6262
public void setup() {
6363
CrtResource.waitForNoResources();
6464

65-
int numThreads = 4;
66-
eventLoopGroup = new EventLoopGroup(numThreads);
67-
hostResolver = new HostResolver(eventLoopGroup);
68-
69-
crtClient = AwsCrtAsyncHttpClient.builder()
70-
.eventLoopGroup(eventLoopGroup)
71-
.hostResolver(hostResolver)
72-
.build();
65+
crtClient = AwsCrtAsyncHttpClient.create();
7366

7467
s3 = S3AsyncClient.builder()
7568
.region(REGION)

http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/AwsCrtAsyncHttpClient.java

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import software.amazon.awssdk.crt.http.HttpMonitoringOptions;
3232
import software.amazon.awssdk.crt.http.HttpProxyOptions;
3333
import software.amazon.awssdk.crt.io.ClientBootstrap;
34-
import software.amazon.awssdk.crt.io.EventLoopGroup;
35-
import software.amazon.awssdk.crt.io.HostResolver;
3634
import software.amazon.awssdk.crt.io.SocketOptions;
3735
import software.amazon.awssdk.crt.io.TlsCipherPreference;
3836
import software.amazon.awssdk.crt.io.TlsContext;
@@ -78,10 +76,8 @@ private AwsCrtAsyncHttpClient(DefaultBuilder builder, AttributeMap config) {
7876
Validate.isPositive(maxConns, "maxConns");
7977
Validate.notNull(builder.cipherPreference, "cipherPreference");
8078
Validate.isPositive(builder.readBufferSize, "readBufferSize");
81-
Validate.notNull(builder.eventLoopGroup, "eventLoopGroup");
82-
Validate.notNull(builder.hostResolver, "hostResolver");
8379

84-
try (ClientBootstrap clientBootstrap = new ClientBootstrap(builder.eventLoopGroup, builder.hostResolver);
80+
try (ClientBootstrap clientBootstrap = new ClientBootstrap(null, null);
8581
SocketOptions clientSocketOptions = new SocketOptions();
8682
TlsContextOptions clientTlsContextOptions = TlsContextOptions.createDefaultClient() // NOSONAR
8783
.withCipherPreference(builder.cipherPreference)
@@ -288,20 +284,6 @@ public interface Builder extends SdkAsyncHttpClient.Builder<AwsCrtAsyncHttpClien
288284
*/
289285
Builder readBufferSize(int readBufferSize);
290286

291-
/**
292-
* The AWS CRT EventLoopGroup to use for this Client.
293-
* @param eventLoopGroup The AWS CRT EventLoopGroup to use for this client.
294-
* @return The builder of the method chaining.
295-
*/
296-
Builder eventLoopGroup(EventLoopGroup eventLoopGroup);
297-
298-
/**
299-
* The AWS CRT HostResolver to use for this Client.
300-
* @param hostResolver The AWS CRT HostResolver to use for this client.
301-
* @return The builder of the method chaining.
302-
*/
303-
Builder hostResolver(HostResolver hostResolver);
304-
305287
/**
306288
* Sets the http proxy configuration to use for this client.
307289
* @param proxyConfiguration The http proxy configuration to use
@@ -359,8 +341,6 @@ private static final class DefaultBuilder implements Builder {
359341
private final AttributeMap.Builder standardOptions = AttributeMap.builder();
360342
private TlsCipherPreference cipherPreference = TlsCipherPreference.TLS_CIPHER_SYSTEM_DEFAULT;
361343
private int readBufferSize = DEFAULT_STREAM_WINDOW_SIZE;
362-
private EventLoopGroup eventLoopGroup;
363-
private HostResolver hostResolver;
364344
private ProxyConfiguration proxyConfiguration;
365345
private ConnectionHealthChecksConfiguration connectionHealthChecksConfiguration;
366346

@@ -403,18 +383,6 @@ public Builder readBufferSize(int readBufferSize) {
403383
return this;
404384
}
405385

406-
@Override
407-
public Builder eventLoopGroup(EventLoopGroup eventLoopGroup) {
408-
this.eventLoopGroup = eventLoopGroup;
409-
return this;
410-
}
411-
412-
@Override
413-
public Builder hostResolver(HostResolver hostResolver) {
414-
this.hostResolver = hostResolver;
415-
return this;
416-
}
417-
418386
@Override
419387
public Builder proxyConfiguration(ProxyConfiguration proxyConfiguration) {
420388
this.proxyConfiguration = proxyConfiguration;

http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/AwsCrtHttpClientSpiVerificationTest.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,13 @@ public class AwsCrtHttpClientSpiVerificationTest {
6565
.dynamicPort()
6666
.dynamicHttpsPort());
6767

68-
private EventLoopGroup eventLoopGroup;
69-
private HostResolver hostResolver;
7068
private SdkAsyncHttpClient client;
7169

7270
@Before
7371
public void setup() throws Exception {
7472
CrtResource.waitForNoResources();
7573

76-
int numThreads = Runtime.getRuntime().availableProcessors();
77-
eventLoopGroup = new EventLoopGroup(numThreads);
78-
hostResolver = new HostResolver(eventLoopGroup);
79-
8074
client = AwsCrtAsyncHttpClient.builder()
81-
.eventLoopGroup(eventLoopGroup)
82-
.hostResolver(hostResolver)
8375
.connectionHealthChecksConfiguration(b -> b.minThroughputInBytesPerSecond(4068L)
8476
.allowableThroughputFailureInterval(Duration.ofSeconds(3)))
8577
.build();
@@ -88,8 +80,8 @@ public void setup() throws Exception {
8880
@After
8981
public void tearDown() {
9082
client.close();
91-
hostResolver.close();
92-
eventLoopGroup.close();
83+
EventLoopGroup.closeStaticDefault();
84+
HostResolver.closeStaticDefault();
9385
CrtResource.waitForNoResources();
9486
}
9587

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.http.crt;
17+
18+
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
19+
import static com.github.tomakehurst.wiremock.client.WireMock.any;
20+
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
21+
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
22+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
23+
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
24+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
25+
import static software.amazon.awssdk.http.HttpTestUtils.createProvider;
26+
import static software.amazon.awssdk.http.crt.CrtHttpClientTestUtils.createRequest;
27+
28+
import com.github.tomakehurst.wiremock.junit.WireMockRule;
29+
import java.net.URI;
30+
import java.util.concurrent.TimeUnit;
31+
import org.junit.After;
32+
import org.junit.Before;
33+
import org.junit.BeforeClass;
34+
import org.junit.Rule;
35+
import org.junit.Test;
36+
import software.amazon.awssdk.crt.CrtResource;
37+
import software.amazon.awssdk.crt.io.EventLoopGroup;
38+
import software.amazon.awssdk.crt.io.HostResolver;
39+
import software.amazon.awssdk.http.RecordingNetworkTrafficListener;
40+
import software.amazon.awssdk.http.RecordingResponseHandler;
41+
import software.amazon.awssdk.http.SdkHttpRequest;
42+
import software.amazon.awssdk.http.async.AsyncExecuteRequest;
43+
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
44+
import software.amazon.awssdk.utils.Logger;
45+
46+
public class AwsCrtHttpClientWireMockTest {
47+
private static final Logger log = Logger.loggerFor(AwsCrtHttpClientWireMockTest.class);
48+
private final RecordingNetworkTrafficListener wiremockTrafficListener = new RecordingNetworkTrafficListener();
49+
50+
@Rule
51+
public WireMockRule mockServer = new WireMockRule(wireMockConfig()
52+
.dynamicPort()
53+
.dynamicHttpsPort()
54+
.networkTrafficListener(wiremockTrafficListener));
55+
56+
@BeforeClass
57+
public static void setup() {
58+
System.setProperty("aws.crt.debugnative", "true");
59+
}
60+
61+
@Before
62+
public void methodSetup() {
63+
wiremockTrafficListener.reset();
64+
}
65+
66+
@After
67+
public void tearDown() {
68+
// Verify there is no resource leak.
69+
EventLoopGroup.closeStaticDefault();
70+
HostResolver.closeStaticDefault();
71+
CrtResource.waitForNoResources();
72+
}
73+
74+
@Test
75+
public void closeClient_reuse_throwException() throws Exception {
76+
SdkAsyncHttpClient client = AwsCrtAsyncHttpClient.create();
77+
78+
client.close();
79+
assertThatThrownBy(() -> makeSimpleRequest(client)).hasMessageContaining("is closed");
80+
}
81+
82+
@Test
83+
public void sharedEventLoopGroup_closeOneClient_shouldNotAffectOtherClients() throws Exception {
84+
try (SdkAsyncHttpClient client = AwsCrtAsyncHttpClient.create()) {
85+
makeSimpleRequest(client);
86+
}
87+
88+
try (SdkAsyncHttpClient anotherClient = AwsCrtAsyncHttpClient.create()) {
89+
makeSimpleRequest(anotherClient);
90+
}
91+
}
92+
93+
/**
94+
* Make a simple async request and wait for it to finish.
95+
*
96+
* @param client Client to make request with.
97+
*/
98+
private void makeSimpleRequest(SdkAsyncHttpClient client) throws Exception {
99+
String body = randomAlphabetic(10);
100+
URI uri = URI.create("http://localhost:" + mockServer.port());
101+
stubFor(any(urlPathEqualTo("/")).willReturn(aResponse().withBody(body)));
102+
SdkHttpRequest request = createRequest(uri);
103+
RecordingResponseHandler recorder = new RecordingResponseHandler();
104+
client.execute(AsyncExecuteRequest.builder().request(request).requestContentPublisher(createProvider("")).responseHandler(recorder).build());
105+
recorder.completeFuture().get(5, TimeUnit.SECONDS);
106+
}
107+
}

http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/H1ServerBehaviorTest.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,8 @@ public class H1ServerBehaviorTest extends SdkAsyncHttpClientH1TestSuite {
3030

3131
@Override
3232
protected SdkAsyncHttpClient setupClient() {
33-
int numThreads = Runtime.getRuntime().availableProcessors();
34-
try (EventLoopGroup eventLoopGroup = new EventLoopGroup(numThreads);
35-
HostResolver hostResolver = new HostResolver(eventLoopGroup)) {
36-
37-
return AwsCrtAsyncHttpClient.builder()
38-
.eventLoopGroup(eventLoopGroup)
39-
.hostResolver(hostResolver)
40-
.buildWithDefaults(AttributeMap.builder().put(TRUST_ALL_CERTIFICATES, true).build());
41-
}
33+
return AwsCrtAsyncHttpClient.builder()
34+
.buildWithDefaults(AttributeMap.builder().put(TRUST_ALL_CERTIFICATES, true).build());
4235
}
4336

4437
}

http-clients/aws-crt-client/src/test/java/software/amazon/awssdk/http/crt/ProxyWireMockTest.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@
4848
public class ProxyWireMockTest {
4949
private SdkAsyncHttpClient client;
5050

51-
private EventLoopGroup eventLoopGroup;
52-
private HostResolver hostResolver;
53-
5451
private ProxyConfiguration proxyCfg;
5552

5653
private WireMockServer mockProxy = new WireMockServer(new WireMockConfiguration()
@@ -75,14 +72,7 @@ public void setup() {
7572
.port(mockProxy.port())
7673
.build();
7774

78-
79-
int numThreads = Runtime.getRuntime().availableProcessors();
80-
eventLoopGroup = new EventLoopGroup(numThreads);
81-
hostResolver = new HostResolver(eventLoopGroup);
82-
8375
client = AwsCrtAsyncHttpClient.builder()
84-
.eventLoopGroup(eventLoopGroup)
85-
.hostResolver(hostResolver)
8676
.proxyConfiguration(proxyCfg)
8777
.build();
8878
}
@@ -92,8 +82,8 @@ public void teardown() {
9282
mockServer.stop();
9383
mockProxy.stop();
9484
client.close();
95-
eventLoopGroup.close();
96-
hostResolver.close();
85+
EventLoopGroup.closeStaticDefault();
86+
HostResolver.closeStaticDefault();
9787
CrtResource.waitForNoResources();
9888
}
9989

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
<rxjava.version>2.1.9</rxjava.version>
109109
<commons-codec.verion>1.10</commons-codec.verion>
110110
<jmh.version>1.21</jmh.version>
111-
<awscrt.version>0.6.5</awscrt.version>
111+
<awscrt.version>0.8.2</awscrt.version>
112112

113113
<!-- Test dependencies -->
114114
<junit.version>4.12</junit.version>

test/sdk-benchmarks/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,6 @@
200200
<groupId>org.eclipse.jetty.http2</groupId>
201201
<artifactId>http2-hpack</artifactId>
202202
</dependency>
203-
<dependency>
204-
<groupId>software.amazon.awssdk.crt</groupId>
205-
<artifactId>aws-crt</artifactId>
206-
<version>${awscrt.version}</version>
207-
<scope>compile</scope>
208-
</dependency>
209203
<dependency>
210204
<groupId>software.amazon.awssdk</groupId>
211205
<artifactId>aws-crt-client</artifactId>

test/sdk-benchmarks/src/main/java/software/amazon/awssdk/benchmark/apicall/httpclient/async/BaseCrtBenchmark.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import org.openjdk.jmh.infra.Blackhole;
3131
import software.amazon.awssdk.benchmark.apicall.httpclient.SdkHttpClientBenchmark;
3232
import software.amazon.awssdk.benchmark.utils.MockServer;
33-
import software.amazon.awssdk.crt.io.EventLoopGroup;
34-
import software.amazon.awssdk.crt.io.HostResolver;
3533
import software.amazon.awssdk.http.SdkHttpConfigurationOption;
3634
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
3735
import software.amazon.awssdk.http.crt.AwsCrtAsyncHttpClient;
@@ -46,25 +44,17 @@ public abstract class BaseCrtBenchmark implements SdkHttpClientBenchmark {
4644
private MockServer mockServer;
4745
private SdkAsyncHttpClient sdkHttpClient;
4846
private ProtocolRestJsonAsyncClient client;
49-
private EventLoopGroup eventLoopGroup;
50-
private HostResolver hostResolver;
5147

5248
@Setup(Level.Trial)
5349
public void setup() throws Exception {
5450
mockServer = new MockServer();
5551
mockServer.start();
5652

57-
int numThreads = Runtime.getRuntime().availableProcessors();
58-
eventLoopGroup = new EventLoopGroup(numThreads);
59-
hostResolver = new HostResolver(eventLoopGroup);
60-
6153
AttributeMap trustAllCerts = AttributeMap.builder()
6254
.put(SdkHttpConfigurationOption.TRUST_ALL_CERTIFICATES, Boolean.TRUE)
6355
.build();
6456

6557
sdkHttpClient = AwsCrtAsyncHttpClient.builder()
66-
.eventLoopGroup(this.eventLoopGroup)
67-
.hostResolver(this.hostResolver)
6858
.buildWithDefaults(trustAllCerts);
6959

7060
client = ProtocolRestJsonAsyncClient.builder()
@@ -81,8 +71,6 @@ public void tearDown() throws Exception {
8171
mockServer.stop();
8272
client.close();
8373
sdkHttpClient.close();
84-
hostResolver.close();
85-
eventLoopGroup.close();
8674
}
8775

8876
@Override

0 commit comments

Comments
 (0)