Skip to content

Upgrade Jetty (and some wiremock) version used for testing. #3055

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
Feb 24, 2022
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
69 changes: 61 additions & 8 deletions bom-internal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,6 @@
<version>${wiremock.version}</version>
<scope>test</scope>
</dependency>
<!-- Only use wiremock instead of wiremock-jre8 when working around bugs in the newer version -->
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>2.18.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down Expand Up @@ -410,11 +403,71 @@
<type>so</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-proxy</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-java-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-openjdk8-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-java-client</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-openjdk8-client</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.24</version>
</dependency>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
3 changes: 1 addition & 2 deletions http-clients/apache-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
<!-- Use wiremock instead of wiremock-jre8 because HEAD request handling doesn't work in the newer versions. -->
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<artifactId>wiremock-jre8</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
3 changes: 1 addition & 2 deletions http-clients/aws-crt-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@
</dependency>

<!--Test Dependencies-->
<!-- Use wiremock instead of wiremock-jre8 because HEAD request handling doesn't work in the newer versions. -->
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<artifactId>wiremock-jre8</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
3 changes: 1 addition & 2 deletions http-clients/netty-nio-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,9 @@
<version>${awsjavasdk.version}</version>
<scope>test</scope>
</dependency>
<!-- Use wiremock instead of wiremock-jre8 because HEAD request handling doesn't work in the newer versions. -->
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<artifactId>wiremock-jre8</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand All @@ -26,6 +27,9 @@
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import java.io.IOException;
import java.util.concurrent.CompletionException;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLHandshakeException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -172,13 +176,13 @@ public void proxyRequest_keyStoreSystemPropertiesConfigured_ableToAuthenticate()

@Test
public void nonProxy_noKeyManagerGiven_shouldThrowException() {
thrown.expectCause(instanceOf(IOException.class));
thrown.expectMessage("The connection was closed");

netty = NettyNioAsyncHttpClient.builder()
.buildWithDefaults(DEFAULTS);

HttpTestUtils.sendGetRequest(mockProxy.httpsPort(), netty).join();
assertThatThrownBy(() -> HttpTestUtils.sendGetRequest(mockProxy.httpsPort(), netty).join())
.isInstanceOf(CompletionException.class)
.hasMessageContaining("SSL")
.hasRootCauseInstanceOf(SSLException.class);
}

private void sendRequest(SdkAsyncHttpClient client, SdkAsyncHttpResponseHandler responseHandler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void onError(Throwable error) {

}

String fullResponseAsString() {
public String fullResponseAsString() {
return bodyParts.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,45 @@
package software.amazon.awssdk.http.nio.netty.internal;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;

import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.http.trafficlistener.WiremockNetworkTrafficListener;
import com.github.tomakehurst.wiremock.core.Options;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import java.net.URI;
import java.time.Duration;
import java.time.Instant;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.internal.verification.AtLeast;
import org.mockito.internal.verification.Times;
import org.mockito.junit.MockitoJUnitRunner;
import software.amazon.awssdk.http.ConnectionCountingTrafficListener;
import software.amazon.awssdk.http.EmptyPublisher;
import software.amazon.awssdk.http.SdkHttpConfigurationOption;
import software.amazon.awssdk.http.SdkHttpMethod;
import software.amazon.awssdk.http.SdkHttpRequest;
import software.amazon.awssdk.http.async.AsyncExecuteRequest;
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
import software.amazon.awssdk.http.EmptyPublisher;
import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
import software.amazon.awssdk.http.nio.netty.RecordingResponseHandler;

@RunWith(MockitoJUnitRunner.class)
public class ConnectionReaperTest {
private static final WiremockNetworkTrafficListener TRAFFIC_LISTENER = Mockito.mock(WiremockNetworkTrafficListener.class);
private static final ConnectionCountingTrafficListener TRAFFIC_LISTENER = new ConnectionCountingTrafficListener();

@Rule
public final WireMockRule mockServer = new WireMockRule(wireMockConfig().dynamicPort()
.dynamicHttpsPort()
.networkTrafficListener(TRAFFIC_LISTENER));

@Before
public void methodSetup() {
reset(TRAFFIC_LISTENER);
}

@Test
public void idleConnectionReaperDoesNotReapActiveConnections() throws InterruptedException {
Duration maxIdleTime = Duration.ofSeconds(2);
Expand All @@ -71,16 +65,19 @@ public void idleConnectionReaperDoesNotReapActiveConnections() throws Interrupte
Instant end = Instant.now().plus(maxIdleTime.plusSeconds(1));

// Send requests for longer than the max-idle time, ensuring no connections are closed.
int connectionCount = TRAFFIC_LISTENER.openedConnections();
while (Instant.now().isBefore(end)) {
makeRequest(client);
Thread.sleep(100);
verify(TRAFFIC_LISTENER, new Times(0)).closed(any());
}

assertThat(TRAFFIC_LISTENER.openedConnections()).isEqualTo(connectionCount + 1);

// Do nothing for longer than the max-idle time, ensuring connections are closed.
Thread.sleep(maxIdleTime.plusSeconds(1).toMillis());

verify(TRAFFIC_LISTENER, new AtLeast(1)).closed(any());
makeRequest(client);
assertThat(TRAFFIC_LISTENER.openedConnections()).isEqualTo(connectionCount + 2);
}

}
Expand All @@ -95,15 +92,15 @@ public void oldConnectionReaperReapsActiveConnections() throws InterruptedExcept

Instant end = Instant.now().plus(Duration.ofSeconds(5));

verify(TRAFFIC_LISTENER, new Times(0)).closed(any());
int connectionCount = TRAFFIC_LISTENER.openedConnections();

// Send requests frequently, validating that connections are still being closed.
// Send requests frequently, validating that new connections are being opened.
while (Instant.now().isBefore(end)) {
makeRequest(client);
Thread.sleep(100);
}

verify(TRAFFIC_LISTENER, new AtLeast(20)).closed(any());
assertThat(TRAFFIC_LISTENER.openedConnections()).isGreaterThanOrEqualTo(connectionCount + 15);
}
}

Expand All @@ -115,18 +112,19 @@ public void noReapingWorks() throws InterruptedException {
.buildWithDefaults(SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS)) {


verify(TRAFFIC_LISTENER, new Times(0)).closed(any());
int connectionCount = TRAFFIC_LISTENER.openedConnections();
makeRequest(client);

Thread.sleep(2_000);

verify(TRAFFIC_LISTENER, new Times(0)).closed(any());
makeRequest(client);
assertThat(TRAFFIC_LISTENER.openedConnections()).isEqualTo(connectionCount + 1);
}
}


private void makeRequest(SdkAsyncHttpClient client) {
stubFor(WireMock.any(urlPathEqualTo("/")).willReturn(aResponse().withBody(randomAlphabetic(10))));
stubFor(WireMock.any(anyUrl()).willReturn(aResponse().withBody(randomAlphabetic(10))));

RecordingResponseHandler handler = new RecordingResponseHandler();

URI uri = URI.create("http://localhost:" + mockServer.port());
client.execute(AsyncExecuteRequest.builder()
Expand All @@ -135,11 +133,14 @@ private void makeRequest(SdkAsyncHttpClient client) {
.method(SdkHttpMethod.GET)
.encodedPath("/")
.putHeader("Host", uri.getHost())
.putHeader("Content-Length", "0")
.build())
.requestContentPublisher(new EmptyPublisher())
.responseHandler(new RecordingResponseHandler())
.responseHandler(handler)
.build())
.join();

assertThat(handler.fullResponseAsString()).hasSize(10);
}

}
1 change: 0 additions & 1 deletion http-clients/url-connection-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.2.24.v20180105</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<dynamodb-local.version>1.16.0</dynamodb-local.version>
<sqllite.version>1.0.392</sqllite.version>
<blockhound.version>1.0.6.RELEASE</blockhound.version>
<jetty.version>9.4.45.v20220203</jetty.version>

<!-- build plugin dependencies-->
<maven.surefire.version>3.0.0-M5</maven.surefire.version>
Expand Down
3 changes: 1 addition & 2 deletions test/http-client-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@
<artifactId>mockito-core</artifactId>
<scope>compile</scope>
</dependency>
<!-- Use wiremock instead of wiremock-jre8 because HEAD request handling doesn't work in the newer versions. -->
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<artifactId>wiremock-jre8</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Loading