@Test public void testGetContentForHttp429RetryLimitExceeded() throws Exception { HttpContentRetriever service = prepareValidService(); CloseableHttpResponse getContentHttpResponse = mock(CloseableHttpResponse.class); StatusLine getContentStatusLine = mock(StatusLine.class); when(getContentHttpResponse.getStatusLine()).thenReturn(getContentStatusLine); when(getContentStatusLine.getStatusCode()).thenReturn(429); HttpEntity getContentHttpEntity = mock(HttpEntity.class); when(getContentHttpResponse.getEntity()).thenReturn(getContentHttpEntity); when(getContentHttpEntity.getContent()).thenReturn(new ByteArrayInputStream("".getBytes())); when(httpClient.execute(any(HttpGet.class))).thenReturn(getContentHttpResponse); ContentRetrieverResponse response = service.retrieveUrlContent("someUrl"); assertNotNull(response); assertTrue(response.getException() instanceof RetryLimitExceededException); assertEquals("", response.getContent()); }
@Override public ContentRetrieverResponse retrieveUrlContent(CharSequence url) { long startTime = System.currentTimeMillis(); log.info("starting content retrieval for url: {}", url); try { return retrieveUrlContent(url.toString(), 0); } catch (Exception e) { log.error("content retrieval failed for url: " + url, e); return new ContentRetrieverResponse(e); } finally { log.info("finished content retrieval for url: {} in {} ms", url, (System.currentTimeMillis() - startTime)); } }
HttpContentRetriever implements ContentRetriever { @Override public ContentRetrieverResponse retrieveUrlContent(CharSequence url) { long startTime = System.currentTimeMillis(); log.info("starting content retrieval for url: {}", url); try { return retrieveUrlContent(url.toString(), 0); } catch (Exception e) { log.error("content retrieval failed for url: " + url, e); return new ContentRetrieverResponse(e); } finally { log.info("finished content retrieval for url: {} in {} ms", url, (System.currentTimeMillis() - startTime)); } } }
HttpContentRetriever implements ContentRetriever { @Override public ContentRetrieverResponse retrieveUrlContent(CharSequence url) { long startTime = System.currentTimeMillis(); log.info("starting content retrieval for url: {}", url); try { return retrieveUrlContent(url.toString(), 0); } catch (Exception e) { log.error("content retrieval failed for url: " + url, e); return new ContentRetrieverResponse(e); } finally { log.info("finished content retrieval for url: {} in {} ms", url, (System.currentTimeMillis() - startTime)); } } HttpContentRetriever(int connectionTimeout, int readTimeout, int maxPageContentLength,
            long throttleSleepTime, int maxRetriesCount); }
HttpContentRetriever implements ContentRetriever { @Override public ContentRetrieverResponse retrieveUrlContent(CharSequence url) { long startTime = System.currentTimeMillis(); log.info("starting content retrieval for url: {}", url); try { return retrieveUrlContent(url.toString(), 0); } catch (Exception e) { log.error("content retrieval failed for url: " + url, e); return new ContentRetrieverResponse(e); } finally { log.info("finished content retrieval for url: {} in {} ms", url, (System.currentTimeMillis() - startTime)); } } HttpContentRetriever(int connectionTimeout, int readTimeout, int maxPageContentLength,
            long throttleSleepTime, int maxRetriesCount); @Override ContentRetrieverResponse retrieveUrlContent(CharSequence url); }
HttpContentRetriever implements ContentRetriever { @Override public ContentRetrieverResponse retrieveUrlContent(CharSequence url) { long startTime = System.currentTimeMillis(); log.info("starting content retrieval for url: {}", url); try { return retrieveUrlContent(url.toString(), 0); } catch (Exception e) { log.error("content retrieval failed for url: " + url, e); return new ContentRetrieverResponse(e); } finally { log.info("finished content retrieval for url: {} in {} ms", url, (System.currentTimeMillis() - startTime)); } } HttpContentRetriever(int connectionTimeout, int readTimeout, int maxPageContentLength,
            long throttleSleepTime, int maxRetriesCount); @Override ContentRetrieverResponse retrieveUrlContent(CharSequence url);  }