@Test public void test503() throws Exception { Response response = responseWithCode(REQUEST, 503); assertThat(handler.handle(response).get()).isInstanceOf(QosException.Unavailable.class); }
@Test public void test308() throws Exception { Response response; // with header response = response(REQUEST, 308).header(HttpHeaders.LOCATION, LOCAL_URL.toString()).build(); assertThat(handler.handle(response).get()) .isInstanceOfSatisfying(QosException.RetryOther.class, retryOther -> assertThat(retryOther.getRedirectTo()).isEqualTo(LOCAL_URL)); // with header response = response(REQUEST, 308).build(); assertThat(handler.handle(response)).isEmpty(); }
@Test public void doesNotHandleOtherCodes() throws Exception { Response response = responseWithCode(REQUEST, 500); assertThat(handler.handle(response)).isEmpty(); }
@Test public void test429WithRetryAfter() throws Exception { Response response = response(REQUEST, 429).header("Retry-After", "120").build(); assertThat(handler.handle(response).get()) .isInstanceOfSatisfying(QosException.Throttle.class, retryAfter -> assertThat(retryAfter.getRetryAfter()).contains(Duration.ofMinutes(2))); }
@Test public void test429WithoutRetryAfter() throws Exception { Response response = responseWithCode(REQUEST, 429); assertThat(handler.handle(response).get()) .isInstanceOfSatisfying(QosException.Throttle.class, retryAfter -> assertThat(retryAfter.getRetryAfter()).isEmpty()); }