@Test void shouldReturnDelay_fromDefault_onParsingDateError() { Response response = mock(Response.class); when(response.headers()).thenReturn( Collections.singletonList( new HttpHeader("Retry-After", Collections.singletonList("Not A Date")))); RetryContext context = new RetryContext(1, null, response); long result = this.interval.getInterval(context); assertThat(result).isEqualTo(1000L); verify(fallback, times(1)).getInterval(any(RetryContext.class)); }
@Override public long getInterval(final RetryContext retryContext) { return retryContext.getResponse() .map(response -> response.headers() .stream() .filter(header -> RETRY_AFTER_HEADER.equalsIgnoreCase(header.name()) && header.values() != null && !header.values().isEmpty()) .map(header -> { String headerValue = header.values().iterator().next(); return determineInterval(headerValue); }) .filter(Objects::nonNull) .findFirst() .orElse(fallback.getInterval(retryContext))) .orElseGet(() -> this.fallback.getInterval(retryContext)); }
RetryAfterHeaderInterval implements RetryInterval { @Override public long getInterval(final RetryContext retryContext) { return retryContext.getResponse() .map(response -> response.headers() .stream() .filter(header -> RETRY_AFTER_HEADER.equalsIgnoreCase(header.name()) && header.values() != null && !header.values().isEmpty()) .map(header -> { String headerValue = header.values().iterator().next(); return determineInterval(headerValue); }) .filter(Objects::nonNull) .findFirst() .orElse(fallback.getInterval(retryContext))) .orElseGet(() -> this.fallback.getInterval(retryContext)); } }
RetryAfterHeaderInterval implements RetryInterval { @Override public long getInterval(final RetryContext retryContext) { return retryContext.getResponse() .map(response -> response.headers() .stream() .filter(header -> RETRY_AFTER_HEADER.equalsIgnoreCase(header.name()) && header.values() != null && !header.values().isEmpty()) .map(header -> { String headerValue = header.values().iterator().next(); return determineInterval(headerValue); }) .filter(Objects::nonNull) .findFirst() .orElse(fallback.getInterval(retryContext))) .orElseGet(() -> this.fallback.getInterval(retryContext)); } RetryAfterHeaderInterval(RetryInterval fallback); }
RetryAfterHeaderInterval implements RetryInterval { @Override public long getInterval(final RetryContext retryContext) { return retryContext.getResponse() .map(response -> response.headers() .stream() .filter(header -> RETRY_AFTER_HEADER.equalsIgnoreCase(header.name()) && header.values() != null && !header.values().isEmpty()) .map(header -> { String headerValue = header.values().iterator().next(); return determineInterval(headerValue); }) .filter(Objects::nonNull) .findFirst() .orElse(fallback.getInterval(retryContext))) .orElseGet(() -> this.fallback.getInterval(retryContext)); } RetryAfterHeaderInterval(RetryInterval fallback); @Override long getInterval(final RetryContext retryContext); }
RetryAfterHeaderInterval implements RetryInterval { @Override public long getInterval(final RetryContext retryContext) { return retryContext.getResponse() .map(response -> response.headers() .stream() .filter(header -> RETRY_AFTER_HEADER.equalsIgnoreCase(header.name()) && header.values() != null && !header.values().isEmpty()) .map(header -> { String headerValue = header.values().iterator().next(); return determineInterval(headerValue); }) .filter(Objects::nonNull) .findFirst() .orElse(fallback.getInterval(retryContext))) .orElseGet(() -> this.fallback.getInterval(retryContext)); } RetryAfterHeaderInterval(RetryInterval fallback); @Override long getInterval(final RetryContext retryContext);  }