Search in sources :

Example 1 with AmazonSyncHttpClient

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);
    }
}
Also used : ConnectionPoolTimeoutException(org.apache.http.conn.ConnectionPoolTimeoutException) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) SdkClientException(software.amazon.awssdk.core.exception.SdkClientException) AmazonSyncHttpClient(software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient) EmptySdkResponseHandler(software.amazon.awssdk.core.internal.http.response.EmptySdkResponseHandler) Test(org.junit.Test)

Example 2 with AmazonSyncHttpClient

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.
    }
}
Also used : SdkServiceException(software.amazon.awssdk.core.exception.SdkServiceException) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) AmazonSyncHttpClient(software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient)

Example 3 with AmazonSyncHttpClient

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)));
}
Also used : SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) AmazonSyncHttpClient(software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient) Test(org.junit.Test)

Example 4 with AmazonSyncHttpClient

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)));
}
Also used : SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) AmazonSyncHttpClient(software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient) Test(org.junit.Test)

Example 5 with AmazonSyncHttpClient

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"));
}
Also used : HttpExecuteRequest(software.amazon.awssdk.http.HttpExecuteRequest) SdkClientConfiguration(software.amazon.awssdk.core.client.config.SdkClientConfiguration) AmazonSyncHttpClient(software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient) Test(org.junit.Test)

Aggregations

AmazonSyncHttpClient (software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient)11 Test (org.junit.Test)10 SdkHttpFullRequest (software.amazon.awssdk.http.SdkHttpFullRequest)7 SdkClientConfiguration (software.amazon.awssdk.core.client.config.SdkClientConfiguration)4 HttpExecuteRequest (software.amazon.awssdk.http.HttpExecuteRequest)3 SdkClientException (software.amazon.awssdk.core.exception.SdkClientException)2 SdkServiceException (software.amazon.awssdk.core.exception.SdkServiceException)2 IOException (java.io.IOException)1 ConnectionPoolTimeoutException (org.apache.http.conn.ConnectionPoolTimeoutException)1 EmptySdkResponseHandler (software.amazon.awssdk.core.internal.http.response.EmptySdkResponseHandler)1 NullErrorResponseHandler (software.amazon.awssdk.core.internal.http.response.NullErrorResponseHandler)1