@Test public void mandatoryStopTestNegativeTest() { Backoff backoff = new Backoff(100, TimeUnit.MILLISECONDS, 60, TimeUnit.SECONDS, 1900, TimeUnit.MILLISECONDS); assertEquals(backoff.next(), 100); backoff.next(); backoff.next(); backoff.next(); assertFalse(withinTenPercentAndDecrementTimer(backoff, 400)); }
public long next() { long current = this.next; if (current < max) { this.next = Math.min(this.next * 2, this.max); } if (!mandatoryStopMade) { long now = clock.millis(); long timeElapsedSinceFirstBackoff = 0; if (initial == current) { firstBackoffTimeInMillis = now; } else { timeElapsedSinceFirstBackoff = now - firstBackoffTimeInMillis; } if (timeElapsedSinceFirstBackoff + current > mandatoryStop) { current = Math.max(initial, mandatoryStop - timeElapsedSinceFirstBackoff); mandatoryStopMade = true; } } if (current > 10) { current -= random.nextInt((int) current / 10); } return Math.max(initial, current); }
Backoff { public long next() { long current = this.next; if (current < max) { this.next = Math.min(this.next * 2, this.max); } if (!mandatoryStopMade) { long now = clock.millis(); long timeElapsedSinceFirstBackoff = 0; if (initial == current) { firstBackoffTimeInMillis = now; } else { timeElapsedSinceFirstBackoff = now - firstBackoffTimeInMillis; } if (timeElapsedSinceFirstBackoff + current > mandatoryStop) { current = Math.max(initial, mandatoryStop - timeElapsedSinceFirstBackoff); mandatoryStopMade = true; } } if (current > 10) { current -= random.nextInt((int) current / 10); } return Math.max(initial, current); } }
Backoff { public long next() { long current = this.next; if (current < max) { this.next = Math.min(this.next * 2, this.max); } if (!mandatoryStopMade) { long now = clock.millis(); long timeElapsedSinceFirstBackoff = 0; if (initial == current) { firstBackoffTimeInMillis = now; } else { timeElapsedSinceFirstBackoff = now - firstBackoffTimeInMillis; } if (timeElapsedSinceFirstBackoff + current > mandatoryStop) { current = Math.max(initial, mandatoryStop - timeElapsedSinceFirstBackoff); mandatoryStopMade = true; } } if (current > 10) { current -= random.nextInt((int) current / 10); } return Math.max(initial, current); } @VisibleForTesting  Backoff(long initial, TimeUnit unitInitial, long max, TimeUnit unitMax, long mandatoryStop,
            TimeUnit unitMandatoryStop, Clock clock);  Backoff(long initial, TimeUnit unitInitial, long max, TimeUnit unitMax, long mandatoryStop,
                   TimeUnit unitMandatoryStop); }
Backoff { public long next() { long current = this.next; if (current < max) { this.next = Math.min(this.next * 2, this.max); } if (!mandatoryStopMade) { long now = clock.millis(); long timeElapsedSinceFirstBackoff = 0; if (initial == current) { firstBackoffTimeInMillis = now; } else { timeElapsedSinceFirstBackoff = now - firstBackoffTimeInMillis; } if (timeElapsedSinceFirstBackoff + current > mandatoryStop) { current = Math.max(initial, mandatoryStop - timeElapsedSinceFirstBackoff); mandatoryStopMade = true; } } if (current > 10) { current -= random.nextInt((int) current / 10); } return Math.max(initial, current); } @VisibleForTesting  Backoff(long initial, TimeUnit unitInitial, long max, TimeUnit unitMax, long mandatoryStop,
            TimeUnit unitMandatoryStop, Clock clock);  Backoff(long initial, TimeUnit unitInitial, long max, TimeUnit unitMax, long mandatoryStop,
                   TimeUnit unitMandatoryStop); long next(); void reduceToHalf(); void reset(); static boolean shouldBackoff(long initialTimestamp, TimeUnit unitInitial, int failedAttempts,
    									long defaultInterval, long maxBackoffInterval); static boolean shouldBackoff(long initialTimestamp, TimeUnit unitInitial, int failedAttempts); }
Backoff { public long next() { long current = this.next; if (current < max) { this.next = Math.min(this.next * 2, this.max); } if (!mandatoryStopMade) { long now = clock.millis(); long timeElapsedSinceFirstBackoff = 0; if (initial == current) { firstBackoffTimeInMillis = now; } else { timeElapsedSinceFirstBackoff = now - firstBackoffTimeInMillis; } if (timeElapsedSinceFirstBackoff + current > mandatoryStop) { current = Math.max(initial, mandatoryStop - timeElapsedSinceFirstBackoff); mandatoryStopMade = true; } } if (current > 10) { current -= random.nextInt((int) current / 10); } return Math.max(initial, current); } @VisibleForTesting  Backoff(long initial, TimeUnit unitInitial, long max, TimeUnit unitMax, long mandatoryStop,
            TimeUnit unitMandatoryStop, Clock clock);  Backoff(long initial, TimeUnit unitInitial, long max, TimeUnit unitMax, long mandatoryStop,
                   TimeUnit unitMandatoryStop); long next(); void reduceToHalf(); void reset(); static boolean shouldBackoff(long initialTimestamp, TimeUnit unitInitial, int failedAttempts,
    									long defaultInterval, long maxBackoffInterval); static boolean shouldBackoff(long initialTimestamp, TimeUnit unitInitial, int failedAttempts); static final long DEFAULT_INTERVAL_IN_NANOSECONDS; static final long MAX_BACKOFF_INTERVAL_NANOSECONDS; }