@Test
    public void testServiceExceptionHandlingWithNonRepeatableRequestContent() {
        int random500StatusCode = 500 + random.nextInt(100);
        String randomErrorCode = UUID.randomUUID().toString();
        
        // A mock HttpClient that always returns the specified status and error code.
        injectMockHttpClient(testedClient, new ReturnServiceErrorHttpClient(random500StatusCode, randomErrorCode));
        
        // The ExecutionContext should collect the expected RequestCount
        ExecutionContext context = new ExecutionContext(true);
        
        // A non-repeatable request
        Request<?> testedNonRepeatableRequest = getSampleRequestWithNonRepeatableContent(originalRequest);
        
        // It should fail directly and throw the ASE, without consulting the
        // custom shouldRetry(..) method.
        try {
            testedClient.requestExecutionBuilder()
                    .request(testedNonRepeatableRequest)
                    .errorResponseHandler(errorResponseHandler)
                    .executionContext(context)
                    .execute();
            Assert.fail("AmazonServiceException is expected.");
        } catch (AmazonServiceException ase) {
            Assert.assertEquals(random500StatusCode, ase.getStatusCode());
            Assert.assertEquals(randomErrorCode, ase.getErrorCode());
        }
        
        // Verifies that shouldRetry and calculateSleepTime were never called
        verifyExpectedContextData(retryCondition,
                                  null,
                                  null,
                                  EXPECTED_SHOULD_RETRY_CALL_COUNT); // shouldRetry is being called again to record MaxRetriesExceeded
        verifyExpectedContextData(backoffStrategy,
                                  null,
                                  null, 
                                  EXPECTED_RETRY_COUNT);
        Assert.assertEquals(
                EXPECTED_RETRY_COUNT + 1,   // request count = retries + 1
                context.getAwsRequestMetrics()
                        .getTimingInfo().getCounter(AWSRequestMetrics.Field.RequestCount.toString()).intValue());
    }
Tests AmazonHttpClient's behavior upon simulated service exceptions when the
request payload is not repeatable.
aws-java-sdk-core/src/test/java/com/amazonaws/retry/AmazonHttpClientRetryPolicyTest.java