### Question:
AmazonHttpClient { public <T> Response<T> execute(Request<?> request, HttpResponseHandler<AmazonWebServiceResponse<T>> responseHandler, HttpResponseHandler<AmazonServiceException> errorResponseHandler, ExecutionContext executionContext) { if (executionContext == null) { throw new AmazonClientException( "Internal SDK Error: No execution context parameter specified."); } final List<RequestHandler2> requestHandler2s = requestHandler2s(request, executionContext); final AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics(); Response<T> response = null; try { response = executeHelper(request, responseHandler, errorResponseHandler, executionContext); final TimingInfo timingInfo = awsRequestMetrics.getTimingInfo().endTiming(); afterResponse(request, requestHandler2s, response, timingInfo); return response; } catch (final AmazonClientException e) { afterError(request, response, requestHandler2s, e); throw e; } } AmazonHttpClient(ClientConfiguration config); @Deprecated  AmazonHttpClient(ClientConfiguration config,
            RequestMetricCollector requestMetricCollector);  AmazonHttpClient(ClientConfiguration config, HttpClient httpClient); @Deprecated  AmazonHttpClient(ClientConfiguration config, HttpClient httpClient,
            RequestMetricCollector requestMetricCollector); @Deprecated ResponseMetadata getResponseMetadataForRequest(AmazonWebServiceRequest request); Response<T> execute(Request<?> request,
            HttpResponseHandler<AmazonWebServiceResponse<T>> responseHandler,
            HttpResponseHandler<AmazonServiceException> errorResponseHandler,
            ExecutionContext executionContext); void shutdown(); RequestMetricCollector getRequestMetricCollector();  }### Answer:
@Test public void testRetryIOExceptionFromExecute() throws IOException { IOException exception = new IOException("BOOM"); EasyMock .expect(httpClient.execute(EasyMock.<HttpRequest> anyObject())) .andThrow(exception) .times(4); EasyMock.replay(httpClient); ExecutionContext context = new ExecutionContext(); Request<?> request = new DefaultRequest<Object>("testsvc"); request.setEndpoint(java.net.URI.create( "http: request.addHeader(HttpHeader.CONTENT_LENGTH, "0"); request.setContent(new ByteArrayInputStream(new byte[0])); try { client.execute(request, null, null, context); Assert.fail("No exception when request repeatedly fails!"); } catch (AmazonClientException e) { Assert.assertSame(exception, e.getCause()); } EasyMock.verify(httpClient); }
@Test public void testRetryIOExceptionFromHandler() throws Exception { final IOException exception = new IOException("BOOM"); HttpResponseHandler<AmazonWebServiceResponse<Object>> handler = EasyMock.createMock(HttpResponseHandler.class); EasyMock .expect(handler.needsConnectionLeftOpen()) .andReturn(false) .anyTimes(); EasyMock .expect(handler.handle(EasyMock.<HttpResponse> anyObject())) .andThrow(exception) .times(4); HttpResponse response = HttpResponse.builder() .content(new ByteArrayInputStream(new byte[0])) .statusCode(200) .statusText("OK") .build(); EasyMock .expect(httpClient.execute(EasyMock.<HttpRequest> anyObject())) .andReturn(response) .times(4); EasyMock.replay(handler, httpClient); ExecutionContext context = new ExecutionContext(); Request<?> request = new DefaultRequest<Object>("testsvc"); request.setEndpoint(java.net.URI.create( "http: request.addHeader(HttpHeader.CONTENT_LENGTH, "0"); request.setContent(new java.io.ByteArrayInputStream(new byte[0])); try { client.execute(request, handler, null, context); Assert.fail("No exception when request repeatedly fails!"); } catch (AmazonClientException e) { Assert.assertSame(exception, e.getCause()); } EasyMock.verify(httpClient); }