/** * check if should retry when publish failed * * @param isLocalError if publish failed because of internal error. * It means message hasn't been sent and always should retry. * @return should retry */ public boolean shouldStop(boolean isLocalError) { if (message.getQos() < 1 && !isLocalError) { return true; } return stopStrategy.shouldStop(attempt); }
return attempt.get(); if (stopStrategy.shouldStop(attempt)) { throw new RetryException(attemptNumber, attempt); } else {
if (stopStrategy.shouldStop(attempt)) { throw new RetryException(attempt); } else {
@Test public void testStopAfterAttempt() { assertFalse(StopStrategies.stopAfterAttempt(3).shouldStop(failedAttempt(2, 6546L))); assertTrue(StopStrategies.stopAfterAttempt(3).shouldStop(failedAttempt(3, 6546L))); assertTrue(StopStrategies.stopAfterAttempt(3).shouldStop(failedAttempt(4, 6546L))); }
@Test public void testStopAfterDelayWithTimeUnit() { assertFalse(StopStrategies.stopAfterDelay(1, TimeUnit.SECONDS).shouldStop(failedAttempt(2, 999L))); assertTrue(StopStrategies.stopAfterDelay(1, TimeUnit.SECONDS).shouldStop(failedAttempt(2, 1000L))); assertTrue(StopStrategies.stopAfterDelay(1, TimeUnit.SECONDS).shouldStop(failedAttempt(2, 1001L))); }
@Test public void testStopAfterDelayWithMilliseconds() { assertFalse(StopStrategies.stopAfterDelay(1000, MILLISECONDS) .shouldStop(failedAttempt(2, 999L))); assertTrue(StopStrategies.stopAfterDelay(1000, MILLISECONDS) .shouldStop(failedAttempt(2, 1000L))); assertTrue(StopStrategies.stopAfterDelay(1000, MILLISECONDS) .shouldStop(failedAttempt(2, 1001L))); }
@Test public void testNeverStop() { assertFalse(StopStrategies.neverStop().shouldStop(failedAttempt(3, 6546L))); }