HeaderToRetryAfterException implements PropagateIfRetryAfter { public static HeaderToRetryAfterException create(Ticker ticker, DateCodec dateCodec) { return new HeaderToRetryAfterException(ticker, dateCodec); } @Inject private  HeaderToRetryAfterException(DateCodecFactory factory); private  HeaderToRetryAfterException(Ticker ticker, DateCodec dateCodec); static HeaderToRetryAfterException create(Ticker ticker, DateCodec dateCodec); @Override ListenableFuture<Object> create(Throwable t); Optional<RetryAfterException> tryCreateRetryAfterException(Throwable in, String retryAfter);  }
@Test(expectedExceptions = RuntimeException.class) public void testArbitraryExceptionDoesntConvert(){ fn.create(new RuntimeException()); }
@Test(expectedExceptions = RetryAfterException.class, expectedExceptionsMessageRegExp = "retry now") public void testHttpResponseExceptionWithRetryAfterDate() { fn.create(new HttpResponseException(command, HttpResponse.builder() .statusCode(503) .addHeader(HttpHeaders.RETRY_AFTER, "Fri, 31 Dec 1999 23:59:59 GMT").build())); }
@Test(expectedExceptions = RetryAfterException.class, expectedExceptionsMessageRegExp = "retry in 700 seconds") public void testHttpResponseExceptionWithRetryAfterOffset(){ fn.create(new HttpResponseException(command, HttpResponse.builder() .statusCode(503) .addHeader(HttpHeaders.RETRY_AFTER, "700").build())); }
@Test(expectedExceptions = RetryAfterException.class, expectedExceptionsMessageRegExp = "retry in 86400 seconds") public void testHttpResponseExceptionWithRetryAfterPastIsZero(){ fn.create(new HttpResponseException(command, HttpResponse.builder() .statusCode(503) .addHeader(HttpHeaders.RETRY_AFTER, "Sun, 2 Jan 2000 00:00:00 GMT").build())); }