- @Test
- public void retries() throws Exception {
- RestClient spy = buildSpy();
- RestRequest mockCallable = mock(RestRequest.class);
- when(mockCallable.call()).thenThrow(new WebApplicationException(new SocketTimeoutException()));
- doReturn(mockCallable).when(spy).buildRequest(any(String.class), ArgumentMatchers.isNull());
- try {
- spy.get();
- } catch (Exception e) {
- //we expect an exception, ignore it
- }
- verify(mockCallable, times(3)).call();
-
- }
-
- @Test
- public void exceptionDoNotRetry() throws Exception {
- RestClient spy = buildSpy();
- RestRequest mockCallable = mock(RestRequest.class);
- when(mockCallable.call()).thenThrow(new WebApplicationException(new NotFoundException()));
- doReturn(mockCallable).when(spy).buildRequest(any(String.class), ArgumentMatchers.isNull());
- try {
- spy.get();
- } catch (Exception e) {
- //we expect an exception, ignore it
- }
- verify(mockCallable, times(1)).call();
-
- }
- private RestClient buildSpy() throws MalformedURLException, IllegalArgumentException, UriBuilderException {
- RestClient client = httpClientFactory
- .newJsonClient(UriBuilder.fromUri("http://localhost/test").build().toURL(), TargetEntity.BPMN);
-
- return spy(client);
- }