use of software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient in project aws-sdk-java-v2 by aws.
the class ConnectionPoolMaxConnectionsIntegrationTest method leasing_a_new_connection_fails_with_connection_pool_timeout.
@Test(timeout = 60 * 1000)
public void leasing_a_new_connection_fails_with_connection_pool_timeout() {
AmazonSyncHttpClient httpClient = HttpTestUtils.testClientBuilder().retryPolicy(RetryPolicy.none()).httpClient(ApacheHttpClient.builder().connectionTimeout(Duration.ofMillis(100)).maxConnections(1).build()).build();
SdkHttpFullRequest request = server.configureHttpEndpoint(SdkHttpFullRequest.builder()).method(SdkHttpMethod.GET).build();
// Block the first connection in the pool with this request.
httpClient.requestExecutionBuilder().request(request).originalRequest(NoopTestRequest.builder().build()).executionContext(executionContext(request)).execute(combinedSyncResponseHandler(new EmptySdkResponseHandler(), null));
try {
// A new connection will be leased here which would fail in
// ConnectionPoolTimeoutException.
httpClient.requestExecutionBuilder().request(request).originalRequest(NoopTestRequest.builder().build()).executionContext(executionContext(request)).execute(combinedSyncResponseHandler(null, null));
Assert.fail("Connection pool timeout exception is expected!");
} catch (SdkClientException e) {
Assert.assertTrue(e.getCause() instanceof ConnectionPoolTimeoutException);
}
}
use of software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient in project aws-sdk-java-v2 by aws.
the class SdkTransactionIdInHeaderTest method executeRequest.
private void executeRequest() throws Exception {
AmazonSyncHttpClient httpClient = HttpTestUtils.testAmazonHttpClient();
try {
SdkHttpFullRequest request = newGetRequest(RESOURCE_PATH).build();
httpClient.requestExecutionBuilder().request(request).originalRequest(NoopTestRequest.builder().build()).executionContext(ClientExecutionAndRequestTimerTestUtils.executionContext(request)).execute(combinedSyncResponseHandler(null, stubErrorHandler()));
fail("Expected exception");
} catch (SdkServiceException expected) {
// Ignored or expected.
}
}
use of software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient in project aws-sdk-java-v2 by aws.
the class AmazonHttpClientWireMockTest method headersSpecifiedInClientConfigurationArePutOnRequest.
@Test
public void headersSpecifiedInClientConfigurationArePutOnRequest() {
SdkHttpFullRequest request = newGetRequest(OPERATION).build();
AmazonSyncHttpClient sut = createClient(HEADER, CONFIG_HEADER_VALUE);
sendRequest(request, sut);
verify(getRequestedFor(urlPathEqualTo(OPERATION)).withHeader(HEADER, matching(CONFIG_HEADER_VALUE)));
}
use of software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient in project aws-sdk-java-v2 by aws.
the class AmazonHttpClientWireMockTest method headersOnRequestsWinOverClientConfigurationHeaders.
@Test
public void headersOnRequestsWinOverClientConfigurationHeaders() {
SdkHttpFullRequest request = newGetRequest(OPERATION).putHeader(HEADER, REQUEST_HEADER_VALUE).build();
AmazonSyncHttpClient sut = createClient(HEADER, CONFIG_HEADER_VALUE);
sendRequest(request, sut);
verify(getRequestedFor(urlPathEqualTo(OPERATION)).withHeader(HEADER, matching(REQUEST_HEADER_VALUE)));
}
use of software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient in project aws-sdk-java-v2 by aws.
the class AmazonHttpClientTest method testUserAgentContainsRetryModeInfo.
@Test
public void testUserAgentContainsRetryModeInfo() {
HttpResponseHandler<?> handler = mock(HttpResponseHandler.class);
SdkClientConfiguration config = HttpTestUtils.testClientConfiguration().toBuilder().option(SdkClientOption.SYNC_HTTP_CLIENT, sdkHttpClient).option(SdkClientOption.CLIENT_TYPE, ClientType.SYNC).option(SdkClientOption.ENDPOINT, URI.create("http://example.com")).option(SdkClientOption.RETRY_POLICY, RetryPolicy.forRetryMode(RetryMode.STANDARD)).build();
AmazonSyncHttpClient client = new AmazonSyncHttpClient(config);
client.requestExecutionBuilder().request(ValidSdkObjects.sdkHttpFullRequest().build()).originalRequest(NoopTestRequest.builder().build()).executionContext(ClientExecutionAndRequestTimerTestUtils.executionContext(null)).execute(combinedSyncResponseHandler(handler, null));
ArgumentCaptor<HttpExecuteRequest> httpRequestCaptor = ArgumentCaptor.forClass(HttpExecuteRequest.class);
verify(sdkHttpClient).prepareRequest(httpRequestCaptor.capture());
final String userAgent = httpRequestCaptor.getValue().httpRequest().firstMatchingHeader("User-Agent").orElseThrow(() -> new AssertionError("User-Agent header was not found"));
Assert.assertTrue(userAgent.contains("cfg/retry-mode/standard"));
}
Aggregations