RetryingJaxRsStrategy implements JaxRsStrategy<T> { @Override public <R> R apply(final Function<T, R> function) throws IOException { return apply(function, new LegacyJaxRsTimeouts()); } RetryingJaxRsStrategy(
            final Set<HostName> hostNames,
            final int port,
            final JaxRsClientFactory jaxRsClientFactory,
            final Class<T> apiClass,
            final String pathPrefix,
            String scheme); RetryingJaxRsStrategy<T> setMaxIterations(int maxIterations); @Override R apply(final Function<T, R> function); @Override R apply(final Function<T, R> function, JaxRsTimeouts timeouts);  }
@Test public void noRetryIfNoFailure() throws Exception { jaxRsStrategy.apply(TestJaxRsApi::doSomething); verify(mockApi, times(1)).doSomething(); verify(jaxRsClientFactory, times(1)).createClient(paramsCaptor.capture()); JaxRsClientFactory.Params<TestJaxRsApi> params = paramsCaptor.getValue(); assertEquals(REST_PORT, params.uri().getPort()); assertEquals(API_PATH, params.uri().getPath()); assertEquals("http", params.uri().getScheme()); assertTrue(SERVER_HOSTS.contains(new HostName(params.uri().getHost()))); }
@Test public void testRetryAfterSingleFailure() throws Exception { when(mockApi.doSomething()) .thenThrow(new ProcessingException("Fake timeout induced by test")) .thenReturn("a response"); jaxRsStrategy.apply(TestJaxRsApi::doSomething); verify(mockApi, times(2)).doSomething(); }
@Test public void testRetryUsesAllAvailableServers() throws Exception { when(mockApi.doSomething()) .thenThrow(new ProcessingException("Fake timeout 1 induced by test")) .thenThrow(new ProcessingException("Fake timeout 2 induced by test")) .thenReturn("a response"); jaxRsStrategy.apply(TestJaxRsApi::doSomething); verify(mockApi, times(3)).doSomething(); verifyAllServersContacted(jaxRsClientFactory); }
@Test public void testRetryLoopsOverAvailableServers() throws Exception { when(mockApi.doSomething()) .thenThrow(new ProcessingException("Fake socket timeout 1 induced by test")) .thenThrow(new ProcessingException("Fake socket timeout 2 induced by test")) .thenThrow(new ProcessingException("Fake socket timeout 3 induced by test")) .thenThrow(new ProcessingException("Fake socket timeout 4 induced by test")) .thenReturn("a response"); jaxRsStrategy.apply(TestJaxRsApi::doSomething); verify(mockApi, times(5)).doSomething(); verifyAllServersContacted(jaxRsClientFactory); }