@Test public void getDelays() { ResettingExponentialBackoffStrategy strategy = new ResettingExponentialBackoffStrategy(30L); WaitContext wc = Mockito.mock(WaitContext.class); when(wc.getAttemptsMade()) .thenReturn(0) .thenReturn(1) .thenReturn(2) .thenReturn(3) .thenReturn(4) .thenReturn(5) .thenReturn(6) .thenReturn(7) .thenReturn(8) .thenReturn(9) .thenReturn(10) .thenReturn(11); assertEquals(1000L, strategy.nextDelay(wc)); assertEquals(2000L, strategy.nextDelay(wc)); assertEquals(4000L, strategy.nextDelay(wc)); assertEquals(8000L, strategy.nextDelay(wc)); assertEquals(16000L, strategy.nextDelay(wc)); assertEquals(1000L, strategy.nextDelay(wc)); assertEquals(2000L, strategy.nextDelay(wc)); assertEquals(4000L, strategy.nextDelay(wc)); assertEquals(8000L, strategy.nextDelay(wc)); assertEquals(16000L, strategy.nextDelay(wc)); assertEquals(1000L, strategy.nextDelay(wc)); }
@Override public long nextDelay(WaiterConfiguration.WaitContext context) { long delay = (long) Math.pow(2, (context.getAttemptsMade() % maxAttemptsPossible)); delay *= 1000; if (delay <= 0) { return resetThresholdInSeconds * 1000; } return Math.min(delay, resetThresholdInSeconds * 1000); }
ResettingExponentialBackoffStrategy implements DelayStrategy { @Override public long nextDelay(WaiterConfiguration.WaitContext context) { long delay = (long) Math.pow(2, (context.getAttemptsMade() % maxAttemptsPossible)); delay *= 1000; if (delay <= 0) { return resetThresholdInSeconds * 1000; } return Math.min(delay, resetThresholdInSeconds * 1000); } }
ResettingExponentialBackoffStrategy implements DelayStrategy { @Override public long nextDelay(WaiterConfiguration.WaitContext context) { long delay = (long) Math.pow(2, (context.getAttemptsMade() % maxAttemptsPossible)); delay *= 1000; if (delay <= 0) { return resetThresholdInSeconds * 1000; } return Math.min(delay, resetThresholdInSeconds * 1000); } ResettingExponentialBackoffStrategy(long resetThresholdInSeconds); }
ResettingExponentialBackoffStrategy implements DelayStrategy { @Override public long nextDelay(WaiterConfiguration.WaitContext context) { long delay = (long) Math.pow(2, (context.getAttemptsMade() % maxAttemptsPossible)); delay *= 1000; if (delay <= 0) { return resetThresholdInSeconds * 1000; } return Math.min(delay, resetThresholdInSeconds * 1000); } ResettingExponentialBackoffStrategy(long resetThresholdInSeconds); @Override long nextDelay(WaiterConfiguration.WaitContext context); }
ResettingExponentialBackoffStrategy implements DelayStrategy { @Override public long nextDelay(WaiterConfiguration.WaitContext context) { long delay = (long) Math.pow(2, (context.getAttemptsMade() % maxAttemptsPossible)); delay *= 1000; if (delay <= 0) { return resetThresholdInSeconds * 1000; } return Math.min(delay, resetThresholdInSeconds * 1000); } ResettingExponentialBackoffStrategy(long resetThresholdInSeconds); @Override long nextDelay(WaiterConfiguration.WaitContext context);  }