Skip to content

Update to 0.3.35 of the CRT with minor API changes #1485

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
Nov 1, 2019
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/bugfix-AWSSDKforJavav2-9a322a2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"category": "AWS Common Runtime Client",
"type": "bugfix",
"description": "Upgrade to the latest version (0.3.35) of the AWS Common Runtime."
}
4 changes: 2 additions & 2 deletions http-clients/aws-crt-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<dependency>
<groupId>software.amazon.awssdk.crt</groupId>
<artifactId>aws-crt</artifactId>
<version>0.3.22</version>
<version>0.3.35</version>
</dependency>

<!--SDK dependencies-->
Expand Down Expand Up @@ -186,4 +186,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,8 @@ public void checkAllCombinations(@FromDataPoints("EventLoop") int eventLoopSize,
@FromDataPoints("SharedClient") boolean useSharedClient) throws Exception {

try {
if (CrtResource.getAllocatedNativeResourceCount() > 0) {
System.err.println("Leaked Resources: " + String.join(", ", CrtResource.getAllocatedNativeResources()));
}
Assert.assertEquals("Expected Zero allocated AwsCrtResources", 0, CrtResource.getAllocatedNativeResourceCount());

CrtResource.waitForNoResources();
String testName = String.format("Testing with eventLoopSize %d, connectionPoolSize %d, numberOfRequests %d, " +
"numberOfParallelJavaClients %d, useSharedClient %b", eventLoopSize, connectionPoolSize,
numberOfRequests, numberOfParallelClients, useSharedClient);
Expand Down Expand Up @@ -197,11 +194,7 @@ public void checkAllCombinations(@FromDataPoints("EventLoop") int eventLoopSize,
awsCrtHttpClient.close();
Assert.assertFalse(failed.get());

if (CrtResource.getAllocatedNativeResourceCount() > 0) {
System.err.println("Leaked Resources: " + String.join(", ", CrtResource.getAllocatedNativeResources()));
}

Assert.assertEquals("Expected Zero allocated AwsCrtResources", 0, CrtResource.getAllocatedNativeResourceCount());
CrtResource.waitForNoResources();

float numSeconds = (float) ((System.currentTimeMillis() - start) / 1000.0);
String timeElapsed = String.format("%.2f sec", numSeconds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class AwsCrtClientKmsIntegrationTest {

@Before
public void setup() {
Assert.assertEquals("Expected Zero allocated AwsCrtResources", 0, CrtResource.getAllocatedNativeResourceCount());
CrtResource.waitForNoResources();

// Create an Http Client for each TLS Cipher Preference supported on the current platform
for (TlsCipherPreference pref: TlsCipherPreference.values()) {
Expand All @@ -55,7 +55,7 @@ public void setup() {

@After
public void tearDown() {
Assert.assertEquals("Expected Zero allocated AwsCrtResources", 0, CrtResource.getAllocatedNativeResourceCount());
CrtResource.waitForNoResources();
}

private boolean doesKeyExist(KmsAsyncClient kms, String keyAlias) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class AwsCrtClientS3IntegrationTest {

@Before
public void setup() {
Assert.assertEquals("Expected Zero allocated AwsCrtResources", 0, CrtResource.getAllocatedNativeResourceCount());
CrtResource.waitForNoResources();

crtClient = AwsCrtAsyncHttpClient.builder()
.eventLoopSize(4)
Expand All @@ -74,7 +74,7 @@ public void tearDown() {
s3.close();
crtClient.close();

Assert.assertEquals("Expected Zero allocated AwsCrtResources", 0, CrtResource.getAllocatedNativeResourceCount());
CrtResource.waitForNoResources();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import software.amazon.awssdk.annotations.SdkPublicApi;
import software.amazon.awssdk.crt.CrtResource;
import software.amazon.awssdk.crt.http.HttpConnectionPoolManager;
import software.amazon.awssdk.crt.http.HttpClientConnectionManager;
import software.amazon.awssdk.crt.http.HttpHeader;
import software.amazon.awssdk.crt.http.HttpRequest;
import software.amazon.awssdk.crt.io.ClientBootstrap;
Expand Down Expand Up @@ -65,7 +65,7 @@ public class AwsCrtAsyncHttpClient implements SdkAsyncHttpClient {
private static final String AWS_COMMON_RUNTIME = "AwsCommonRuntime";
private static final int DEFAULT_STREAM_WINDOW_SIZE = 16 * 1024 * 1024; // 16 MB

private final Map<URI, HttpConnectionPoolManager> connectionPools = new ConcurrentHashMap<>();
private final Map<URI, HttpClientConnectionManager> connectionPools = new ConcurrentHashMap<>();
private final LinkedList<CrtResource> ownedSubResources = new LinkedList<>();
private final AtomicBoolean isClosed = new AtomicBoolean(false);
private final ClientBootstrap bootstrap;
Expand Down Expand Up @@ -95,7 +95,7 @@ public AwsCrtAsyncHttpClient(DefaultBuilder builder, AttributeMap config) {

bootstrap = own(new ClientBootstrap(builder.eventLoopSize));
socketOptions = own(new SocketOptions());
tlsContextOptions = own(new TlsContextOptions().withCipherPreference(builder.cipherPreference));
tlsContextOptions = own(TlsContextOptions.createDefaultClient().withCipherPreference(builder.cipherPreference));
tlsContextOptions.setVerifyPeer(builder.verifyPeer);
tlsContext = own(new TlsContext(tlsContextOptions));

Expand Down Expand Up @@ -131,22 +131,22 @@ public String clientName() {
return AWS_COMMON_RUNTIME;
}

private HttpConnectionPoolManager createConnectionPool(URI uri) {
private HttpClientConnectionManager createConnectionPool(URI uri) {
Validate.notNull(uri, "URI must not be null");
log.debug(() -> "Creating ConnectionPool for: URI:" + uri + ", MaxConns: " + maxConnectionsPerEndpoint);

return new HttpConnectionPoolManager(bootstrap, socketOptions, tlsContext, uri,
HttpConnectionPoolManager.DEFAULT_MAX_BUFFER_SIZE, windowSize,
return new HttpClientConnectionManager(bootstrap, socketOptions, tlsContext, uri,
HttpClientConnectionManager.DEFAULT_MAX_BUFFER_SIZE, windowSize,
maxConnectionsPerEndpoint);
}

private HttpConnectionPoolManager getOrCreateConnectionPool(URI uri) {
private HttpClientConnectionManager getOrCreateConnectionPool(URI uri) {
Validate.notNull(uri, "URI must not be null");
HttpConnectionPoolManager connPool = connectionPools.get(uri);
HttpClientConnectionManager connPool = connectionPools.get(uri);

if (connPool == null) {
HttpConnectionPoolManager newConnPool = createConnectionPool(uri);
HttpConnectionPoolManager alreadyExistingConnPool = connectionPools.putIfAbsent(uri, newConnPool);
HttpClientConnectionManager newConnPool = createConnectionPool(uri);
HttpClientConnectionManager alreadyExistingConnPool = connectionPools.putIfAbsent(uri, newConnPool);

if (alreadyExistingConnPool == null) {
connPool = newConnPool;
Expand Down Expand Up @@ -222,7 +222,7 @@ public CompletableFuture<Void> execute(AsyncExecuteRequest asyncRequest) {
Validate.notNull(asyncRequest.responseHandler(), "ResponseHandler must not be null");

URI uri = toUri(asyncRequest.request());
HttpConnectionPoolManager crtConnPool = getOrCreateConnectionPool(uri);
HttpClientConnectionManager crtConnPool = getOrCreateConnectionPool(uri);
HttpRequest crtRequest = toCrtRequest(uri, asyncRequest);

CompletableFuture<Void> requestFuture = new CompletableFuture<>();
Expand All @@ -249,7 +249,7 @@ public CompletableFuture<Void> execute(AsyncExecuteRequest asyncRequest) {
@Override
public void close() {
isClosed.set(true);
for (HttpConnectionPoolManager connPool : connectionPools.values()) {
for (HttpClientConnectionManager connPool : connectionPools.values()) {
IoUtils.closeQuietly(connPool, log.logger());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.crt.CRT;
import software.amazon.awssdk.crt.http.CrtHttpStreamHandler;
import software.amazon.awssdk.crt.http.HttpConnection;
import software.amazon.awssdk.crt.http.HttpClientConnection;
import software.amazon.awssdk.crt.http.HttpException;
import software.amazon.awssdk.crt.http.HttpHeader;
import software.amazon.awssdk.crt.http.HttpStream;
Expand All @@ -38,15 +38,15 @@
public class AwsCrtAsyncHttpStreamAdapter implements CrtHttpStreamHandler {
private static final Logger log = Logger.loggerFor(AwsCrtAsyncHttpStreamAdapter.class);

private final HttpConnection connection;
private final HttpClientConnection connection;
private final CompletableFuture<Void> responseComplete;
private final AsyncExecuteRequest sdkRequest;
private final SdkHttpResponse.Builder respBuilder = SdkHttpResponse.builder();
private final int windowSize;
private final AwsCrtRequestBodySubscriber requestBodySubscriber;
private AwsCrtResponseBodyPublisher respBodyPublisher = null;

public AwsCrtAsyncHttpStreamAdapter(HttpConnection connection, CompletableFuture<Void> responseComplete,
public AwsCrtAsyncHttpStreamAdapter(HttpClientConnection connection, CompletableFuture<Void> responseComplete,
AsyncExecuteRequest sdkRequest, int windowSize) {
Validate.notNull(connection, "HttpConnection is null");
Validate.notNull(responseComplete, "reqComplete Future is null");
Expand All @@ -69,7 +69,7 @@ private void initRespBodyPublisherIfNeeded(HttpStream stream) {
}

@Override
public void onResponseHeaders(HttpStream stream, int responseStatusCode, HttpHeader[] nextHeaders) {
public void onResponseHeaders(HttpStream stream, int responseStatusCode, int blockType, HttpHeader[] nextHeaders) {
initRespBodyPublisherIfNeeded(stream);

respBuilder.statusCode(responseStatusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.crt.http.HttpConnection;
import software.amazon.awssdk.crt.http.HttpClientConnection;
import software.amazon.awssdk.crt.http.HttpStream;
import software.amazon.awssdk.utils.Logger;
import software.amazon.awssdk.utils.Validate;
Expand All @@ -41,7 +41,7 @@ public class AwsCrtResponseBodyPublisher implements Publisher<ByteBuffer> {
private static final Logger log = Logger.loggerFor(AwsCrtResponseBodyPublisher.class);
private static final LongUnaryOperator DECREMENT_IF_GREATER_THAN_ZERO = x -> ((x > 0) ? (x - 1) : (x));

private final HttpConnection connection;
private final HttpClientConnection connection;
private final HttpStream stream;
private final CompletableFuture<Void> responseComplete;
private final AtomicLong outstandingRequests = new AtomicLong(0);
Expand All @@ -62,7 +62,7 @@ public class AwsCrtResponseBodyPublisher implements Publisher<ByteBuffer> {
* @param windowSize The max allowed bytes to be queued. The sum of the sizes of all queued ByteBuffers should
* never exceed this value.
*/
public AwsCrtResponseBodyPublisher(HttpConnection connection, HttpStream stream,
public AwsCrtResponseBodyPublisher(HttpClientConnection connection, HttpStream stream,
CompletableFuture<Void> responseComplete, int windowSize) {
Validate.notNull(connection, "HttpConnection must not be null");
Validate.notNull(stream, "Stream must not be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class AwsCrtHttpClientSpiVerificationTest {

@Before
public void setup() throws Exception {
Assert.assertEquals("Expected Zero allocated AwsCrtResources", 0, CrtResource.getAllocatedNativeResourceCount());
CrtResource.waitForNoResources();

client = AwsCrtAsyncHttpClient.builder()
.build();
Expand All @@ -77,7 +77,7 @@ public void setup() throws Exception {
@After
public void tearDown() {
client.close();
Assert.assertEquals("Expected Zero allocated AwsCrtResources", 0, CrtResource.getAllocatedNativeResourceCount());
CrtResource.waitForNoResources();
}

private byte[] generateRandomBody(int size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.reactivestreams.Publisher;
import org.reactivestreams.tck.PublisherVerification;
import org.reactivestreams.tck.TestEnvironment;
import software.amazon.awssdk.crt.http.HttpConnection;
import software.amazon.awssdk.crt.http.HttpClientConnection;
import software.amazon.awssdk.crt.http.HttpStream;
import software.amazon.awssdk.http.crt.internal.AwsCrtResponseBodyPublisher;
import software.amazon.awssdk.utils.Logger;
Expand All @@ -37,7 +37,7 @@ public AwsCrtResponseBodyPublisherReactiveStreamCompatTest() {

@Override
public Publisher<ByteBuffer> createPublisher(long elements) {
HttpConnection connection = mock(HttpConnection.class);
HttpClientConnection connection = mock(HttpClientConnection.class);
HttpStream stream = mock(HttpStream.class);
AwsCrtResponseBodyPublisher bodyPublisher = new AwsCrtResponseBodyPublisher(connection, stream, new CompletableFuture<>(), Integer.MAX_VALUE);

Expand Down
2 changes: 1 addition & 1 deletion test/sdk-benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
<dependency>
<groupId>software.amazon.awssdk.crt</groupId>
<artifactId>aws-crt</artifactId>
<version>0.3.22</version>
<version>0.3.35</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down