@Test public void mandatoryStopTest() { Clock mockClock = Mockito.mock(Clock.class); Backoff backoff = new Backoff( 100, TimeUnit.MILLISECONDS, 60, TimeUnit.SECONDS, 1900, TimeUnit.MILLISECONDS, mockClock ); Mockito.when(mockClock.millis()).thenReturn(0L); assertTrue(checkExactAndDecrementTimer(backoff, 100)); Mockito.when(mockClock.millis()).thenReturn(100L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 200)); Mockito.when(mockClock.millis()).thenReturn(300L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 400)); Mockito.when(mockClock.millis()).thenReturn(700L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 800)); Mockito.when(mockClock.millis()).thenReturn(1500L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 400)); Mockito.when(mockClock.millis()).thenReturn(1900L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 3200)); Mockito.when(mockClock.millis()).thenReturn(3200L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 6400)); Mockito.when(mockClock.millis()).thenReturn(3200L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 12800)); Mockito.when(mockClock.millis()).thenReturn(6400L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 25600)); Mockito.when(mockClock.millis()).thenReturn(12800L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 51200)); Mockito.when(mockClock.millis()).thenReturn(25600L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 60000)); Mockito.when(mockClock.millis()).thenReturn(51200L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 60000)); Mockito.when(mockClock.millis()).thenReturn(60000L); backoff.reset(); Mockito.when(mockClock.millis()).thenReturn(0L); assertTrue(checkExactAndDecrementTimer(backoff, 100)); Mockito.when(mockClock.millis()).thenReturn(100L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 200)); Mockito.when(mockClock.millis()).thenReturn(300L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 400)); Mockito.when(mockClock.millis()).thenReturn(700L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 800)); Mockito.when(mockClock.millis()).thenReturn(1500L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 400)); backoff.reset(); Mockito.when(mockClock.millis()).thenReturn(0L); assertTrue(checkExactAndDecrementTimer(backoff, 100)); Mockito.when(mockClock.millis()).thenReturn(100L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 200)); Mockito.when(mockClock.millis()).thenReturn(300L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 400)); Mockito.when(mockClock.millis()).thenReturn(700L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 800)); backoff.reset(); Mockito.when(mockClock.millis()).thenReturn(0L); assertTrue(checkExactAndDecrementTimer(backoff, 100)); Mockito.when(mockClock.millis()).thenReturn(100L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 200)); Mockito.when(mockClock.millis()).thenReturn(300L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 400)); Mockito.when(mockClock.millis()).thenReturn(700L); assertTrue(withinTenPercentAndDecrementTimer(backoff, 800)); }
public void reset() { this.next = this.initial; this.mandatoryStopMade = false; }
Backoff { public void reset() { this.next = this.initial; this.mandatoryStopMade = false; } }
Backoff { public void reset() { this.next = this.initial; this.mandatoryStopMade = false; } @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 void reset() { this.next = this.initial; this.mandatoryStopMade = false; } @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 void reset() { this.next = this.initial; this.mandatoryStopMade = false; } @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; }