}
@Test(dataProvider = "codes")
public void test503DoesBackoffAndRetryForCode(String code) {
AWSUtils utils = createMock(AWSUtils.class);
HttpCommand command = createMock(HttpCommand.class);
HttpRequest putBucket = HttpRequest.builder().method(PUT)
.endpoint("https://adriancole-blobstore113.s3.amazonaws.com/").build();
HttpResponse limitExceeded = HttpResponse.builder().statusCode(SERVICE_UNAVAILABLE.getStatusCode())
.payload(Payloads.newStringPayload(String.format("<Error><Code>%s</Code></Error>", code))).build();
expect(command.getCurrentRequest()).andReturn(putBucket);
final AtomicInteger counter = new AtomicInteger();
expect(command.incrementFailureCount()).andAnswer(new IAnswer<Integer>() {
@Override
public Integer answer() throws Throwable {
return counter.incrementAndGet();
}
}).anyTimes();
expect(command.isReplayable()).andReturn(true).anyTimes();
expect(command.getFailureCount()).andAnswer(new IAnswer<Integer>() {
@Override
public Integer answer() throws Throwable {
return counter.get();
}
}).anyTimes();
AWSError error = new AWSError();
error.setCode(code);
expect(utils.parseAWSErrorFromContent(putBucket, limitExceeded)).andReturn(error);
replay(utils, command);
AWSServerErrorRetryHandler retry = new AWSServerErrorRetryHandler(utils,
ImmutableSet.<String> of("RequestLimitExceeded"));