Skip to content

Commit 698364c

Browse files
committed
Remove CrtResource Dependency injection
1 parent 498b103 commit 698364c

File tree

6 files changed

+90
-197
lines changed

6 files changed

+90
-197
lines changed

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

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
import org.junit.Test;
1212
import software.amazon.awssdk.core.SdkBytes;
1313
import software.amazon.awssdk.crt.CrtResource;
14-
import software.amazon.awssdk.crt.io.ClientBootstrap;
15-
import software.amazon.awssdk.crt.io.SocketOptions;
1614
import software.amazon.awssdk.crt.io.TlsCipherPreference;
17-
import software.amazon.awssdk.crt.io.TlsContext;
1815
import software.amazon.awssdk.crt.io.TlsContextOptions;
1916
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
2017
import software.amazon.awssdk.regions.Region;
@@ -36,12 +33,6 @@ public class AwsCrtClientKmsIntegrationTest {
3633
private static Region REGION = Region.US_EAST_1;
3734
private static List<SdkAsyncHttpClient> awsCrtHttpClients = new ArrayList<>();
3835

39-
List<CrtResource> crtResources = new ArrayList<>();
40-
41-
private void addResource(CrtResource resource) {
42-
crtResources.add(resource);
43-
}
44-
4536
@Before
4637
public void setup() {
4738
Assert.assertEquals("Expected Zero allocated AwsCrtResources", 0, CrtResource.getAllocatedNativeResourceCount());
@@ -52,33 +43,18 @@ public void setup() {
5243
continue;
5344
}
5445

55-
ClientBootstrap bootstrap = new ClientBootstrap(1);
56-
SocketOptions socketOptions = new SocketOptions();
57-
TlsContext tlsContext = new TlsContext();
58-
59-
addResource(bootstrap);
60-
addResource(socketOptions);
61-
addResource(tlsContext);
6246

6347
SdkAsyncHttpClient awsCrtHttpClient = AwsCrtAsyncHttpClient.builder()
64-
.bootstrap(bootstrap)
65-
.socketOptions(socketOptions)
66-
.tlsContext(tlsContext)
48+
.eventLoopSize(1)
6749
.build();
6850

6951
awsCrtHttpClients.add(awsCrtHttpClient);
7052
}
7153
}
7254

73-
private void closeResources() {
74-
for (CrtResource r: crtResources) {
75-
r.close();
76-
}
77-
}
7855

7956
@After
8057
public void tearDown() {
81-
closeResources();
8258
Assert.assertEquals("Expected Zero allocated AwsCrtResources", 0, CrtResource.getAllocatedNativeResourceCount());
8359
}
8460

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

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
import software.amazon.awssdk.core.ResponseBytes;
3131
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
3232
import software.amazon.awssdk.crt.CrtResource;
33-
import software.amazon.awssdk.crt.io.ClientBootstrap;
34-
import software.amazon.awssdk.crt.io.SocketOptions;
35-
import software.amazon.awssdk.crt.io.TlsContext;
3633
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
3734
import software.amazon.awssdk.regions.Region;
3835
import software.amazon.awssdk.services.s3.S3AsyncClient;
@@ -57,28 +54,12 @@ public class AwsCrtClientS3IntegrationTest {
5754

5855
private static S3AsyncClient s3;
5956

60-
List<CrtResource> crtResources = new ArrayList<>();
61-
62-
private void addResource(CrtResource resource) {
63-
crtResources.add(resource);
64-
}
65-
6657
@Before
6758
public void setup() {
6859
Assert.assertEquals("Expected Zero allocated AwsCrtResources", 0, CrtResource.getAllocatedNativeResourceCount());
6960

70-
ClientBootstrap bootstrap = new ClientBootstrap(4);
71-
SocketOptions socketOptions = new SocketOptions();
72-
TlsContext tlsContext = new TlsContext();
73-
74-
addResource(bootstrap);
75-
addResource(socketOptions);
76-
addResource(tlsContext);
77-
7861
crtClient = AwsCrtAsyncHttpClient.builder()
79-
.bootstrap(bootstrap)
80-
.socketOptions(socketOptions)
81-
.tlsContext(tlsContext)
62+
.eventLoopSize(4)
8263
.build();
8364

8465
s3 = S3AsyncClient.builder()
@@ -93,10 +74,6 @@ public void tearDown() {
9374
s3.close();
9475
crtClient.close();
9576

96-
for (CrtResource r: crtResources) {
97-
r.close();
98-
}
99-
10077
Assert.assertEquals("Expected Zero allocated AwsCrtResources", 0, CrtResource.getAllocatedNativeResourceCount());
10178
}
10279

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

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232
import org.junit.experimental.theories.Theory;
3333
import org.junit.runner.RunWith;
3434
import software.amazon.awssdk.crt.CrtResource;
35-
import software.amazon.awssdk.crt.io.ClientBootstrap;
36-
import software.amazon.awssdk.crt.io.SocketOptions;
37-
import software.amazon.awssdk.crt.io.TlsContext;
38-
import software.amazon.awssdk.crt.io.TlsContextOptions;
3935
import software.amazon.awssdk.http.SdkHttpConfigurationOption;
4036
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
4137
import software.amazon.awssdk.regions.Region;
@@ -45,10 +41,9 @@
4541
import software.amazon.awssdk.utils.AttributeMap;
4642

4743
@RunWith(Theories.class)
48-
public class AwsCrtCombinatorialConfigStressIntegrationTest {
44+
public class AwsCrtCombinatorialConfigStressIntegrationTest {
4945
private final static String KEY_ALIAS = "alias/aws-sdk-java-v2-integ-test";
5046
private final static Region REGION = Region.US_EAST_1;
51-
private final static List<SdkAsyncHttpClient> awsCrtHttpClients = new ArrayList<>();
5247
private final static int DEFAULT_KEY_SIZE = 32;
5348

5449
// Success rate will currently never go above ~99% due to aws-c-http not detecting connection close headers, and KMS
@@ -98,26 +93,16 @@ private boolean testWithClient(KmsAsyncClient asyncKMSClient, int numberOfReques
9893
}
9994

10095
private boolean testWithNewClient(int eventLoopSize, int numberOfRequests) {
101-
try (ClientBootstrap newBootstrap = new ClientBootstrap(eventLoopSize)) {
102-
try (SocketOptions newSocketOptions = new SocketOptions()) {
103-
try (TlsContextOptions newContextOptions = new TlsContextOptions()) {
104-
try (TlsContext newTlsContext = new TlsContext(newContextOptions)) {
105-
try (SdkAsyncHttpClient newAwsCrtHttpClient = AwsCrtAsyncHttpClient.builder()
106-
.bootstrap(newBootstrap)
107-
.socketOptions(newSocketOptions)
108-
.tlsContext(newTlsContext)
109-
.build()) {
110-
try (KmsAsyncClient newAsyncKMSClient = KmsAsyncClient.builder()
111-
.region(REGION)
112-
.httpClient(newAwsCrtHttpClient)
113-
.credentialsProvider(CREDENTIALS_PROVIDER_CHAIN)
114-
.build()) {
115-
boolean succeeded = testWithClient(newAsyncKMSClient, numberOfRequests);
116-
return succeeded;
117-
}
118-
}
119-
}
120-
}
96+
try (SdkAsyncHttpClient newAwsCrtHttpClient = AwsCrtAsyncHttpClient.builder()
97+
.eventLoopSize(eventLoopSize)
98+
.build()) {
99+
try (KmsAsyncClient newAsyncKMSClient = KmsAsyncClient.builder()
100+
.region(REGION)
101+
.httpClient(newAwsCrtHttpClient)
102+
.credentialsProvider(CREDENTIALS_PROVIDER_CHAIN)
103+
.build()) {
104+
boolean succeeded = testWithClient(newAsyncKMSClient, numberOfRequests);
105+
return succeeded;
121106
}
122107
}
123108
}
@@ -172,13 +157,9 @@ public void checkAllCombinations(@FromDataPoints("EventLoop") int eventLoopSize,
172157
.put(SdkHttpConfigurationOption.MAX_CONNECTIONS, connectionPoolSize)
173158
.build();
174159

175-
ClientBootstrap bootstrap = new ClientBootstrap(eventLoopSize);
176-
SocketOptions socketOptions = new SocketOptions();
177-
TlsContext tlsContext = new TlsContext();
160+
178161
SdkAsyncHttpClient awsCrtHttpClient = AwsCrtAsyncHttpClient.builder()
179-
.bootstrap(bootstrap)
180-
.socketOptions(socketOptions)
181-
.tlsContext(tlsContext)
162+
.eventLoopSize(eventLoopSize)
182163
.buildWithDefaults(attributes);
183164

184165
KmsAsyncClient sharedAsyncKMSClient = KmsAsyncClient.builder()
@@ -212,10 +193,6 @@ public void checkAllCombinations(@FromDataPoints("EventLoop") int eventLoopSize,
212193

213194
sharedAsyncKMSClient.close();
214195
awsCrtHttpClient.close();
215-
tlsContext.close();
216-
socketOptions.close();
217-
bootstrap.close();
218-
219196
Assert.assertFalse(failed.get());
220197

221198
if (CrtResource.getAllocatedNativeResourceCount() > 0) {

0 commit comments

Comments
 (0)