@Test public void should_throw_exception_at_end() { RetryableParameters parameters = new RetryableParameters(3, 1, 1, 1, MILLISECONDS); RetryableOnException<Void, VitamRuntimeException> retryable = new RetryableOnException<>(parameters); ThrowingCallable runRetryable = () -> retryable.exec(() -> { throw new VitamRuntimeException("throw"); }); assertThatThrownBy(runRetryable).isInstanceOf(VitamRuntimeException.class); }
@Override public T exec(DelegateRetry<T, E> delegate) throws E { while (counter.getAndIncrement() < param.getNbRetry()) { try { return delegate.call(); } catch (Exception e) { boolean attemptExceedNbRetry = counter.get() >= param.getNbRetry(); boolean shouldStopRetry = retryOn.negate().test(e); if (attemptExceedNbRetry || shouldStopRetry) { throw e; } sleep(counter.get(), delegate.toString(), param, randomSleep, onException, e); } } throw new IllegalStateException("Unreachable statement."); }
RetryableOnException implements Retryable<T, E> { @Override public T exec(DelegateRetry<T, E> delegate) throws E { while (counter.getAndIncrement() < param.getNbRetry()) { try { return delegate.call(); } catch (Exception e) { boolean attemptExceedNbRetry = counter.get() >= param.getNbRetry(); boolean shouldStopRetry = retryOn.negate().test(e); if (attemptExceedNbRetry || shouldStopRetry) { throw e; } sleep(counter.get(), delegate.toString(), param, randomSleep, onException, e); } } throw new IllegalStateException("Unreachable statement."); } }
RetryableOnException implements Retryable<T, E> { @Override public T exec(DelegateRetry<T, E> delegate) throws E { while (counter.getAndIncrement() < param.getNbRetry()) { try { return delegate.call(); } catch (Exception e) { boolean attemptExceedNbRetry = counter.get() >= param.getNbRetry(); boolean shouldStopRetry = retryOn.negate().test(e); if (attemptExceedNbRetry || shouldStopRetry) { throw e; } sleep(counter.get(), delegate.toString(), param, randomSleep, onException, e); } } throw new IllegalStateException("Unreachable statement."); } RetryableOnException(RetryableParameters param, Predicate<Exception> retryOn, Consumer<Exception> onException);  RetryableOnException(RetryableParameters param, Predicate<Exception> retryOn);  RetryableOnException(RetryableParameters param); }
RetryableOnException implements Retryable<T, E> { @Override public T exec(DelegateRetry<T, E> delegate) throws E { while (counter.getAndIncrement() < param.getNbRetry()) { try { return delegate.call(); } catch (Exception e) { boolean attemptExceedNbRetry = counter.get() >= param.getNbRetry(); boolean shouldStopRetry = retryOn.negate().test(e); if (attemptExceedNbRetry || shouldStopRetry) { throw e; } sleep(counter.get(), delegate.toString(), param, randomSleep, onException, e); } } throw new IllegalStateException("Unreachable statement."); } RetryableOnException(RetryableParameters param, Predicate<Exception> retryOn, Consumer<Exception> onException);  RetryableOnException(RetryableParameters param, Predicate<Exception> retryOn);  RetryableOnException(RetryableParameters param); @Override T exec(DelegateRetry<T, E> delegate); @Override void execute(DelegateRetryVoid<E> delegate); }
RetryableOnException implements Retryable<T, E> { @Override public T exec(DelegateRetry<T, E> delegate) throws E { while (counter.getAndIncrement() < param.getNbRetry()) { try { return delegate.call(); } catch (Exception e) { boolean attemptExceedNbRetry = counter.get() >= param.getNbRetry(); boolean shouldStopRetry = retryOn.negate().test(e); if (attemptExceedNbRetry || shouldStopRetry) { throw e; } sleep(counter.get(), delegate.toString(), param, randomSleep, onException, e); } } throw new IllegalStateException("Unreachable statement."); } RetryableOnException(RetryableParameters param, Predicate<Exception> retryOn, Consumer<Exception> onException);  RetryableOnException(RetryableParameters param, Predicate<Exception> retryOn);  RetryableOnException(RetryableParameters param); @Override T exec(DelegateRetry<T, E> delegate); @Override void execute(DelegateRetryVoid<E> delegate);  }