com.amazonaws.http.apache.client.impl.ConnectionManagerAwareHttpClient

Here are the examples of the java api class com.amazonaws.http.apache.client.impl.ConnectionManagerAwareHttpClient taken from open source projects.

1. OverloadServerTests#requestTimeoutEnabled_HonorsRetryPolicy()

Project: aws-sdk-java
File: OverloadServerTests.java
@Test(timeout = TEST_TIMEOUT)
public void requestTimeoutEnabled_HonorsRetryPolicy() throws IOException {
    int maxRetries = 2;
    ClientConfiguration config = new ClientConfiguration().withRequestTimeout(1 * 1000).withMaxErrorRetry(maxRetries);
    HttpClientFactory<ConnectionManagerAwareHttpClient> httpClientFactory = new ApacheHttpClientFactory();
    ConnectionManagerAwareHttpClient rawHttpClient = spy(httpClientFactory.create(HttpClientSettings.adapt(config)));
    httpClient = new AmazonHttpClient(config, rawHttpClient, null);
    try {
        execute(httpClient, newGetRequest());
        fail("Exception expected");
    } catch (AmazonClientException e) {
        assertThat(e.getCause(), instanceOf(HttpRequestTimeoutException.class));
        int expectedNumberOfRequests = 1 + maxRetries;
        assertNumberOfRetries(rawHttpClient, expectedNumberOfRequests);
        assertNumberOfTasksTriggered(httpClient.getHttpRequestTimer(), expectedNumberOfRequests);
    }
}

2. MockedClientTests#requestTimeoutEnabled_RequestCompletesWithinTimeout_EntityNotBufferedForStreamedResponse()

Project: aws-sdk-java
File: MockedClientTests.java
@Test
public void requestTimeoutEnabled_RequestCompletesWithinTimeout_EntityNotBufferedForStreamedResponse() throws Exception {
    ClientConfiguration config = new ClientConfiguration().withRequestTimeout(5 * 1000);
    ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config);
    HttpResponseProxy responseProxy = createHttpResponseProxySpy();
    doReturn(responseProxy).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class));
    httpClient = new AmazonHttpClient(config, rawHttpClient, null);
    try {
        httpClient.execute(createMockGetRequest(), new NullResponseHandler() {

            @Override
            public boolean needsConnectionLeftOpen() {
                // Streaming operation
                return true;
            }
        }, new NullErrorResponseHandler(), new ExecutionContext());
        fail("Exception expected");
    } catch (AmazonClientException e) {
    }
    assertResponseWasNotBuffered(responseProxy);
}

3. MockedClientTests#requestTimeoutDisabled_RequestCompletesWithinTimeout_EntityNotBuffered()

Project: aws-sdk-java
File: MockedClientTests.java
@Test
public void requestTimeoutDisabled_RequestCompletesWithinTimeout_EntityNotBuffered() throws Exception {
    ClientConfiguration config = new ClientConfiguration().withRequestTimeout(0);
    ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config);
    HttpResponseProxy responseProxy = createHttpResponseProxySpy();
    doReturn(responseProxy).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class));
    httpClient = new AmazonHttpClient(config, rawHttpClient, null);
    try {
        execute(httpClient, createMockGetRequest());
        fail("Exception expected");
    } catch (AmazonClientException e) {
    }
    assertResponseWasNotBuffered(responseProxy);
}

4. MockedClientTests#requestTimeoutEnabled_HeadRequestCompletesWithinTimeout_EntityNotBuffered()

Project: aws-sdk-java
File: MockedClientTests.java
/**
     * Response to HEAD requests don't have an entity so we shouldn't try to wrap the response in a
     * {@link BufferedHttpEntity}.
     */
@Test
public void requestTimeoutEnabled_HeadRequestCompletesWithinTimeout_EntityNotBuffered() throws Exception {
    ClientConfiguration config = new ClientConfiguration().withRequestTimeout(5 * 1000).withMaxErrorRetry(0);
    ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config);
    HttpResponseProxy responseProxy = createHttpHeadResponseProxy();
    doReturn(responseProxy).when(rawHttpClient).execute(any(HttpHead.class), any(HttpContext.class));
    httpClient = new AmazonHttpClient(config, rawHttpClient, null);
    try {
        execute(httpClient, createMockHeadRequest());
        fail("Exception expected");
    } catch (AmazonClientException e) {
        NullResponseHandler.assertIsUnmarshallingException(e);
    }
    assertNull(responseProxy.getEntity());
}

5. DummyResponseServerTests#requestTimeoutEnabled_ServerRespondsWithRetryableError_RetriesUpToLimitThenThrowsServerException()

Project: aws-sdk-java
File: DummyResponseServerTests.java
@Test(timeout = TEST_TIMEOUT)
public void requestTimeoutEnabled_ServerRespondsWithRetryableError_RetriesUpToLimitThenThrowsServerException() throws IOException {
    int maxRetries = 2;
    ClientConfiguration config = new ClientConfiguration().withRequestTimeout(25 * 1000).withClientExecutionTimeout(25 * 1000).withMaxErrorRetry(maxRetries);
    HttpClientFactory<ConnectionManagerAwareHttpClient> httpClientFactory = new ApacheHttpClientFactory();
    ConnectionManagerAwareHttpClient rawHttpClient = spy(httpClientFactory.create(HttpClientSettings.adapt(config)));
    httpClient = new AmazonHttpClient(config, rawHttpClient, null);
    try {
        execute(httpClient, newGetRequest());
        fail("Exception expected");
    } catch (AmazonServiceException e) {
        assertEquals(e.getStatusCode(), STATUS_CODE);
        int expectedNumberOfRequests = 1 + maxRetries;
        assertNumberOfRetries(rawHttpClient, expectedNumberOfRequests);
        assertNumberOfTasksTriggered(httpClient.getHttpRequestTimer(), 0);
        assertNumberOfTasksTriggered(httpClient.getClientExecutionTimer(), 0);
    }
}

6. MockedClientTests#clientExecutionTimeoutEnabled_RequestCompletesWithinTimeout_EntityNotBufferedForStreamedResponse()

Project: aws-sdk-java
File: MockedClientTests.java
@Test
public void clientExecutionTimeoutEnabled_RequestCompletesWithinTimeout_EntityNotBufferedForStreamedResponse() throws Exception {
    ClientConfiguration config = new ClientConfiguration().withClientExecutionTimeout(CLIENT_EXECUTION_TIMEOUT);
    ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config);
    HttpResponseProxy responseProxy = createHttpResponseProxySpy();
    doReturn(responseProxy).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class));
    httpClient = new AmazonHttpClient(config, rawHttpClient, null);
    try {
        httpClient.execute(createMockGetRequest(), new NullResponseHandler() {

            @Override
            public boolean needsConnectionLeftOpen() {
                // Streaming operation
                return true;
            }
        }, new NullErrorResponseHandler(), new ExecutionContext());
        fail("Exception expected");
    } catch (AmazonClientException e) {
    }
    assertResponseWasNotBuffered(responseProxy);
}

7. MockedClientTests#clientExecutionTimeoutDisabled_RequestCompletesWithinTimeout_EntityNotBuffered()

Project: aws-sdk-java
File: MockedClientTests.java
@Test
public void clientExecutionTimeoutDisabled_RequestCompletesWithinTimeout_EntityNotBuffered() throws Exception {
    ClientConfiguration config = new ClientConfiguration().withClientExecutionTimeout(0);
    ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config);
    HttpResponseProxy responseProxy = createHttpResponseProxySpy();
    doReturn(responseProxy).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class));
    httpClient = new AmazonHttpClient(config, rawHttpClient, null);
    try {
        execute(httpClient, createMockGetRequest());
        fail("Exception expected");
    } catch (AmazonClientException e) {
    }
    assertResponseWasNotBuffered(responseProxy);
}

8. DummySuccessfulResponseServerTests#clientInterruptedDuringResponseHandlers_DoesNotLeakConnection()

Project: aws-sdk-java
File: DummySuccessfulResponseServerTests.java
/**
     * Tests that a streaming operation has it's request properly cleaned up if the client is interrupted after the
     * response is received.
     *
     * @see TT0070103230
     */
@Test
public void clientInterruptedDuringResponseHandlers_DoesNotLeakConnection() throws IOException {
    ClientConfiguration config = new ClientConfiguration();
    ConnectionManagerAwareHttpClient rawHttpClient = new ApacheHttpClientFactory().create(HttpClientSettings.adapt(config));
    httpClient = new AmazonHttpClient(config, rawHttpClient, null);
    interruptCurrentThreadAfterDelay(1000);
    List<RequestHandler2> requestHandlers = RequestHandlerTestUtils.buildRequestHandlerList(new SlowRequestHandler().withAfterResponseWaitInSeconds(10));
    try {
        httpClient.execute(newGetRequest(), new DummyResponseHandler().leaveConnectionOpen(), new NullErrorResponseHandler(), new ExecutionContext(requestHandlers, false, null));
        fail("Expected exception");
    } catch (AmazonClientException e) {
        assertThat(e.getCause(), instanceOf(InterruptedException.class));
    }
    @SuppressWarnings("deprecation") int leasedConnections = ((ConnPoolControl<?>) ((SdkHttpClient) rawHttpClient).getHttpClientConnectionManager()).getTotalStats().getLeased();
    assertEquals(0, leasedConnections);
}

9. AbortedExceptionClientExecutionTimerTest#clientExecutionTimeoutEnabled_aborted_exception_occurs_timeout_expired()

Project: aws-sdk-java
File: AbortedExceptionClientExecutionTimerTest.java
@Test(expected = ClientExecutionTimeoutException.class)
public void clientExecutionTimeoutEnabled_aborted_exception_occurs_timeout_expired() throws Exception {
    ClientConfiguration config = new ClientConfiguration().withClientExecutionTimeout(CLIENT_EXECUTION_TIMEOUT).withMaxErrorRetry(0);
    ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config);
    httpClient = new AmazonHttpClient(config, rawHttpClient, null);
    execute(httpClient, new EmptyHttpRequest(server.getEndpoint(), HttpMethodName.PUT, new SdkBufferedInputStream(new InputStream() {

        @Override
        public int read() throws IOException {
            return 1;
        }
    })));
}

10. AbortedExceptionClientExecutionTimerTest#clientExecutionTimeoutEnabled_aborted_exception_occurs_timeout_not_expired()

Project: aws-sdk-java
File: AbortedExceptionClientExecutionTimerTest.java
@Test(expected = AbortedException.class)
public void clientExecutionTimeoutEnabled_aborted_exception_occurs_timeout_not_expired() throws Exception {
    ClientConfiguration config = new ClientConfiguration().withClientExecutionTimeout(CLIENT_EXECUTION_TIMEOUT).withMaxErrorRetry(0);
    ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config);
    doThrow(new AbortedException()).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class));
    httpClient = new AmazonHttpClient(config, rawHttpClient, null);
    execute(httpClient, createMockGetRequest());
}

11. MockedClientTests#requestTimeoutEnabled_RequestCompletesWithinTimeout_TaskCanceledAndEntityBuffered()

Project: aws-sdk-java
File: MockedClientTests.java
@Test
public void requestTimeoutEnabled_RequestCompletesWithinTimeout_TaskCanceledAndEntityBuffered() throws Exception {
    ClientConfiguration config = new ClientConfiguration().withRequestTimeout(5 * 1000).withMaxErrorRetry(0);
    ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config);
    HttpResponseProxy responseProxy = createHttpResponseProxySpy();
    doReturn(responseProxy).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class));
    httpClient = new AmazonHttpClient(config, rawHttpClient, null);
    try {
        execute(httpClient, createMockGetRequest());
        fail("Exception expected");
    } catch (AmazonClientException e) {
        NullResponseHandler.assertIsUnmarshallingException(e);
    }
    assertResponseIsBuffered(responseProxy);
    ScheduledThreadPoolExecutor requestTimerExecutor = httpClient.getHttpRequestTimer().getExecutor();
    assertTimerNeverTriggered(requestTimerExecutor);
    assertCanceledTasksRemoved(requestTimerExecutor);
    // Core threads should be spun up on demand. Since only one task was submitted only one
    // thread should exist
    assertEquals(1, requestTimerExecutor.getPoolSize());
    assertCoreThreadsShutDownAfterBeingIdle(requestTimerExecutor);
}

12. MockedClientTests#clientExecutionTimeoutEnabled_RequestCompletesWithinTimeout_TaskCanceledAndEntityBuffered()

Project: aws-sdk-java
File: MockedClientTests.java
@Test
public void clientExecutionTimeoutEnabled_RequestCompletesWithinTimeout_TaskCanceledAndEntityBuffered() throws Exception {
    ClientConfiguration config = new ClientConfiguration().withClientExecutionTimeout(CLIENT_EXECUTION_TIMEOUT).withMaxErrorRetry(0);
    ConnectionManagerAwareHttpClient rawHttpClient = createRawHttpClientSpy(config);
    HttpResponseProxy responseProxy = createHttpResponseProxySpy();
    doReturn(responseProxy).when(rawHttpClient).execute(any(HttpRequestBase.class), any(HttpContext.class));
    httpClient = new AmazonHttpClient(config, rawHttpClient, null);
    try {
        execute(httpClient, createMockGetRequest());
        fail("Exception expected");
    } catch (AmazonClientException e) {
        NullResponseHandler.assertIsUnmarshallingException(e);
    }
    assertResponseIsBuffered(responseProxy);
    ScheduledThreadPoolExecutor requestTimerExecutor = httpClient.getClientExecutionTimer().getExecutor();
    assertTimerNeverTriggered(requestTimerExecutor);
    assertCanceledTasksRemoved(requestTimerExecutor);
    // Core threads should be spun up on demand. Since only one task was submitted only one
    // thread should exist
    assertEquals(1, requestTimerExecutor.getPoolSize());
    assertCoreThreadsShutDownAfterBeingIdle(requestTimerExecutor);
}