RetryNTimes extends AbstractRetryTemplate<V> { protected static Exception getOriginalException(Throwable e) { if (e instanceof ExecutionException) { return (Exception) ((null == e.getCause())?e : getOriginalException(e.getCause())); } if (e instanceof InvocationTargetException) { return (Exception) ((null == e.getCause())?e : getOriginalException(e.getCause())); } return (Exception) e; } RetryNTimes(int n, int delayBaseMilli);  RetryNTimes(int n);  RetryNTimes(int n, RetryPolicy retryPolicy);  RetryNTimes(int n, RetryPolicy retryPolicy, boolean logDetail); static RetryTemplate<V> retryForEver(RetryPolicy retryPolicy); static RetryTemplate<V> noRetry(); @Override V execute(Command<V> command); @Override void destroy();  }
@Test public void testGetOriginalException() { assertTrue(RetryNTimes.getOriginalException(new IOException("test")) instanceof IOException); assertTrue(RetryNTimes.getOriginalException( new ExecutionException(new IllegalArgumentException("test"))) instanceof IllegalArgumentException); assertTrue(RetryNTimes.getOriginalException(new ExecutionException(null)) instanceof ExecutionException); assertTrue(RetryNTimes.getOriginalException(new ExecutionException(new InvocationTargetException( new HttpClientErrorException(HttpStatus.BAD_REQUEST, "test")))) instanceof HttpClientErrorException); assertTrue(RetryNTimes.getOriginalException( new ExecutionException(new InvocationTargetException(null))) instanceof InvocationTargetException); assertTrue(RetryNTimes.getOriginalException(new InvocationTargetException(new IOException("test"))) instanceof IOException); assertTrue(RetryNTimes.getOriginalException(new InvocationTargetException(null)) instanceof InvocationTargetException); assertFalse(RetryNTimes.getOriginalException( new InvocationTargetException(new IOException())) instanceof InvocationTargetException); assertFalse(RetryNTimes.getOriginalException(new ExecutionException( new InvocationTargetException(new IOException("test")))) instanceof ExecutionException); }